diff options
Diffstat (limited to 'unit-tests/test/script/parser')
-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 |
3 files changed, 154 insertions, 0 deletions
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 |