aboutsummaryrefslogtreecommitdiff
path: root/unit-tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-22 11:59:20 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:34 +0200
commit31e16a7413813293e3cccb6799eaa08b7af5af4e (patch)
tree45f06abbcf44652b58c3a2ad7485f64108994abd /unit-tests
parent8e3a8ffa6579a51f5a9351e1b99c07d3e1fbd234 (diff)
Implement support for compound tests
Diffstat (limited to 'unit-tests')
-rw-r--r--unit-tests/test/script/lexer/assign-line.test8
-rw-r--r--unit-tests/test/script/lexer/buildfile3
-rw-r--r--unit-tests/test/script/lexer/driver.cxx7
-rw-r--r--unit-tests/test/script/lexer/script-line.test18
-rw-r--r--unit-tests/test/script/lexer/variable-line.test18
-rw-r--r--unit-tests/test/script/parser/driver.cxx54
-rw-r--r--unit-tests/test/script/parser/scope.test107
7 files changed, 195 insertions, 20 deletions
diff --git a/unit-tests/test/script/lexer/assign-line.test b/unit-tests/test/script/lexer/assign-line.test
new file mode 100644
index 0000000..ce3e8a1
--- /dev/null
+++ b/unit-tests/test/script/lexer/assign-line.test
@@ -0,0 +1,8 @@
+# Note: this mode auto-expires after each token.
+#
+test.arguments += assign-line
+
+$* <";" >>EOO # semi-only
+;
+<newline>
+EOO
diff --git a/unit-tests/test/script/lexer/buildfile b/unit-tests/test/script/lexer/buildfile
index a9f6be9..70be793 100644
--- a/unit-tests/test/script/lexer/buildfile
+++ b/unit-tests/test/script/lexer/buildfile
@@ -7,6 +7,7 @@
import libs = libbutl%lib{butl}
src = token lexer diagnostics utility variable name test/script/{token lexer}
-exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs test{variable.test}
+exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs \
+test{script-line assign-line variable-line variable}
include ../../../../build2/
diff --git a/unit-tests/test/script/lexer/driver.cxx b/unit-tests/test/script/lexer/driver.cxx
index cd7110f..e37e29d 100644
--- a/unit-tests/test/script/lexer/driver.cxx
+++ b/unit-tests/test/script/lexer/driver.cxx
@@ -42,9 +42,12 @@ namespace build2
{
cin.exceptions (istream::failbit | istream::badbit);
- // The variable mode auto-expires so we need something underneath.
+ // Some modes auto-expire so we need something underneath.
//
- bool u (m == lexer_mode::variable);
+ bool u (m == lexer_mode::assign_line ||
+ m == lexer_mode::variable_line ||
+ m == lexer_mode::variable);
+
lexer l (cin, path ("stdin"), u ? lexer_mode::script_line : m);
if (u)
l.mode (m);
diff --git a/unit-tests/test/script/lexer/script-line.test b/unit-tests/test/script/lexer/script-line.test
new file mode 100644
index 0000000..b4fe3ef
--- /dev/null
+++ b/unit-tests/test/script/lexer/script-line.test
@@ -0,0 +1,18 @@
+test.arguments += script-line
+
+$* <"cmd;" >>EOO # semi
+'cmd'
+;
+<newline>
+EOO
+
+$* <"cmd ;" >>EOO # semi-separated
+'cmd'
+;
+<newline>
+EOO
+
+$* <";" >>EOO # semi-only
+;
+<newline>
+EOO
diff --git a/unit-tests/test/script/lexer/variable-line.test b/unit-tests/test/script/lexer/variable-line.test
new file mode 100644
index 0000000..543c6f9
--- /dev/null
+++ b/unit-tests/test/script/lexer/variable-line.test
@@ -0,0 +1,18 @@
+test.arguments += variable-line
+
+$* <"cmd;" >>EOO # semi
+'cmd'
+;
+<newline>
+EOO
+
+$* <"cmd ;" >>EOO # semi-separated
+'cmd'
+;
+<newline>
+EOO
+
+$* <";" >>EOO # semi-only
+;
+<newline>
+EOO
diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx
index 4d71082..09fd6f5 100644
--- a/unit-tests/test/script/parser/driver.cxx
+++ b/unit-tests/test/script/parser/driver.cxx
@@ -25,25 +25,45 @@ namespace build2
{
namespace script
{
+ // Here we assume we are running serially.
+ //
class print_runner: public runner
{
public:
+ print_runner (bool scope): scope_ (scope) {}
+
virtual void
- enter (scope&, const location&) override {}
+ enter (scope&, const location&) override
+ {
+ if (scope_)
+ {
+ cout << ind_ << "{" << endl;
+ ind_ += " ";
+ }
+ }
virtual void
run (scope&, const command& t, size_t, const location&) override
{
- // Here we assume we are running serially.
- //
- cout << t << endl;
+ cout << ind_ << t << endl;
}
virtual void
- leave (scope&, const location&) override {}
+ leave (scope&, const location&) override
+ {
+ if (scope_)
+ {
+ ind_.resize (ind_.size () - 2);
+ cout << ind_ << "}" << endl;
+ }
+ }
+
+ private:
+ bool scope_;
+ string ind_;
};
- // Usage: argv[0] [<testscript-name>]
+ // Usage: argv[0] [-s] [<testscript-name>]
//
int
main (int argc, char* argv[])
@@ -53,9 +73,27 @@ namespace build2
init (1); // Default verbosity.
reset (strings ()); // No command line variables.
+ bool scope (false);
+ path name;
+
+ for (int i (1); i != argc; ++i)
+ {
+ string a (argv[i]);
+
+ if (a == "-s")
+ scope = true;
+ else
+ {
+ name = path (move (a));
+ break;
+ }
+ }
+
+ if (name.empty ())
+ name = path ("testscript");
+
try
{
- path name (argc > 1 ? argv[1] : "testscript");
cin.exceptions (istream::failbit | istream::badbit);
// Enter mock targets. Use fixed names and paths so that we can use
@@ -83,7 +121,7 @@ namespace build2
// Parse and run.
//
script s (tt, st);
- print_runner r;
+ print_runner r (scope);
parser p;
p.pre_parse (cin, name, s);
diff --git a/unit-tests/test/script/parser/scope.test b/unit-tests/test/script/parser/scope.test
index a2c6d9f..7517022 100644
--- a/unit-tests/test/script/parser/scope.test
+++ b/unit-tests/test/script/parser/scope.test
@@ -1,15 +1,104 @@
$* testscript <'cmd $@' >"cmd 1" # id-testscript
$* foo.test <'cmd $@' >"cmd foo/1" # id
-wd = [dir_path] $build.work
-wd += test
-wd += 1
+wd = [dir_path] $~;
+wd += test;
+wd += 1;
$* testscript <'cmd $~' >"cmd $wd" # wd-testscript
-# @@ TMP wd1
+wd = [dir_path] $~;
+wd += test;
+wd += foo;
+wd += 1;
+$* foo.test <'cmd $~' >"cmd $wd" # wd
+
+$* -s <<EOI >>EOO # compound-2
+cmd1;
+cmd2
+EOI
+{
+ {
+ cmd1
+ cmd2
+ }
+}
+EOO
+
+$* -s <<EOI >>EOO # compound-3
+cmd1;
+cmd2;
+cmd3
+EOI
+{
+ {
+ cmd1
+ cmd2
+ cmd3
+ }
+}
+EOO
+
+$* -s <<EOI >>EOO # compound-var
+cmd1;
+x = abc;
+cmd2 \$x
+EOI
+{
+ {
+ cmd1
+ cmd2 abc
+ }
+}
+EOO
+
+$* -s <<EOI >>EOO # compound-var-first
+x = abc;
+cmd \$x
+EOI
+{
+ {
+ cmd abc
+ }
+}
+EOO
+
+$* -s <<EOI >>EOO # var-setup-tdown
+x = abc
+cmd \$x
+y = 123
+EOI
+{
+ {
+ cmd abc
+ }
+}
+EOO
+
+$* <<EOI 2>>EOE != 0 # test-after-tdown
+cmd1
+x = abc
+cmd2
+EOI
+testscript:3:1: error: test after teardown
+ testscript:2:1: info: last teardown line appears here
+EOE
+
+$* <<EOI 2>>EOE != 0 # expected-line
+cmd;
+EOI
+testscript:2:1: error: expected another line after semicolon
+EOE
+
+# @@ Need newline-less support.
#
-wd1 = [dir_path] $build.work
-wd1 += test
-wd1 += foo
-wd1 += 1
-$* foo.test <'cmd $~' >"cmd $wd1" # wd
+#$* <<EOI 2>>EOE != 0 # expected-newline-cmd
+#cmd ;\
+#EOI
+#testscript:2:1: error: expected newline instead of <end of file>
+#EOE
+
+#$* <<EOI 2>>EOE != 0 # expected-newline-var
+#x =abc;\
+#EOI
+#testscript:2:1: error: expected newline instead of <end of file>
+#EOE