aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-10-18 16:21:01 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:29 +0200
commit24f3e34e6c1cec0500cfa6c22285e4677361b3a7 (patch)
tree1c0e76466598a28a8539b550c23c863dcb6cb9f2
parent3eb0cd7fe3c1dec0bb3b7e1d225107e55ca4b435 (diff)
Complete testscript parser's parse_command_exit()
-rw-r--r--build2/test/script/parser.cxx25
-rw-r--r--unit-tests/test/script/lexer/script-line.test1
2 files changed, 20 insertions, 6 deletions
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx
index 74bacee..626bc38 100644
--- a/build2/test/script/parser.cxx
+++ b/build2/test/script/parser.cxx
@@ -525,10 +525,7 @@ namespace build2
// going to continue lexing in the script_line mode.
//
if (tt == type::equal || tt == type::not_equal)
- {
- next (t, tt);
ts.exit = parse_command_exit (t, tt);
- }
if (tt != type::newline)
fail (t) << "unexpected " << t;
@@ -559,14 +556,30 @@ namespace build2
command_exit parser::
parse_command_exit (token& t, token_type& tt)
{
+ exit_comparison comp (tt == type::equal
+ ? exit_comparison::eq
+ : exit_comparison::ne);
+
// The next chunk should be the exit status.
//
+ next (t, tt);
names ns (parse_names (t, tt, true, "exit status"));
+ unsigned long es (256);
+
+ try
+ {
+ if (ns.size () == 1 && ns[0].simple () && !ns[0].empty ())
+ es = stoul (ns[0].value);
+ }
+ catch (const exception&)
+ {
+ }
- //@@ TODO: validate to be single, simple, non-empty name that
- // converts to integer (is exit status always non-negative).
+ if (es > 255)
+ fail (t) << "command exit status expected instead of " << ns <<
+ info << "must be an unsigned integer less than 256";
- return command_exit {exit_comparison::eq, 0};
+ return command_exit {comp, static_cast<uint8_t> (es)};
}
string parser::
diff --git a/unit-tests/test/script/lexer/script-line.test b/unit-tests/test/script/lexer/script-line.test
index 6a55926..ff67801 100644
--- a/unit-tests/test/script/lexer/script-line.test
+++ b/unit-tests/test/script/lexer/script-line.test
@@ -1,3 +1,4 @@
+foo != 0
a=aaa
foo bar <"bbb $a ccc" >ddd 2>>EOE
eee