aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/test
diff options
context:
space:
mode:
Diffstat (limited to 'unit-tests/test')
-rw-r--r--unit-tests/test/script/lexer/driver.cxx21
-rw-r--r--unit-tests/test/script/lexer/script-line.test10
-rw-r--r--unit-tests/test/script/lexer/variable.test46
3 files changed, 70 insertions, 7 deletions
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
+'*'
+<newline>
+EOO
+
+$* <"*abc" >>EOO
+'*'
+'abc'
+<newline>
+EOO
+
+$* <"~" >>EOO
+'~'
+<newline>
+EOO
+
+$* <"~123" >>EOO
+'~'
+'123'
+<newline>
+EOO
+
+$* <"0" >>EOO
+'0'
+<newline>
+EOO
+
+$* <"10" >>EOO
+'10'
+<newline>
+EOO
+
+$* <"101" >>EOO
+'101'
+<newline>
+EOO
+
+$* <"1abc" >>EOO
+'1'
+'abc'
+<newline>
+EOO