From 4230333bc5b32d30e35264b1104240bb5e2247ff Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 16 Oct 2016 13:29:57 +0200 Subject: Implement testscript $*, $NN, $~ special variables --- unit-tests/test/script/lexer/driver.cxx | 21 ++++++++---- unit-tests/test/script/lexer/script-line.test | 10 ++++++ unit-tests/test/script/lexer/variable.test | 46 +++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 unit-tests/test/script/lexer/variable.test (limited to 'unit-tests/test/script') diff --git a/unit-tests/test/script/lexer/driver.cxx b/unit-tests/test/script/lexer/driver.cxx index 6e5167d..7e237ed 100644 --- a/unit-tests/test/script/lexer/driver.cxx +++ b/unit-tests/test/script/lexer/driver.cxx @@ -29,18 +29,25 @@ namespace build2 assert (argc == 2); string s (argv[1]); - if (s == "script") m = lexer_mode::script_line; - else if (s == "variable") m = lexer_mode::variable_line; - else if (s == "test") m = lexer_mode::test_line; - else if (s == "command") m = lexer_mode::command_line; - else if (s == "here") m = lexer_mode::here_line; - else assert (false); + if (s == "script-line") m = lexer_mode::script_line; + else if (s == "variable-line") m = lexer_mode::variable_line; + else if (s == "test-line") m = lexer_mode::test_line; + else if (s == "command-line") m = lexer_mode::command_line; + else if (s == "here-line") m = lexer_mode::here_line; + else if (s == "variable") m = lexer_mode::variable; + else assert (false); } try { cin.exceptions (istream::failbit | istream::badbit); - lexer l (cin, path ("stdin"), m); + + // The variable mode auto-expires so we need something underneath. + // + bool u (m == lexer_mode::variable); + lexer l (cin, path ("stdin"), u ? lexer_mode::script_line : m); + if (u) + l.mode (m); // No use printing eos since we will either get it or loop forever. // diff --git a/unit-tests/test/script/lexer/script-line.test b/unit-tests/test/script/lexer/script-line.test index 8fd77ce..f03c3bb 100644 --- a/unit-tests/test/script/lexer/script-line.test +++ b/unit-tests/test/script/lexer/script-line.test @@ -6,3 +6,13 @@ $foo fox = $foo-$cxx.target.class $fox $test +$~ +$* +$0 +test = xxx +$0 +$* +test.options += --foo +$1 +test.arguments += bar +$2 diff --git a/unit-tests/test/script/lexer/variable.test b/unit-tests/test/script/lexer/variable.test new file mode 100644 index 0000000..6478fea --- /dev/null +++ b/unit-tests/test/script/lexer/variable.test @@ -0,0 +1,46 @@ +# Test handling custom variable names ($*, $~, $NN). +# +test.arguments += variable + +$* <"*" >>EOO +'*' + +EOO + +$* <"*abc" >>EOO +'*' +'abc' + +EOO + +$* <"~" >>EOO +'~' + +EOO + +$* <"~123" >>EOO +'~' +'123' + +EOO + +$* <"0" >>EOO +'0' + +EOO + +$* <"10" >>EOO +'10' + +EOO + +$* <"101" >>EOO +'101' + +EOO + +$* <"1abc" >>EOO +'1' +'abc' + +EOO -- cgit v1.1