aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-09 15:10:56 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-12-11 14:31:39 +0300
commit32f153664e7b6cadfb518b83e12b9768a150d709 (patch)
tree706d683404d412e29e4cbd4640ce8b2780689c65
parentec16a07c4bc3f3552ba5b4d09d3c5c375fb19e35 (diff)
Prefix pseudo-builtin diagnostincs messages with their names
-rw-r--r--libbuild2/build/script/script.cxx5
-rw-r--r--libbuild2/script/run.cxx16
-rw-r--r--libbuild2/script/timeout.cxx7
-rw-r--r--libbuild2/script/timeout.hxx6
-rw-r--r--libbuild2/script/timeout.ixx7
-rw-r--r--libbuild2/test/script/script.cxx14
-rw-r--r--tests/test/script/runner/exit.testscript2
-rw-r--r--tests/test/script/runner/set.testscript10
-rw-r--r--tests/test/script/runner/timeout.testscript12
9 files changed, 46 insertions, 33 deletions
diff --git a/libbuild2/build/script/script.cxx b/libbuild2/build/script/script.cxx
index e003b6a..14dd9e1 100644
--- a/libbuild2/build/script/script.cxx
+++ b/libbuild2/build/script/script.cxx
@@ -253,8 +253,9 @@ namespace build2
set_timeout (const string& t, bool success, const location& l)
{
fragment_deadline =
- to_deadline (parse_deadline (t, "buildscript timeout", l),
- success);
+ to_deadline (
+ parse_deadline (t, "buildscript timeout", "timeout: ", l),
+ success);
}
optional<deadline> environment::
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx
index 90ddc4d..b1bc888 100644
--- a/libbuild2/script/run.cxx
+++ b/libbuild2/script/run.cxx
@@ -782,12 +782,12 @@ namespace build2
timeout_options ops (scan);
if (!scan.more ())
- fail (ll) << "missing timeout";
+ fail (ll) << "timeout: missing timeout";
string a (scan.next ());
if (scan.more ())
- fail (ll) << "unexpected argument '" << scan.next () << "'";
+ fail (ll) << "timeout: unexpected argument '" << scan.next () << "'";
env.set_timeout (a, ops.success (), ll);
}
@@ -820,7 +820,7 @@ namespace build2
const string& s (*i++);
if (i != e)
- fail (ll) << "unexpected argument '" << *i << "'";
+ fail (ll) << "exit: unexpected argument '" << *i << "'";
error (ll) << s;
throw exit (false);
@@ -861,23 +861,23 @@ namespace build2
set_options ops (scan);
if (ops.whitespace () && ops.newline ())
- fail (ll) << "both -n|--newline and -w|--whitespace specified";
+ fail (ll) << "set: both -n|--newline and -w|--whitespace specified";
if (!scan.more ())
- fail (ll) << "missing variable name";
+ fail (ll) << "set: missing variable name";
string a (scan.next ()); // Either attributes or variable name.
const string* ats (!scan.more () ? nullptr : &a);
string vname (!scan.more () ? move (a) : scan.next ());
if (scan.more ())
- fail (ll) << "unexpected argument '" << scan.next () << "'";
+ fail (ll) << "set: unexpected argument '" << scan.next () << "'";
if (ats != nullptr && ats->empty ())
- fail (ll) << "empty variable attributes";
+ fail (ll) << "set: empty variable attributes";
if (vname.empty ())
- fail (ll) << "empty variable name";
+ fail (ll) << "set: empty variable name";
// Read out the stream content into a string while keeping an eye on
// the deadline. Then parse it according to the split mode.
diff --git a/libbuild2/script/timeout.cxx b/libbuild2/script/timeout.cxx
index a44e1bb..63cc61a 100644
--- a/libbuild2/script/timeout.cxx
+++ b/libbuild2/script/timeout.cxx
@@ -12,7 +12,10 @@ using namespace std;
namespace build2
{
optional<duration>
- parse_timeout (const string& s, const char* what, const location& l)
+ parse_timeout (const string& s,
+ const char* what,
+ const char* prefix,
+ const location& l)
{
if (optional<uint64_t> n = parse_number (s))
{
@@ -21,6 +24,6 @@ namespace build2
: optional<duration> ();
}
else
- fail (l) << "invalid " << what << " '" << s << "'" << endf;
+ fail (l) << prefix << "invalid " << what << " '" << s << "'" << endf;
}
}
diff --git a/libbuild2/script/timeout.hxx b/libbuild2/script/timeout.hxx
index 9991ad6..4ab43a5 100644
--- a/libbuild2/script/timeout.hxx
+++ b/libbuild2/script/timeout.hxx
@@ -10,12 +10,13 @@
namespace build2
{
// Parse the specified in seconds timeout returning it if the value is not
- // zero and nullopt otherwise. Issue diagnostics and fail if the argument is
- // not a valid timeout.
+ // zero and nullopt otherwise. Issue diagnostics with an optional prefix and
+ // fail if the argument is not a valid timeout.
//
optional<duration>
parse_timeout (const string&,
const char* what,
+ const char* prefix = "",
const location& = location ());
// As above, but return the timepoint which is away from now by the
@@ -24,6 +25,7 @@ namespace build2
optional<timestamp>
parse_deadline (const string&,
const char* what,
+ const char* prefix = "",
const location& = location ());
// Return the earlier timeout/deadline of two values, if any is present.
diff --git a/libbuild2/script/timeout.ixx b/libbuild2/script/timeout.ixx
index 755af17..e31ed07 100644
--- a/libbuild2/script/timeout.ixx
+++ b/libbuild2/script/timeout.ixx
@@ -4,9 +4,12 @@
namespace build2
{
inline optional<timestamp>
- parse_deadline (const string& s, const char* what, const location& l)
+ parse_deadline (const string& s,
+ const char* what,
+ const char* prefix,
+ const location& l)
{
- if (optional<duration> t = parse_timeout (s, what, l))
+ if (optional<duration> t = parse_timeout (s, what, prefix, l))
return system_clock::now () + *t;
else
return nullopt;
diff --git a/libbuild2/test/script/script.cxx b/libbuild2/test/script/script.cxx
index cb367bc..b539c71 100644
--- a/libbuild2/test/script/script.cxx
+++ b/libbuild2/test/script/script.cxx
@@ -480,6 +480,7 @@ namespace build2
: "testscript timeout");
const char* tt ("test timeout");
+ const char* pf ("timeout: ");
size_t p (t.find ('/'));
if (p != string::npos)
@@ -491,15 +492,17 @@ namespace build2
if (p != 0)
group_deadline =
- to_deadline (parse_deadline (string (t, 0, p), gt, l),
+ to_deadline (parse_deadline (string (t, 0, p), gt, pf, l),
success);
if (p != t.size () - 1)
test_timeout =
- to_timeout (parse_timeout (string (t, p + 1), tt, l), success);
+ to_timeout (parse_timeout (string (t, p + 1), tt, pf, l),
+ success);
}
else
- group_deadline = to_deadline (parse_deadline (t, gt, l), success);
+ group_deadline = to_deadline (parse_deadline (t, gt, pf, l),
+ success);
}
optional<deadline> group::
@@ -516,8 +519,9 @@ namespace build2
set_timeout (const string& t, bool success, const location& l)
{
fragment_deadline =
- to_deadline (parse_deadline (t, "test fragment timeout", l),
- success);
+ to_deadline (
+ parse_deadline (t, "test fragment timeout", "timeout: ", l),
+ success);
}
optional<deadline> test::
diff --git a/tests/test/script/runner/exit.testscript b/tests/test/script/runner/exit.testscript
index 24e51fa..8d3f052 100644
--- a/tests/test/script/runner/exit.testscript
+++ b/tests/test/script/runner/exit.testscript
@@ -76,7 +76,7 @@ empty_id = ''
: unexpected
:
$c <'exit "foo" "bar"' && $b 2>>EOE != 0
- testscript:1:1: error: unexpected argument 'bar'
+ testscript:1:1: error: exit: unexpected argument 'bar'
info: test id: 1
EOE
}
diff --git a/tests/test/script/runner/set.testscript b/tests/test/script/runner/set.testscript
index 777eccf..e19cce3 100644
--- a/tests/test/script/runner/set.testscript
+++ b/tests/test/script/runner/set.testscript
@@ -52,7 +52,7 @@
: both-newline-whitespace
:
$c <'set -nw' && $b 2>>EOE != 0
- testscript:1:1: error: both -n|--newline and -w|--whitespace specified
+ testscript:1:1: error: set: both -n|--newline and -w|--whitespace specified
info: test id: 1
EOE
}
@@ -63,28 +63,28 @@
: none
:
$c <'set -e' && $b 2>>EOE != 0
- testscript:1:1: error: missing variable name
+ testscript:1:1: error: set: missing variable name
info: test id: 1
EOE
: unexpected
:
$c <'set foo bar baz' && $b 2>>EOE != 0
- testscript:1:1: error: unexpected argument 'baz'
+ testscript:1:1: error: set: unexpected argument 'baz'
info: test id: 1
EOE
: empty-attrs
:
$c <"set '' baz" && $b 2>>EOE != 0
- testscript:1:1: error: empty variable attributes
+ testscript:1:1: error: set: empty variable attributes
info: test id: 1
EOE
: empty-var
:
$c <"set ''" && $b 2>>EOE != 0
- testscript:1:1: error: empty variable name
+ testscript:1:1: error: set: empty variable name
info: test id: 1
EOE
}
diff --git a/tests/test/script/runner/timeout.testscript b/tests/test/script/runner/timeout.testscript
index bf39034..5f87d39 100644
--- a/tests/test/script/runner/timeout.testscript
+++ b/tests/test/script/runner/timeout.testscript
@@ -54,14 +54,14 @@
: missing
:
$c <'timeout' && $b 2>>~%EOE% != 0
- testscript:1:1: error: missing timeout
+ testscript:1:1: error: timeout: missing timeout
%.
EOE
: invalid
:
$c <'timeout foo' && $b 2>>~%EOE% != 0
- testscript:1:1: error: invalid test fragment timeout 'foo'
+ testscript:1:1: error: timeout: invalid test fragment timeout 'foo'
%.
EOE
}
@@ -121,7 +121,7 @@
+timeout foo/
}
EOI
- testscript:2:4: error: invalid test group timeout 'foo'
+ testscript:2:4: error: timeout: invalid test group timeout 'foo'
%.
EOE
}
@@ -176,7 +176,7 @@
+timeout /foo
}
EOI
- testscript:2:4: error: invalid test timeout 'foo'
+ testscript:2:4: error: timeout: invalid test timeout 'foo'
%.
EOE
}
@@ -229,7 +229,7 @@
$c <<EOI && $b 2>>~%EOE% != 0
+timeout foo/
EOI
- testscript:1:2: error: invalid testscript timeout 'foo'
+ testscript:1:2: error: timeout: invalid testscript timeout 'foo'
%.
EOE
@@ -300,7 +300,7 @@
+timeout /foo
}
EOI
- testscript:2:4: error: invalid test timeout 'foo'
+ testscript:2:4: error: timeout: invalid test timeout 'foo'
%.
EOE
}