diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-10-19 17:51:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-04 09:26:33 +0200 |
commit | 08b6f40b285780906c70c0d56483b8edbb077667 (patch) | |
tree | ce78deb752756a934cdbd8b7b3df875b48addcd2 | |
parent | e84fd4aeeb15cd5894193dc403afc60e0dd7f321 (diff) |
Add testscript parser unit test
-rw-r--r-- | build2/test/script/script.cxx | 2 | ||||
-rw-r--r-- | unit-tests/test/script/buildfile | 2 | ||||
-rw-r--r-- | unit-tests/test/script/lexer/buildfile | 2 | ||||
-rw-r--r-- | unit-tests/test/script/lexer/driver.cxx | 2 | ||||
-rw-r--r-- | unit-tests/test/script/parser/buildfile | 15 | ||||
-rw-r--r-- | unit-tests/test/script/parser/driver.cxx | 99 | ||||
-rw-r--r-- | unit-tests/test/script/parser/testscript | 40 |
7 files changed, 159 insertions, 3 deletions
diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx index 1fb100d..5e79cab 100644 --- a/build2/test/script/script.cxx +++ b/build2/test/script/script.cxx @@ -150,6 +150,8 @@ namespace build2 // Set the script CWD ($~) which is the $out_base/<script-name>. // + // @@ This will conflict for 'testscript'! + // assign (cwd_var) = dir_path (tt.out_dir ()) /= st.name; } diff --git a/unit-tests/test/script/buildfile b/unit-tests/test/script/buildfile index b84e5ce..6b303e1 100644 --- a/unit-tests/test/script/buildfile +++ b/unit-tests/test/script/buildfile @@ -2,6 +2,6 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -d = lexer/ +d = lexer/ parser/ ./: $d include $d diff --git a/unit-tests/test/script/lexer/buildfile b/unit-tests/test/script/lexer/buildfile index f67f9b3..0d32710 100644 --- a/unit-tests/test/script/lexer/buildfile +++ b/unit-tests/test/script/lexer/buildfile @@ -1,4 +1,4 @@ -# file : unit-tests/test/script/buildfile +# file : unit-tests/test/script/lexer/buildfile # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file diff --git a/unit-tests/test/script/lexer/driver.cxx b/unit-tests/test/script/lexer/driver.cxx index b80eed9..6d9bfb7 100644 --- a/unit-tests/test/script/lexer/driver.cxx +++ b/unit-tests/test/script/lexer/driver.cxx @@ -1,4 +1,4 @@ -// file : unit-tests/test/script/driver.cxx -*- C++ -*- +// file : unit-tests/test/script/lexer/driver.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2016 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file diff --git a/unit-tests/test/script/parser/buildfile b/unit-tests/test/script/parser/buildfile new file mode 100644 index 0000000..56a4682 --- /dev/null +++ b/unit-tests/test/script/parser/buildfile @@ -0,0 +1,15 @@ +# file : unit-tests/test/script/parser/buildfile +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +#@@ Temporary until we get utility library support. +# +import libs = libbutl%lib{butl} +src = token lexer parser diagnostics utility variable name context target \ +scope prerequisite file module operation rule b-options algorithm search \ +filesystem config/{utility init operation} dump types-parsers \ +test/{target script/{token lexer parser script}} + +exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs #test{testscript} + +include ../../../../build2/ diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx new file mode 100644 index 0000000..5e24faa --- /dev/null +++ b/unit-tests/test/script/parser/driver.cxx @@ -0,0 +1,99 @@ +// file : unit-tests/test/script/parser/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <cassert> +#include <iostream> + +#include <build2/types> +#include <build2/utility> + +#include <build2/target> +#include <build2/context> + +#include <build2/test/target> + +#include <build2/test/script/token> +#include <build2/test/script/parser> +#include <build2/test/script/runner> + +using namespace std; + +namespace build2 +{ + namespace test + { + namespace script + { + class print_runner: public runner + { + public: + virtual void + run (const test& t) override + { + // Here we assume we are running serially. + // + cout << t << endl; + } + }; + + int + main () + { + tracer trace ("main"); + + init (1); // Default verbosity. + reset (strings ()); // No command line variables. + + try + { + path name ("testscript"); + cin.exceptions (istream::failbit | istream::badbit); + + // Enter mock targets. Use fixed names and paths so that we can use + // them in expected results. Strictly speaking target paths should + // be absolute. However, the testscript implementation doesn't + // really care. + // + file& tt ( + targets.insert<file> (work, + dir_path (), + "driver", + &extension_pool.find (""), + trace)); + + testscript& st ( + targets.insert<testscript> (work, + dir_path (), + "testscript", + &extension_pool.find (""), + trace)); + + tt.path (path ("driver")); + st.path (path ("testscript")); + + // Parse and run. + // + script s (tt, st); + print_runner r; + + parser p; + p.pre_parse (cin, name, s); + p.parse (name, s, r); + } + catch (const failed&) + { + return 1; + } + + return 0; + } + } + } +} + +int +main () +{ + return build2::test::script::main (); +} diff --git a/unit-tests/test/script/parser/testscript b/unit-tests/test/script/parser/testscript new file mode 100644 index 0000000..2a9c2b9 --- /dev/null +++ b/unit-tests/test/script/parser/testscript @@ -0,0 +1,40 @@ +foo != 0 +a=aaa +foo bar <"bbb $a ccc" >ddd 2>>EOE == 2 +eee +EOE +foo +bar +cmd $build.version.string +foo = baz +$foo +fox = $foo-$build.version.string +$fox +$test +$~ +$* +$0 +test = xxx +$0 +$* +test.options += --foo +$1 +$* +test.arguments += bar +$2 +$* +($3 == [null]) + +x = [uint64] 001 +foo $x +cmd abc$(x)23 +cmd >>EOO << EOI +foo +$x +bar +EOO +$x$x$x +EOI + +y = >> +cmd "2"$y |