From f41599c8e9435f3dfec60b872c2b4ae31177efdd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 10 Oct 2020 17:22:46 +0300 Subject: Add support for test timeouts --- libbuild2/script/timeout.ixx | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 libbuild2/script/timeout.ixx (limited to 'libbuild2/script/timeout.ixx') diff --git a/libbuild2/script/timeout.ixx b/libbuild2/script/timeout.ixx new file mode 100644 index 0000000..755af17 --- /dev/null +++ b/libbuild2/script/timeout.ixx @@ -0,0 +1,44 @@ +// file : libbuild2/script/timeout.ixx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +namespace build2 +{ + inline optional + parse_deadline (const string& s, const char* what, const location& l) + { + if (optional t = parse_timeout (s, what, l)) + return system_clock::now () + *t; + else + return nullopt; + } + + template + inline T + earlier (const T& x, const T& y) + { + return x < y ? x : y; + } + + template + inline T + earlier (const T& x, const optional& y) + { + return y ? earlier (x, *y) : x; + } + + template + inline T + earlier (const optional& x, const T& y) + { + return earlier (y, x); + } + + template + inline optional + earlier (const optional& x, const optional& y) + { + return x ? earlier (*x, y) : + y ? earlier (*y, x) : + optional (); + } +} -- cgit v1.1