From 08b6f40b285780906c70c0d56483b8edbb077667 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 19 Oct 2016 17:51:51 +0200 Subject: Add testscript parser unit test --- build2/test/script/script.cxx | 2 + unit-tests/test/script/buildfile | 2 +- unit-tests/test/script/lexer/buildfile | 2 +- unit-tests/test/script/lexer/driver.cxx | 2 +- unit-tests/test/script/parser/buildfile | 15 +++++ unit-tests/test/script/parser/driver.cxx | 99 ++++++++++++++++++++++++++++++++ unit-tests/test/script/parser/testscript | 40 +++++++++++++ 7 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 unit-tests/test/script/parser/buildfile create mode 100644 unit-tests/test/script/parser/driver.cxx create mode 100644 unit-tests/test/script/parser/testscript 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/. // + // @@ 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 +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include + +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 (work, + dir_path (), + "driver", + &extension_pool.find (""), + trace)); + + testscript& st ( + targets.insert (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 -- cgit v1.1