aboutsummaryrefslogtreecommitdiff
path: root/unit-tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-08 16:37:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-08 16:38:53 +0200
commitf4b2107284329b12f595eba856072b79b824a63f (patch)
tree0e34fdcd61747adc0cad2c5af5f32d27dab42ae2 /unit-tests
parent278140ebf2bc97eb72a1e8adb04a40a0a5807d8f (diff)
Implement testscript command-if
Diffstat (limited to 'unit-tests')
-rw-r--r--unit-tests/test/script/parser/buildfile3
-rw-r--r--unit-tests/test/script/parser/description.test2
-rw-r--r--unit-tests/test/script/parser/driver.cxx39
-rw-r--r--unit-tests/test/script/parser/if-else.test518
-rw-r--r--unit-tests/test/script/parser/scope.test4
5 files changed, 557 insertions, 9 deletions
diff --git a/unit-tests/test/script/parser/buildfile b/unit-tests/test/script/parser/buildfile
index f87f7e8..eab5b36 100644
--- a/unit-tests/test/script/parser/buildfile
+++ b/unit-tests/test/script/parser/buildfile
@@ -12,6 +12,7 @@ test/{target script/{token lexer parser script}}
exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs \
test{cleanup command-re-parse description exit expansion here-document \
- here-string include pipe-expr pre-parse redirect scope setup-teardown}
+ here-string if-else include pipe-expr pre-parse redirect scope \
+ setup-teardown}
include ../../../../build2/
diff --git a/unit-tests/test/script/parser/description.test b/unit-tests/test/script/parser/description.test
index c2c441b..48a2faf 100644
--- a/unit-tests/test/script/parser/description.test
+++ b/unit-tests/test/script/parser/description.test
@@ -172,7 +172,7 @@ $* <<EOI 2>>EOE != 0 # both
: foo
cmd : bar
EOI
-testscript:2:1: error: both leading and trailing description
+testscript:2:1: error: both leading and trailing descriptions
EOE
# Legal places for a description.
diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx
index badb658..de34da7 100644
--- a/unit-tests/test/script/parser/driver.cxx
+++ b/unit-tests/test/script/parser/driver.cxx
@@ -30,7 +30,8 @@ namespace build2
class print_runner: public runner
{
public:
- print_runner (bool scope, bool id): scope_ (scope), id_ (id) {}
+ print_runner (bool scope, bool id, bool line)
+ : scope_ (scope), id_ (id), line_ (line) {}
virtual void
enter (scope& s, const location&) override
@@ -81,9 +82,33 @@ namespace build2
}
virtual void
- run (scope&, const command_expr& e, size_t, const location&) override
+ run (scope&,
+ const command_expr& e,
+ size_t i,
+ const location&) override
{
- cout << ind_ << e << endl;
+ cout << ind_ << e;
+
+ if (line_)
+ cout << " # " << i;
+
+ cout << endl;
+ }
+
+ virtual bool
+ run_if (scope&,
+ const command_expr& e,
+ size_t i,
+ const location&) override
+ {
+ cout << ind_ << "? " << e;
+
+ if (line_)
+ cout << " # " << i;
+
+ cout << endl;
+
+ return e.back ().pipe.back ().program.string () == "true";
}
virtual void
@@ -99,10 +124,11 @@ namespace build2
private:
bool scope_;
bool id_;
+ bool line_;
string ind_;
};
- // Usage: argv[0] [-s] [-i] [<testscript-name>]
+ // Usage: argv[0] [-s] [-i] [-l] [<testscript-name>]
//
int
main (int argc, char* argv[])
@@ -114,6 +140,7 @@ namespace build2
bool scope (false);
bool id (false);
+ bool line (false);
path name;
for (int i (1); i != argc; ++i)
@@ -124,6 +151,8 @@ namespace build2
scope = true;
else if (a == "-i")
id = true;
+ else if (a == "-l")
+ line = true;
else
{
name = path (move (a));
@@ -168,7 +197,7 @@ namespace build2
script s (tt, st, dir_path (work) /= "test-driver");
p.pre_parse (cin, s);
- print_runner r (scope, id);
+ print_runner r (scope, id, line);
p.parse (s, r);
}
catch (const failed&)
diff --git a/unit-tests/test/script/parser/if-else.test b/unit-tests/test/script/parser/if-else.test
new file mode 100644
index 0000000..8663920
--- /dev/null
+++ b/unit-tests/test/script/parser/if-else.test
@@ -0,0 +1,518 @@
+: if-true
+:
+$* <<EOI >>EOO
+if true foo
+ cmd1
+ cmd2
+end
+EOI
+? true foo
+cmd1
+cmd2
+EOO
+
+: if-false
+:
+$* <<EOI >>EOO
+if false foo
+ cmd1
+ cmd2
+end
+EOI
+? false foo
+EOO
+
+: ifn-true
+:
+$* <<EOI >>EOO
+if! true foo
+ cmd1
+ cmd2
+end
+EOI
+? true foo
+EOO
+
+: ifn-false
+:
+$* <<EOI >>EOO
+if! false foo
+ cmd1
+ cmd2
+end
+EOI
+? false foo
+cmd1
+cmd2
+EOO
+
+: elif-true
+:
+$* <<EOI >>EOO
+if false
+ cmd1
+ cmd2
+elif true
+ cmd3
+ cmd4
+end
+EOI
+? false
+? true
+cmd3
+cmd4
+EOO
+
+: elif-false
+:
+$* <<EOI >>EOO
+if false
+ cmd1
+ cmd2
+elif false
+ cmd3
+ cmd4
+end
+EOI
+? false
+? false
+EOO
+
+: elifn-true
+:
+$* <<EOI >>EOO
+if false
+ cmd1
+ cmd2
+elif! true
+ cmd3
+ cmd4
+end
+EOI
+? false
+? true
+EOO
+
+: elifn-false
+:
+$* <<EOI >>EOO
+if false
+ cmd1
+ cmd2
+elif! false
+ cmd3
+ cmd4
+end
+EOI
+? false
+? false
+cmd3
+cmd4
+EOO
+
+: else-true
+:
+$* <<EOI >>EOO
+if false
+ cmd1
+ cmd2
+else
+ cmd3
+ cmd4
+end
+EOI
+? false
+cmd3
+cmd4
+EOO
+
+: else-false
+:
+$* <<EOI >>EOO
+if true
+ cmd1
+ cmd2
+else
+ cmd3
+ cmd4
+end
+EOI
+? true
+cmd1
+cmd2
+EOO
+
+: if-chain
+:
+$* <<EOI >>EOO
+if false
+ cmd
+ cmd
+elif false
+ cmd
+ cmd
+elif false
+ cmd
+ cmd
+elif true
+ cmd1
+ cmd2
+elif false
+ cmd
+ cmd
+else
+ cmd
+ cmd
+end
+EOI
+? false
+? false
+? false
+? true
+cmd1
+cmd2
+EOO
+
+: nested-take
+:
+$* <<EOI >>EOO
+if true
+ cmd1
+ if false
+ cmd
+ elif false
+ if true
+ cmd
+ end
+ else
+ cmd2
+ end
+ cmd3
+end
+EOI
+? true
+cmd1
+? false
+? false
+cmd2
+cmd3
+EOO
+
+: nested-skip
+:
+$* <<EOI >>EOO
+if false
+ cmd1
+ if false
+ cmd
+ elif false
+ if true
+ cmd
+ end
+ else
+ cmd2
+ end
+ cmd3
+else
+ cmd
+end
+EOI
+? false
+cmd
+EOO
+
+: line-index
+:
+$* -l <<EOI >>EOO
+if false
+ cmd
+ if true
+ cmd
+ end
+ cmd
+elif false
+ cmd
+else
+ cmd
+end
+EOI
+? false # 1
+? false # 6
+cmd # 8
+EOO
+
+: var
+:
+$* <<EOI >>EOO
+if true
+ x = foo
+else
+ x = bar
+end;
+cmd \$x
+EOI
+? true
+cmd foo
+EOO
+
+: semi-inside
+:
+$* <<EOI 2>>EOE != 0
+if
+ cmd;
+ cmd
+end
+EOI
+testscript:2:3: error: ';' inside 'if'
+EOE
+
+: colon-inside-leading
+:
+$* <<EOI 2>>EOE != 0
+if
+ : foo
+ cmd
+end
+EOI
+testscript:2:3: error: description inside 'if'
+EOE
+
+: colon-inside-trailing
+:
+$* <<EOI 2>>EOE != 0
+if
+ cmd : foo
+end
+EOI
+testscript:2:3: error: description inside 'if'
+EOE
+
+: eos-inside
+:
+$* <<EOI 2>>EOE != 0
+if
+EOI
+testscript:2:1: error: expected closing 'end'
+EOE
+
+: scope-inside
+:
+$* <<EOI 2>>EOE != 0
+if
+ {
+ }
+end
+EOI
+testscript:2:3: error: expected closing 'end'
+EOE
+
+: setup-inside
+:
+$* <<EOI 2>>EOE != 0
+if
+ +cmd
+end
+EOI
+testscript:2:3: error: setup command inside 'if'
+EOE
+
+: tdown-inside
+:
+$* <<EOI 2>>EOE != 0
+if
+ -cmd
+end
+EOI
+testscript:2:3: error: teardown command inside 'if'
+EOE
+
+: if-without-command
+:
+$* <<EOI 2>>EOE != 0
+if
+ cmd
+end
+EOI
+testscript:1:3: error: missing program
+EOE
+
+: command-after-else
+:
+$* <<EOI 2>>EOE != 0
+if true
+ cmd
+else cmd
+ cmd
+end
+EOI
+testscript:3:6: error: expected newline instead of 'cmd'
+EOE
+
+: command-after-end
+:
+$* <<EOI 2>>EOE != 0
+if true
+ cmd
+end cmd
+EOI
+testscript:3:5: error: expected newline instead of 'cmd'
+EOE
+
+: elif-without-if
+:
+$* <<EOI 2>>EOE != 0
+cmd
+elif true
+ cmd
+end
+EOI
+testscript:2:1: error: 'elif' without preceding 'if'
+EOE
+
+: elifn-without-if
+:
+$* <<EOI 2>>EOE != 0
+cmd
+elif! true
+ cmd
+end
+EOI
+testscript:2:1: error: 'elif!' without preceding 'if'
+EOE
+
+: else-without-if
+:
+$* <<EOI 2>>EOE != 0
+cmd
+else
+ cmd
+end
+EOI
+testscript:2:1: error: 'else' without preceding 'if'
+EOE
+
+: end-without-if
+:
+$* <<EOI 2>>EOE != 0
+cmd
+end
+EOI
+testscript:2:1: error: 'end' without preceding 'if'
+EOE
+
+: else-after-else
+:
+$* <<EOI 2>>EOE != 0
+if false
+ cmd
+else
+ cmd
+else
+ cmd
+end
+EOI
+testscript:5:1: error: 'else' after 'else'
+EOE
+
+: elif-after-else
+:
+$* <<EOI 2>>EOE != 0
+if false
+ cmd
+else
+ cmd
+elif true
+ cmd
+end
+EOI
+testscript:5:1: error: 'elif' after 'else'
+EOE
+
+: if-after-semi
+:
+$* -s <<EOI >>EOO
+cmd1;
+if true
+ cmd2
+end
+EOI
+{
+ {
+ cmd1
+ ? true
+ cmd2
+ }
+}
+EOO
+
+: setup-if
+:
+$* -s <<EOI >>EOO
++if true
+ cmd
+end
+EOI
+{
+ ? true
+ cmd
+}
+EOO
+
+: tdown-if
+:
+$* -s <<EOI >>EOO
+-if true
+ cmd
+end
+EOI
+{
+ ? true
+ cmd
+}
+EOO
+
+: semi-after-end
+:
+$* -s <<EOI >>EOO
+if true
+ cmd1
+end;
+cmd2
+EOI
+{
+ {
+ ? true
+ cmd1
+ cmd2
+ }
+}
+EOO
+
+: colon-after-end
+:
+$* -s <<EOI >>EOO
+if true
+ cmd1
+ cmd2
+end : test
+EOI
+{
+ : id:test
+ {
+ ? true
+ cmd1
+ cmd2
+ }
+}
+EOO
+
+: leading-and-trailing-description
+:
+$* <<EOI 2>>EOE != 0
+: foo
+if true
+ cmd
+end : bar
+EOI
+testscript:4:1: error: both leading and trailing descriptions
+EOE
diff --git a/unit-tests/test/script/parser/scope.test b/unit-tests/test/script/parser/scope.test
index 38b6a76..8708b19 100644
--- a/unit-tests/test/script/parser/scope.test
+++ b/unit-tests/test/script/parser/scope.test
@@ -123,7 +123,7 @@ $* <<EOI 2>>EOE != 0 # expected-line-rcbrace
cmd;
}
EOI
-testscript:3:1: error: expected another line after semicolon
+testscript:3:1: error: expected another line after ';'
EOE
$* <<:EOI 2>>EOE != 0 # expected-newline-rcbrace
@@ -217,7 +217,7 @@ EOE
$* <<EOI 2>>EOE != 0 # expected-line-eof
cmd;
EOI
-testscript:2:1: error: expected another line after semicolon
+testscript:2:1: error: expected another line after ';'
EOE
$* <<:EOI 2>>EOE != 0 # expected-newline-cmd