From 77410b0cdde47219d6c6a36533fcb9354f17c3dd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 6 Mar 2019 23:06:30 +0300 Subject: Use new setup for unit tests --- build/root.build | 6 - build2/.gitignore | 5 + build2/buildfile | 24 +- build2/cc/lexer+char-literal.test.testscript | 67 +++ build2/cc/lexer+comment.test.testscript | 88 ++++ build2/cc/lexer+line.test.testscript | 67 +++ build2/cc/lexer+number.test.testscript | 48 ++ build2/cc/lexer+preprocessor.test.testscript | 73 +++ build2/cc/lexer+raw-string-literal.test.testscript | 90 ++++ build2/cc/lexer+string-literal.test.testscript | 65 +++ build2/cc/lexer.test.cxx | 80 +++ build2/cc/parser+module.test.testscript | 149 ++++++ build2/cc/parser.test.cxx | 66 +++ build2/function+call.test.testscript | 161 ++++++ build2/function+syntax.test.testscript | 29 ++ build2/function.test.cxx | 131 +++++ build2/lexer+buildspec.test.testscript | 16 + build2/lexer+comment.test.testscript | 139 ++++++ build2/lexer+eval.test.testscript | 76 +++ build2/lexer+quoting.test.testscript | 108 ++++ build2/lexer.test.cxx | 98 ++++ build2/name.test.cxx | 96 ++++ build2/scheduler.test.cxx | 187 +++++++ .../script/lexer+command-expansion.test.testscript | 248 +++++++++ .../test/script/lexer+command-line.test.testscript | 208 ++++++++ .../script/lexer+description-line.test.testscript | 33 ++ .../test/script/lexer+first-token.test.testscript | 97 ++++ .../test/script/lexer+second-token.test.testscript | 68 +++ .../script/lexer+variable-line.test.testscript | 28 ++ build2/test/script/lexer+variable.test.testscript | 70 +++ build2/test/script/lexer.test.cxx | 85 ++++ build2/test/script/parser+cleanup.test.testscript | 58 +++ .../test/script/parser+command-if.test.testscript | 548 ++++++++++++++++++++ .../script/parser+command-re-parse.test.testscript | 12 + .../test/script/parser+description.test.testscript | 486 ++++++++++++++++++ .../test/script/parser+directive.test.testscript | 74 +++ build2/test/script/parser+exit.test.testscript | 27 + .../test/script/parser+expansion.test.testscript | 36 ++ .../script/parser+here-document.test.testscript | 213 ++++++++ .../test/script/parser+here-string.test.testscript | 19 + build2/test/script/parser+include.test.testscript | 104 ++++ .../test/script/parser+pipe-expr.test.testscript | 133 +++++ .../test/script/parser+pre-parse.test.testscript | 23 + build2/test/script/parser+redirect.test.testscript | 356 +++++++++++++ build2/test/script/parser+regex.test.testscript | 223 +++++++++ build2/test/script/parser+scope-if.test.testscript | 554 +++++++++++++++++++++ build2/test/script/parser+scope.test.testscript | 280 +++++++++++ .../script/parser+setup-teardown.test.testscript | 151 ++++++ build2/test/script/parser.test.cxx | 242 +++++++++ build2/test/script/regex.test.cxx | 301 +++++++++++ buildfile | 1 - unit-tests/.gitignore | 6 - unit-tests/cc/lexer/buildfile | 6 - unit-tests/cc/lexer/char-literal.testscript | 67 --- unit-tests/cc/lexer/comment.testscript | 88 ---- unit-tests/cc/lexer/driver.cxx | 80 --- unit-tests/cc/lexer/line.testscript | 67 --- unit-tests/cc/lexer/number.testscript | 48 -- unit-tests/cc/lexer/preprocessor.testscript | 73 --- unit-tests/cc/lexer/raw-string-literal.testscript | 90 ---- unit-tests/cc/lexer/string-literal.testscript | 65 --- unit-tests/cc/parser/buildfile | 6 - unit-tests/cc/parser/driver.cxx | 66 --- unit-tests/cc/parser/module.testscript | 149 ------ unit-tests/function/buildfile | 6 - unit-tests/function/call.testscript | 161 ------ unit-tests/function/driver.cxx | 131 ----- unit-tests/function/syntax.testscript | 29 -- unit-tests/lexer/buildfile | 6 - unit-tests/lexer/buildspec.testscript | 16 - unit-tests/lexer/comment.testscript | 139 ------ unit-tests/lexer/driver.cxx | 98 ---- unit-tests/lexer/eval.testscript | 76 --- unit-tests/lexer/quoting.testscript | 108 ---- unit-tests/name/buildfile | 6 - unit-tests/name/driver.cxx | 96 ---- unit-tests/scheduler/buildfile | 6 - unit-tests/scheduler/driver.cxx | 187 ------- unit-tests/test/script/lexer/buildfile | 6 - .../test/script/lexer/command-expansion.testscript | 248 --------- .../test/script/lexer/command-line.testscript | 208 -------- .../test/script/lexer/description-line.testscript | 33 -- unit-tests/test/script/lexer/driver.cxx | 85 ---- .../test/script/lexer/first-token.testscript | 97 ---- .../test/script/lexer/second-token.testscript | 68 --- .../test/script/lexer/variable-line.testscript | 28 -- unit-tests/test/script/lexer/variable.testscript | 70 --- unit-tests/test/script/parser/buildfile | 6 - unit-tests/test/script/parser/cleanup.testscript | 58 --- .../test/script/parser/command-if.testscript | 548 -------------------- .../test/script/parser/command-re-parse.testscript | 12 - .../test/script/parser/description.testscript | 486 ------------------ unit-tests/test/script/parser/directive.testscript | 74 --- unit-tests/test/script/parser/driver.cxx | 242 --------- unit-tests/test/script/parser/exit.testscript | 27 - unit-tests/test/script/parser/expansion.testscript | 36 -- .../test/script/parser/here-document.testscript | 213 -------- .../test/script/parser/here-string.testscript | 19 - unit-tests/test/script/parser/include.testscript | 104 ---- unit-tests/test/script/parser/pipe-expr.testscript | 133 ----- unit-tests/test/script/parser/pre-parse.testscript | 23 - unit-tests/test/script/parser/redirect.testscript | 356 ------------- unit-tests/test/script/parser/regex.testscript | 223 --------- unit-tests/test/script/parser/scope-if.testscript | 554 --------------------- unit-tests/test/script/parser/scope.testscript | 280 ----------- .../test/script/parser/setup-teardown.testscript | 151 ------ unit-tests/test/script/regex/buildfile | 6 - unit-tests/test/script/regex/driver.cxx | 301 ----------- 108 files changed, 6537 insertions(+), 6581 deletions(-) create mode 100644 build2/cc/lexer+char-literal.test.testscript create mode 100644 build2/cc/lexer+comment.test.testscript create mode 100644 build2/cc/lexer+line.test.testscript create mode 100644 build2/cc/lexer+number.test.testscript create mode 100644 build2/cc/lexer+preprocessor.test.testscript create mode 100644 build2/cc/lexer+raw-string-literal.test.testscript create mode 100644 build2/cc/lexer+string-literal.test.testscript create mode 100644 build2/cc/lexer.test.cxx create mode 100644 build2/cc/parser+module.test.testscript create mode 100644 build2/cc/parser.test.cxx create mode 100644 build2/function+call.test.testscript create mode 100644 build2/function+syntax.test.testscript create mode 100644 build2/function.test.cxx create mode 100644 build2/lexer+buildspec.test.testscript create mode 100644 build2/lexer+comment.test.testscript create mode 100644 build2/lexer+eval.test.testscript create mode 100644 build2/lexer+quoting.test.testscript create mode 100644 build2/lexer.test.cxx create mode 100644 build2/name.test.cxx create mode 100644 build2/scheduler.test.cxx create mode 100644 build2/test/script/lexer+command-expansion.test.testscript create mode 100644 build2/test/script/lexer+command-line.test.testscript create mode 100644 build2/test/script/lexer+description-line.test.testscript create mode 100644 build2/test/script/lexer+first-token.test.testscript create mode 100644 build2/test/script/lexer+second-token.test.testscript create mode 100644 build2/test/script/lexer+variable-line.test.testscript create mode 100644 build2/test/script/lexer+variable.test.testscript create mode 100644 build2/test/script/lexer.test.cxx create mode 100644 build2/test/script/parser+cleanup.test.testscript create mode 100644 build2/test/script/parser+command-if.test.testscript create mode 100644 build2/test/script/parser+command-re-parse.test.testscript create mode 100644 build2/test/script/parser+description.test.testscript create mode 100644 build2/test/script/parser+directive.test.testscript create mode 100644 build2/test/script/parser+exit.test.testscript create mode 100644 build2/test/script/parser+expansion.test.testscript create mode 100644 build2/test/script/parser+here-document.test.testscript create mode 100644 build2/test/script/parser+here-string.test.testscript create mode 100644 build2/test/script/parser+include.test.testscript create mode 100644 build2/test/script/parser+pipe-expr.test.testscript create mode 100644 build2/test/script/parser+pre-parse.test.testscript create mode 100644 build2/test/script/parser+redirect.test.testscript create mode 100644 build2/test/script/parser+regex.test.testscript create mode 100644 build2/test/script/parser+scope-if.test.testscript create mode 100644 build2/test/script/parser+scope.test.testscript create mode 100644 build2/test/script/parser+setup-teardown.test.testscript create mode 100644 build2/test/script/parser.test.cxx create mode 100644 build2/test/script/regex.test.cxx delete mode 100644 unit-tests/.gitignore delete mode 100644 unit-tests/cc/lexer/buildfile delete mode 100644 unit-tests/cc/lexer/char-literal.testscript delete mode 100644 unit-tests/cc/lexer/comment.testscript delete mode 100644 unit-tests/cc/lexer/driver.cxx delete mode 100644 unit-tests/cc/lexer/line.testscript delete mode 100644 unit-tests/cc/lexer/number.testscript delete mode 100644 unit-tests/cc/lexer/preprocessor.testscript delete mode 100644 unit-tests/cc/lexer/raw-string-literal.testscript delete mode 100644 unit-tests/cc/lexer/string-literal.testscript delete mode 100644 unit-tests/cc/parser/buildfile delete mode 100644 unit-tests/cc/parser/driver.cxx delete mode 100644 unit-tests/cc/parser/module.testscript delete mode 100644 unit-tests/function/buildfile delete mode 100644 unit-tests/function/call.testscript delete mode 100644 unit-tests/function/driver.cxx delete mode 100644 unit-tests/function/syntax.testscript delete mode 100644 unit-tests/lexer/buildfile delete mode 100644 unit-tests/lexer/buildspec.testscript delete mode 100644 unit-tests/lexer/comment.testscript delete mode 100644 unit-tests/lexer/driver.cxx delete mode 100644 unit-tests/lexer/eval.testscript delete mode 100644 unit-tests/lexer/quoting.testscript delete mode 100644 unit-tests/name/buildfile delete mode 100644 unit-tests/name/driver.cxx delete mode 100644 unit-tests/scheduler/buildfile delete mode 100644 unit-tests/scheduler/driver.cxx delete mode 100644 unit-tests/test/script/lexer/buildfile delete mode 100644 unit-tests/test/script/lexer/command-expansion.testscript delete mode 100644 unit-tests/test/script/lexer/command-line.testscript delete mode 100644 unit-tests/test/script/lexer/description-line.testscript delete mode 100644 unit-tests/test/script/lexer/driver.cxx delete mode 100644 unit-tests/test/script/lexer/first-token.testscript delete mode 100644 unit-tests/test/script/lexer/second-token.testscript delete mode 100644 unit-tests/test/script/lexer/variable-line.testscript delete mode 100644 unit-tests/test/script/lexer/variable.testscript delete mode 100644 unit-tests/test/script/parser/buildfile delete mode 100644 unit-tests/test/script/parser/cleanup.testscript delete mode 100644 unit-tests/test/script/parser/command-if.testscript delete mode 100644 unit-tests/test/script/parser/command-re-parse.testscript delete mode 100644 unit-tests/test/script/parser/description.testscript delete mode 100644 unit-tests/test/script/parser/directive.testscript delete mode 100644 unit-tests/test/script/parser/driver.cxx delete mode 100644 unit-tests/test/script/parser/exit.testscript delete mode 100644 unit-tests/test/script/parser/expansion.testscript delete mode 100644 unit-tests/test/script/parser/here-document.testscript delete mode 100644 unit-tests/test/script/parser/here-string.testscript delete mode 100644 unit-tests/test/script/parser/include.testscript delete mode 100644 unit-tests/test/script/parser/pipe-expr.testscript delete mode 100644 unit-tests/test/script/parser/pre-parse.testscript delete mode 100644 unit-tests/test/script/parser/redirect.testscript delete mode 100644 unit-tests/test/script/parser/regex.testscript delete mode 100644 unit-tests/test/script/parser/scope-if.testscript delete mode 100644 unit-tests/test/script/parser/scope.testscript delete mode 100644 unit-tests/test/script/parser/setup-teardown.testscript delete mode 100644 unit-tests/test/script/regex/buildfile delete mode 100644 unit-tests/test/script/regex/driver.cxx diff --git a/build/root.build b/build/root.build index 6640407..03e3fe6 100644 --- a/build/root.build +++ b/build/root.build @@ -34,12 +34,6 @@ using c # using? cli -# All exe{} in unit-tests/ are, well, tests. Also don't link whole archives -# by default there. -# -unit-tests/exe{*}: test = true -unit-tests/libu{*}: bin.whole = false - # Specify the test target for cross-testing. # test.target = $cxx.target diff --git a/build2/.gitignore b/build2/.gitignore index 5ea3913..51b4c16 100644 --- a/build2/.gitignore +++ b/build2/.gitignore @@ -1,6 +1,11 @@ b b-boot +*.test #*-options #*-options.?xx config.hxx version.hxx + +# Testscript output directory (can be symlink). +# +test-*.test diff --git a/build2/buildfile b/build2/buildfile index bd730c3..64935f3 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -5,15 +5,33 @@ import libs = libbutl%lib{butl} import libs += libpkgconf%lib{pkgconf} -exe{b}: cxx{b} libue{b} +./: exe{b}: cxx{b} libue{b} -libue{b}: {hxx ixx txx cxx}{** -b -b-options -config -version} \ - {hxx ixx cxx}{b-options} {hxx}{config version} \ +libue{b}: {hxx ixx txx cxx}{** -b -b-options -config -version -**.test...} \ + {hxx ixx cxx}{b-options} {hxx}{config version} \ $libs hxx{config}: in{config} hxx{version}: in{version} $src_root/manifest +# Unit tests. +# +exe{*.test}: +{ + test = true + install = false +} + +for t: cxx{**.test...} +{ + d = $directory($t) + n = $name($t)... + b = $path.base($name($t)) + + ./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n +$b+*.test...} + $d/exe{$n}: libue{b}: bin.whole = false +} + # Build options. # # Pass our compiler target to be used as build2 host. diff --git a/build2/cc/lexer+char-literal.test.testscript b/build2/cc/lexer+char-literal.test.testscript new file mode 100644 index 0000000..6a0a036 --- /dev/null +++ b/build2/cc/lexer+char-literal.test.testscript @@ -0,0 +1,67 @@ +# file : build2/cc/lexer+char-literal.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test character literals. +# + +: normal +: +$* <>EOO +'a' +'aa' +'"' +EOI + + + +EOO + +: prefix +: +$* <>EOO +L'a' +U'a' +u'a' +u8'a' +u8R'a' +EOI + + + + +'u8R' + +EOO + +: suffix +: +$* <>EOO +'a'x +'a'_X123 +EOI + + +EOO + +: escape +: +$* <>EOO +'\'' +'\\' +'\\\'' +'\n' +U'\U0001f34c' +EOI + + + + + +EOO + +: unterminated +: +$* <"'a" 2>>EOE != 0 +stdin:1:1: error: unterminated character literal +EOE diff --git a/build2/cc/lexer+comment.test.testscript b/build2/cc/lexer+comment.test.testscript new file mode 100644 index 0000000..493c295 --- /dev/null +++ b/build2/cc/lexer+comment.test.testscript @@ -0,0 +1,88 @@ +# file : build2/cc/lexer+comment.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test C and C++ comments. +# + +: c-comment +: +$* <"';'" +// /* +; +// */ +EOI + +: c-unterminated +: +$* <>EOE != 0 +/* +comment +EOI +stdin:1:2: error: unterminated comment +EOE + +: cxx-unterminated +: +$* <<:EOI +// comment +EOI + +: in-char-literal +: +$* <>EOO +'//' +'/*'*/ +EOI + + + + +EOO + +: in-string-literal +: +$* <>EOO +"//foo" +"/*"*/ +EOI + + + + +EOO + +: in-raw-string-literal +: +$* <>EOO +R"X( +// foo +/* bar +)X"*/ +EOI + + + +EOO diff --git a/build2/cc/lexer+line.test.testscript b/build2/cc/lexer+line.test.testscript new file mode 100644 index 0000000..abcc587 --- /dev/null +++ b/build2/cc/lexer+line.test.testscript @@ -0,0 +1,67 @@ +# file : build2/cc/lexer+line.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test line continuations. +# + +: identifier +: +$* <"'foo123'" +fo\ +o\ +1\ +2\ +3 +EOI + +: punctuation +: +$* <'' +.\ +.\ +. +EOI + +: c-comment +: +$* <>EOO +\abc +EOI + +'abc' +EOO + +: multiple +: +$* <>EOO +\\ +EOI + +EOO + +: unterminated +: +$* <<:EOI >'' +\ +EOI diff --git a/build2/cc/lexer+number.test.testscript b/build2/cc/lexer+number.test.testscript new file mode 100644 index 0000000..c342818 --- /dev/null +++ b/build2/cc/lexer+number.test.testscript @@ -0,0 +1,48 @@ +# file : build2/cc/lexer+number.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test numbers. +# + +$* <'1' >'' +$* <'.1' >'' +$* <'1.' >'' + +$* <'0b101' >'' +$* <'0123' >'' +$* <'0X12AB' >'' + +$* <'1e10' >'' +$* <'1E+10' >'' +$* <'0x1.p10' >'' +$* <'0x1.P-10' >'' + +$* <"123'456" >'' +$* <"0xff00'00ff" >'' + +$* <'123f' >'' +$* <'123UL' >'' +$* <'123_X' >'' + +: separate-punctuation +: +$* <'123;' >>EOO + +';' +EOO + +: separate-plus-minus +: +$* <'1.0_a+2.0' >>EOO + + + +EOO + +: separate-whitespace +: +$* <'123 abc' >>EOO + +'abc' +EOO diff --git a/build2/cc/lexer+preprocessor.test.testscript b/build2/cc/lexer+preprocessor.test.testscript new file mode 100644 index 0000000..fc061cb --- /dev/null +++ b/build2/cc/lexer+preprocessor.test.testscript @@ -0,0 +1,73 @@ +# file : build2/cc/lexer+preprocessor.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test preprocessor lines. +# + +: normal +: +$* <>EOO +; +# 1 "test.cxx" 2 +; + ; +# 4 +; +#line 8 "z:\\tmp\\test.hxx" +; +#line 10 +; +# 5 "test.cxx" +; +EOI +';' stdin:1:1 +';' test.cxx:1:1 +';' test.cxx:2:3 +';' test.cxx:4:1 +';' z:\tmp\test.hxx:8:1 +';' z:\tmp\test.hxx:10:1 +';' test.cxx:5:1 +EOO + +: include +: +$* <>EOE != 0 +#include +EOI +stdin:1:1: error: unexpected #include directive +EOE + +: nested +: +$* <>EOO +#define FOO(x) #y +; +EOI +';' +EOO diff --git a/build2/cc/lexer+raw-string-literal.test.testscript b/build2/cc/lexer+raw-string-literal.test.testscript new file mode 100644 index 0000000..e72d77b --- /dev/null +++ b/build2/cc/lexer+raw-string-literal.test.testscript @@ -0,0 +1,90 @@ +# file : build2/cc/lexer+raw-string-literal.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test raw string literals. +# + +: normal +: +$* <>EOO +R"()" +R"(ab)" +R"(a"b)" +R"(a)b)" +R"%(a%)b)%" +R"X(a + b)X" +R"X(a\ + b)X" +EOI + + + + + + + +EOO + +: prefix +: +$* <>EOO +LR"(ab)" +UR"(ab)" +uR"(ab)" +u8R"(ab)" +EOI + + + + +EOO + +: suffix +: +$* <>EOO +R"(ab)"x +R"(ab)"_X123 +EOI + + +EOO + +: escape +: +$* <>EOO +R"(\)" +EOI + +EOO + +: invalid-no-paren +: +$* <'R"a"' 2>>EOE != 0 +stdin:1:2: error: invalid raw string literal +EOE + +: invalid-paren +: +$* <'R")()("' 2>>EOE != 0 +stdin:1:2: error: invalid raw string literal +EOE + +: invalid-unterminated-paren +: +$* <'R"(abc"' 2>>EOE != 0 +stdin:1:2: error: invalid raw string literal +EOE + +: invalid-unterminated-delimiter +: +$* <'R"X(abc)"' 2>>EOE != 0 +stdin:1:2: error: invalid raw string literal +EOE + +: invalid-unterminated-quote +: +$* <'R"X(abc)X' 2>>EOE != 0 +stdin:1:2: error: invalid raw string literal +EOE diff --git a/build2/cc/lexer+string-literal.test.testscript b/build2/cc/lexer+string-literal.test.testscript new file mode 100644 index 0000000..c486aa1 --- /dev/null +++ b/build2/cc/lexer+string-literal.test.testscript @@ -0,0 +1,65 @@ +# file : build2/cc/lexer+string-literal.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test string literals (except raw). +# + +: normal +: +$* <>EOO +"aa" +"'" +"a""b" +EOI + + + + +EOO + +: prefix +: +$* <>EOO +L"ab" +U"ab" +u"ab" +u8"ab" +EOI + + + + +EOO + +: suffix +: +$* <>EOO +"ab"x +"ab"_X123 +EOI + + +EOO + +: escape +: +$* <>EOO +"\"\"" +"\\\\" +"\\\"\\" +"\n\t" +U"a\U0001f34c" +EOI + + + + + +EOO + +: unterminated +: +$* <'"ab' 2>>EOE != 0 +stdin:1:1: error: unterminated string literal +EOE diff --git a/build2/cc/lexer.test.cxx b/build2/cc/lexer.test.cxx new file mode 100644 index 0000000..a2e33b7 --- /dev/null +++ b/build2/cc/lexer.test.cxx @@ -0,0 +1,80 @@ +// file : build2/cc/lexer.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include + +using namespace std; +using namespace butl; + +namespace build2 +{ + namespace cc + { + // Usage: argv[0] [-l] [] + // + int + main (int argc, char* argv[]) + { + bool loc (false); + const char* file (nullptr); + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-l") + loc = true; + else + { + file = argv[i]; + break; + } + } + + try + { + ifdstream is; + if (file != nullptr) + is.open (file); + else + { + file = "stdin"; + is.open (fddup (stdin_fd ())); + } + + lexer l (is, path (file)); + + // No use printing eos since we will either get it or loop forever. + // + for (token t; l.next (t) != token_type::eos; ) + { + cout << t; + + if (loc) + cout << ' ' << t.file << ':' << t.line << ':' << t.column; + + cout << endl; + } + } + catch (const failed&) + { + return 1; + } + + return 0; + } + } +} + +int +main (int argc, char* argv[]) +{ + return build2::cc::main (argc, argv); +} diff --git a/build2/cc/parser+module.test.testscript b/build2/cc/parser+module.test.testscript new file mode 100644 index 0000000..0e2e52e --- /dev/null +++ b/build2/cc/parser+module.test.testscript @@ -0,0 +1,149 @@ +# file : build2/cc/parser+module.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test C++ module constructs. +# + +: import +: +$* <>EOI +import foo; +import foo.bar; +import foo.bar.baz; +EOI + +: module-implementation +: +$* <>EOI +module foo; +EOI + +: module-interface +: +$* <>EOI +export module foo; +EOI + +: export-imported +: +$* <>EOO +export import foo; +EOI +export import foo; +EOO + +: export-imported-block +: +$* <>EOO +import bar; + +export {import foo;} + +export +{ + namespace foo + { + class c {}; + } + + template int f (); + + import bar; +} +EOI +export import bar; +export import foo; +EOO + +: non-module +: +$* <>EOO +import foo [[export({import})]]; +module bar [[module({module})]]; +EOI +import foo; +module bar; +EOO + +: import-duplicate +: +$* <>EOO +import foo; +import bar.baz; +import foo; +import bar . baz; +EOI +import foo; +import bar.baz; +EOO + +: brace-missing +: +$* <>EOE != 0 +export +{ + class foo + { + //}; + module foo; +} +EOI +stdin:8:1: error: {}-imbalance detected +EOE + +: brace-stray +: +$* <>EOE != 0 +export +{ + class foo + { + };} +} +module foo; +EOI +stdin:6:1: error: {}-imbalance detected +EOE + +: import-missing-name +: +$* <>EOE != 0 +import ; +EOI +stdin:1:8: error: module name expected instead of ';' +EOE + +: module-missing-name +: +$* <>EOE != 0 +module ; +EOI +stdin:1:1: error: module declaration expected after leading module marker +EOE + +: import-missing-semi +: +$* <>EOE != 0 +import foo +EOI +stdin:2:1: error: ';' expected instead of +EOE + +: module-missing-semi +: +$* <>EOE != 0 +export module foo +EOI +stdin:2:1: error: ';' expected instead of +EOE diff --git a/build2/cc/parser.test.cxx b/build2/cc/parser.test.cxx new file mode 100644 index 0000000..ab42e31 --- /dev/null +++ b/build2/cc/parser.test.cxx @@ -0,0 +1,66 @@ +// file : build2/cc/parser.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include + +using namespace std; +using namespace butl; + +namespace build2 +{ + namespace cc + { + // Usage: argv[0] [] + // + int + main (int argc, char* argv[]) + { + try + { + const char* file; + + ifdstream is; + if (argc > 1) + { + file = argv[1]; + is.open (file); + } + else + { + file = "stdin"; + is.open (fddup (stdin_fd ())); + } + + parser p; + translation_unit u (p.parse (is, path (file))); + + for (const module_import& m: u.mod.imports) + cout << (m.exported ? "export " : "") + << "import " << m.name << ';' << endl; + + if (!u.mod.name.empty ()) + cout << (u.mod.iface ? "export " : "") + << "module " << u.mod.name << ';' << endl; + } + catch (const failed&) + { + return 1; + } + + return 0; + } + } +} + +int +main (int argc, char* argv[]) +{ + return build2::cc::main (argc, argv); +} diff --git a/build2/function+call.test.testscript b/build2/function+call.test.testscript new file mode 100644 index 0000000..1678c28 --- /dev/null +++ b/build2/function+call.test.testscript @@ -0,0 +1,161 @@ +# file : build2/function+call.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: qual-implicit +: +$* <'print $dummy.dummy0()' >'abc' + +: qual-explicit +: +$* <'print $dummy.qual()' >'abc' + +: qual-fail +: +$* <'print $qual()' 2>>EOE != 0 +buildfile:1:8: error: unmatched call to qual() + info: candidate: dummy.qual() +EOE + +: derived-base +: Test derived-to-base overload resolution +: +$* <'print $dummy.abs([dir_path] .)' >'false'; +$* <'print $dummy.abs([abs_dir_path] .)' >'true' + +: variadic +: +$* <'print $variadic([bool] true, foo, bar)' >'3' + +: fail +: +$* <'$fail()' 2>>EOE != 0 +error: failed +buildfile:1:2: info: while calling fail() +EOE + +: fail-invalid-arg +: +$* <'$fail_arg(abc)' 2>>EOE != 0 +error: invalid argument: invalid uint64 value: 'abc' +buildfile:1:2: info: while calling fail_arg() +EOE + +: no-match-name +: +$* <'$bogus()' 2>>EOE != 0 +buildfile:1:2: error: unmatched call to bogus() +EOE + +: no-match-count +: +$* <'$dummy0(abc)' 2>>EOE != 0 +buildfile:1:2: error: unmatched call to dummy0() + info: candidate: dummy0(), qualified name dummy.dummy0 +EOE + +: no-match-type +: +$* <'$dummy1([uint64] 123)' 2>>EOE != 0 +buildfile:1:2: error: unmatched call to dummy1(uint64) + info: candidate: dummy1(string), qualified name dummy.dummy1 +EOE + +: ambig +: +$* <'$ambig(abc)' 2>>~/EOE/ != 0 +buildfile:1:2: error: ambiguous call to ambig() +/(( + info: candidate: ambig( [, uint64]), qualified name dummy.ambig + info: candidate: ambig( [, string]), qualified name dummy.ambig +/)|( + info: candidate: ambig( [, string]), qualified name dummy.ambig + info: candidate: ambig( [, uint64]), qualified name dummy.ambig +/)) +EOE + +: unmatched +: +$* <'$ambig(abc, def)' 2>>~/EOE/ != 0 +buildfile:1:2: error: unmatched call to ambig(, ) +/(( + info: candidate: ambig( [, uint64]), qualified name dummy.ambig + info: candidate: ambig( [, string]), qualified name dummy.ambig +/)|( + info: candidate: ambig( [, string]), qualified name dummy.ambig + info: candidate: ambig( [, uint64]), qualified name dummy.ambig +/)) +EOE + +: reverse +: +$* <'print $reverse([string] abc)' >'abc' + +: optional-absent +: +$* <'print $optional()' >'true' + +: optional-present +: +$* <'print $optional(abc)' >'false' + +: null-true +: +$* <'print $nullable([null])' >'true' + +: null-false +: +$* <'print $nullable(nonull)' >'false' + +: null-fail +: +$* <'$dummy1([string null])' 2>>EOE != 0 +error: invalid argument: null value +buildfile:1:2: info: while calling dummy1(string) +EOE + +: print-call-1-untyped +: +$* <'$bogus(abc)' 2>>EOE != 0 +buildfile:1:2: error: unmatched call to bogus() +EOE + +: print-call-1-typed +: +$* <'$bogus([uint64] 123)' 2>>EOE != 0 +buildfile:1:2: error: unmatched call to bogus(uint64) +EOE + +: print-call-2 +: +$* <'$bogus(abc, [uint64] 123)' 2>>EOE != 0 +buildfile:1:2: error: unmatched call to bogus(, uint64) +EOE + +: print-fovl +: +$* <'$ambig([bool] true)' 2>>~/EOE/ != 0 +buildfile:1:2: error: ambiguous call to ambig(bool) +/(( + info: candidate: ambig( [, uint64]), qualified name dummy.ambig + info: candidate: ambig( [, string]), qualified name dummy.ambig +/)|( + info: candidate: ambig( [, string]), qualified name dummy.ambig + info: candidate: ambig( [, uint64]), qualified name dummy.ambig +/)) +EOE + +: print-fovl-variadic +: +$* <'$variadic(abc)' 2>>EOE != 0 +buildfile:1:2: error: unmatched call to variadic() + info: candidate: variadic(bool [, ...]) +EOE + +: member-function +: +$* <'print $dummy.length([path] abc)' >'3' + +: data-member +: +$* <'print $dummy.type([name] cxx{foo})' >'cxx' diff --git a/build2/function+syntax.test.testscript b/build2/function+syntax.test.testscript new file mode 100644 index 0000000..bd86dd0 --- /dev/null +++ b/build2/function+syntax.test.testscript @@ -0,0 +1,29 @@ +# file : build2/function+syntax.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +$* <'$dump()' >:'' : none +$* <'$dump( )' >:'' : none-in-spaces +$* <'$dump("")' >'{}' : one-empty +$* <'$dump(a)' >'a' : one-single +$* <'$dump(a b c)' >'a b c' : one-list +$* <'$dump(d/t{x y z})' >'d/t{x} d/t{y} d/t{z}' : one-names + +$* <'print a$dummy1([string] b)c' >'abc' : concat +$* <'print $dummy2([uint64] 123, [uint64] 321)' >'444' : multi-arg + +: quoting +: Verify we can inhibit function call with quoting +: +$* <>EOO +foo = FOO +bar = BAR + +print $foo"($bar)" +print "$foo"($bar) +print "$foo""($bar)" +EOI +FOOBAR +FOOBAR +FOOBAR +EOO diff --git a/build2/function.test.cxx b/build2/function.test.cxx new file mode 100644 index 0000000..a9ba7bb --- /dev/null +++ b/build2/function.test.cxx @@ -0,0 +1,131 @@ +// file : build2/function.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; + +namespace build2 +{ + static const optional arg_bool[1] = + { + &value_traits::value_type + }; + + static dir_path + scoped (const scope*, dir_path d) + { + return d; + } + + static void + scoped_void (const scope*, dir_path) + { + } + + int + main (int, char* argv[]) + { + init (argv[0], 1); // Fake build system driver, default verbosity. + reset (strings ()); // No command line variables. + + function_family f ("dummy"); + + f["fail"] = []() {fail << "failed" << endf;}; + f["fail_arg"] = [](names a) {return convert (move (a[0]));}; + + f["nullable"] = [](names* a) {return a == nullptr;}; + f["optional"] = [](optional a) {return !a;}; + + f["dummy0"] = []() {return "abc";}; + f["dummy1"] = [](string s) {return s;}; + f["dummy2"] = [](uint64_t x, uint64_t y) {return x + y;}; + + f["ambig"] = [](names a, optional) {return a;}; + f["ambig"] = [](names a, optional) {return a;}; + + f["reverse"] = [](names a) {return a;}; + + f["scoped"] = [](const scope*, names a) {return a;}; + f["scoped_void"] = [](const scope*, names) {}; + f["scoped"] = &scoped; + f["scoped_void"] = &scoped_void; + + f[".qual"] = []() {return "abc";}; + + f[".length"] = &path::size; // Member function. + f[".type"] = &name::type; // Data member. + + f[".abs"] = [](dir_path d) {return d.absolute ();}; + + // Variadic function with first required argument of type bool. Returns + // number of arguments passed. + // + functions.insert ( + "variadic", + function_overload ( + nullptr, + 1, + function_overload::arg_variadic, + function_overload::types (arg_bool, 1), + [] (const scope*, vector_view args, const function_overload&) + { + return value (static_cast (args.size ())); + })); + + // Dump arguments. + // + functions.insert ( + "dump", + function_overload ( + nullptr, + 0, + function_overload::arg_variadic, + function_overload::types (), + [] (const scope*, vector_view args, const function_overload&) + { + for (value& a: args) + { + if (a.null) + cout << "[null]"; + else if (!a.empty ()) + { + names storage; + cout << reverse (a, storage); + } + cout << endl; + } + return value (nullptr); + })); + + try + { + scope& s (*scope::global_); + + parser p; + p.parse_buildfile (cin, path ("buildfile"), s, s); + } + catch (const failed&) + { + return 1; + } + + return 0; + } +} + +int +main (int argc, char* argv[]) +{ + return build2::main (argc, argv); +} diff --git a/build2/lexer+buildspec.test.testscript b/build2/lexer+buildspec.test.testscript new file mode 100644 index 0000000..9083abe --- /dev/null +++ b/build2/lexer+buildspec.test.testscript @@ -0,0 +1,16 @@ +# file : build2/lexer+buildspec.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.arguments = buildspec + +: punctuation +: +$* <:'x,x(x)' >>EOO +'x' +, +'x' + ( +'x' +) +EOO diff --git a/build2/lexer+comment.test.testscript b/build2/lexer+comment.test.testscript new file mode 100644 index 0000000..4323c84 --- /dev/null +++ b/build2/lexer+comment.test.testscript @@ -0,0 +1,139 @@ +# file : build2/lexer+comment.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: single-line +: +{ + : only + : + $* <>:EOO + # comment + EOI + EOO + + : first + : + $* <>EOO + # comment + foo + EOI + 'foo' + + EOO + + : last + : + $* <>EOO + foo + # comment + EOI + 'foo' + + EOO + + : few + : + $* <>EOO + foo + # comment + # comment + EOI + 'foo' + + EOO + + : cont + : + $* <>EOO + foo + # comment\\ + bar + EOI + 'foo' + + 'bar' + + EOO + + : same + : + $* <>EOO + foo # comment + bar # comment + EOI + 'foo' + + 'bar' + + EOO +} + +: multi-line +: +{ + : only + : + $* <>:EOO + #\ + comment + comment + #\ + EOI + EOO + + : empty + : + $* <>:EOO + #\ + #\ + EOI + EOO + + : start-same + : + $* <>EOO + foo #\ + comment + comment + #\ + EOI + 'foo' + + EOO + + : end-same + : + $* <>EOO + #\ + comment + comment + foo #\ + bar + EOI + 'bar' + + EOO + + : end-not + : + $* <>EOO + #\ + comment + #\ not an end + foo #\ + bar + EOI + 'bar' + + EOO + + : unterm + : + $* <>EOE != 0 + #\ + comment + EOI + stdin:3:1: error: unterminated multi-line comment + EOE +} diff --git a/build2/lexer+eval.test.testscript b/build2/lexer+eval.test.testscript new file mode 100644 index 0000000..eccd029 --- /dev/null +++ b/build2/lexer+eval.test.testscript @@ -0,0 +1,76 @@ +# file : build2/lexer+eval.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.arguments = eval + +: punctuation +: +$* <:'x:x{x}x[x]x$x?x,x(x)' >>EOO +'x' +: +'x' +{ +'x' +} +'x' +[ +'x' +] +'x' +$ +'x' +? +'x' +, +'x' +( +'x' +) +EOO + +: logical +: +$* <:'x|x||x&x&&x!x!!x)' >>EOO +'x|x' +|| +'x&x' +&& +'x' +! +'x' +! +! +'x' +) +EOO + +: comparison +: +$* <:'x=x==x!=xx>=)' >>EOO +'x=x' +== +'x' +!= +'x' +< +'x' +<= +'x' +> +'x' +>= +) +EOO + +: newline +: +$* <'x' >- 2>>EOE != 0 +stdin:1:2: error: newline in evaluation context +EOE + +: eof +: +$* <:'' 2>>EOE != 0 +stdin:1:1: error: unterminated evaluation context +EOE diff --git a/build2/lexer+quoting.test.testscript b/build2/lexer+quoting.test.testscript new file mode 100644 index 0000000..21b9046 --- /dev/null +++ b/build2/lexer+quoting.test.testscript @@ -0,0 +1,108 @@ +# file : build2/lexer+quoting.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.options += -q + +: unquoted +: +$* <'foo' >>EOO +'foo' + +EOO + +: comp +: +{ + : single + : + $* <":'foo':" >>EOO + : + 'foo' [S/C] + : + + EOO + + : double + : + $* <':"foo":' >>EOO + : + 'foo' [D/C] + : + + EOO + + : single-empty + : + $* <"''" >>EOO + '' [S/C] + + EOO + + : double-empty + : + $* <'""' >>EOO + '' [D/C] + + EOO +} + +: part +{ + : quoted + { + : start + : Token start already quoted + : + $* <'"$foo"' >>EOO + '' [D/P] + $ [D/C] + 'foo' [D/P] + + EOO + + : end + : Token end still quoted + : + $* <'"foo$"' >>EOO + 'foo' [D/P] + $ [D/C] + '' [D/P] + + EOO + } + + : unquoted + { + : start + : Token starts with unquoted character + : + $* <'f"oo"' >>EOO + 'foo' [D/P] + + EOO + + : end + : Token continous with unquoted character + : + $* <'"fo"o' >>EOO + 'foo' [D/P] + + EOO + + : escape + : Token continous with unquoted escaped character + : + $* <'"fo"\"' >>EOO + 'fo"' [D/P] + + EOO + } +} + +: mixed +: +$* <"\"fo\"'o'" >>EOO +'foo' [M/P] + +EOO diff --git a/build2/lexer.test.cxx b/build2/lexer.test.cxx new file mode 100644 index 0000000..8abd5f7 --- /dev/null +++ b/build2/lexer.test.cxx @@ -0,0 +1,98 @@ +// file : build2/lexer.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include +#include + +using namespace std; + +namespace build2 +{ + // Usage: argv[0] [-q] [] + // + int + main (int argc, char* argv[]) + { + bool quote (false); + lexer_mode m (lexer_mode::normal); + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-q") + quote = true; + else + { + if (a == "normal") m = lexer_mode::normal; + else if (a == "variable") m = lexer_mode::variable; + else if (a == "value") m = lexer_mode::value; + else if (a == "attribute") m = lexer_mode::attribute; + else if (a == "eval") m = lexer_mode::eval; + else if (a == "buildspec") m = lexer_mode::buildspec; + else assert (false); + break; + } + } + + try + { + cin.exceptions (istream::failbit | istream::badbit); + + // Most alternative modes auto-expire so we need something underneath. + // + lexer l (cin, path ("stdin")); + + if (m != lexer_mode::normal) + l.mode (m); + + // No use printing eos since we will either get it or loop forever. + // + for (token t (l.next ()); t.type != token_type::eos; t = l.next ()) + { + if (t.separated && t.type != token_type::newline) + cout << ' '; + + // Print each token on a separate line without quoting operators. + // + t.printer (cout, t, false); + + if (quote) + { + char q ('\0'); + switch (t.qtype) + { + case quote_type::single: q = 'S'; break; + case quote_type::double_: q = 'D'; break; + case quote_type::mixed: q = 'M'; break; + case quote_type::unquoted: break; + } + + if (q != '\0') + cout << " [" << q << (t.qcomp ? "/C" : "/P") << ']'; + } + + cout << endl; + } + } + catch (const failed&) + { + return 1; + } + + return 0; + } +} + +int +main (int argc, char* argv[]) +{ + return build2::main (argc, argv); +} diff --git a/build2/name.test.cxx b/build2/name.test.cxx new file mode 100644 index 0000000..0434aac --- /dev/null +++ b/build2/name.test.cxx @@ -0,0 +1,96 @@ +// file : build2/name.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include + +#include // Includes name. +#include + +#include + +using namespace std; + +namespace build2 +{ + int + main (int, char*[]) + { + using dir = dir_path; + + // Test string representation. + // + { + auto ts = [] (const name& n) {return to_string (n);}; + + assert (ts (name ()) == ""); + + assert (ts (name ("foo")) == "foo"); + + assert (ts (name (dir ("bar/"))) == "bar/"); + assert (ts (name (dir ("bar/baz/"))) == "bar/baz/"); + + assert (ts (name (dir ("bar/"), "dir", "")) == "dir{bar/}"); + assert (ts (name (dir ("bar/baz/"), "dir", "")) == "bar/dir{baz/}"); + + assert (ts (name (dir ("bar/"), "foo")) == "bar/foo"); + + assert (ts (name (dir ("bar/"), "dir", "foo")) == "bar/dir{foo}"); + assert (ts (name (dir ("bar/baz/"), "dir", "foo")) == "bar/baz/dir{foo}"); + } + + // Test stream representation. + // + { + auto ts = [] (const name& n, bool quote = true) + { + ostringstream os; + stream_verb (os, stream_verbosity (0, 1)); + to_stream (os, n, quote); + return os.str (); + }; + + assert (ts (name ()) == "''"); + assert (ts (name (), false) == "{}"); + + assert (ts (name ("foo")) == "foo"); + + assert (ts (name (dir ("bar/"))) == "bar/"); + assert (ts (name (dir ("bar/baz/"))) == "bar/baz/"); + + assert (ts (name (dir ("bar/"), "dir", "")) == "dir{bar/}"); + assert (ts (name (dir ("bar/baz/"), "dir", "")) == "bar/dir{baz/}"); + + assert (ts (name (dir ("bar/"), "foo")) == "bar/foo"); + + assert (ts (name (dir ("bar/"), "dir", "foo")) == "bar/dir{foo}"); + assert (ts (name (dir ("bar/baz/"), "dir", "foo")) == "bar/baz/dir{foo}"); + + // Quoting. + // + assert (ts (name (dir ("bar baz/"), "dir", "foo fox")) == "'bar baz/'dir{'foo fox'}"); + + // Relative logic. + // +#ifndef _WIN32 + dir rb ("/bar/"); + relative_base = &rb; + + assert (ts (name (dir ("/bar/"), "dir", "")) == "dir{./}"); + assert (ts (name (dir ("/bar/"), "", "foo")) == "foo"); + assert (ts (name (dir ("/bar/baz/"), "dir", "")) == "dir{baz/}"); +#endif + } + + return 0; + } +} + +int +main (int argc, char* argv[]) +{ + return build2::main (argc, argv); +} diff --git a/build2/scheduler.test.cxx b/build2/scheduler.test.cxx new file mode 100644 index 0000000..b088c1d --- /dev/null +++ b/build2/scheduler.test.cxx @@ -0,0 +1,187 @@ +// file : build2/scheduler.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include +#include + +#include + +using namespace std; + +namespace build2 +{ + // Usage argv[0] [-v ] [-d ] [-c ] + // [-q ] + // + // -v task tree volume (affects both depth and width), for example 100 + // -d computational difficulty of each task, for example 10 + // -c max active threads, if unspecified or 0, then hardware concurrency + // -q task queue depth, if unspecified or 0, then appropriate default used + // + // Specifying any option also turns on the verbose mode. + // + // Notes on testing: + // + // 1. Ideally you would want to test things on an SMP machine. + // + // 2. When need to compare performance, disable turbo boost since its + // availability depends on CPU utilization/temperature: + // + // # echo '1' >/sys/devices/system/cpu/intel_pstate/no_turbo + // + // 3. Use turbostat(1) to see per-CPU details (utlization, frequency): + // + // $ sudo turbostat --interval 1 ./driver -d 8 -v 300 + // + static bool + prime (uint64_t); + + // Find # of primes in the [x, y) range. + // + static void + inner (uint64_t x, uint64_t y, uint64_t& r) + { + for (; x != y; ++x) + if (prime (x)) + r++; + }; + + int + main (int argc, char* argv[]) + { + bool verb (false); + + // Adjust assert() below if changing these defaults. + // + size_t volume (100); + uint32_t difficulty (10); + + size_t max_active (0); + size_t queue_depth (0); + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-v") + volume = stoul (argv[++i]); + else if (a == "-d") + difficulty = stoul (argv[++i]); + else if (a == "-c") + max_active = stoul (argv[++i]); + else if (a == "-q") + queue_depth = stoul (argv[++i]); + else + assert (false); + + verb = true; + } + + if (max_active == 0) + max_active = scheduler::hardware_concurrency (); + + scheduler s (max_active, 1, 0, queue_depth); + + // Find # prime counts of primes in [i, d*i*i) ranges for i in (0, n]. + // + auto outer = [difficulty, &s] (size_t n, vector& o, uint64_t& r) + { + scheduler::atomic_count task_count (0); + + for (size_t i (1); i <= n; ++i) + { + o[i - 1] = 0; + s.async (task_count, + inner, + i, + i * i * difficulty, + ref (o[i - 1])); + } + + s.wait (task_count); + assert (task_count == 0); + + for (uint64_t v: o) + r += prime (v) ? 1 : 0; + }; + + vector r (volume, 0); + vector> o (volume, vector ()); + + scheduler::atomic_count task_count (0); + + for (size_t i (0); i != volume; ++i) + { + o[i].resize (i); + s.async (task_count, + outer, + i, + ref (o[i]), + ref (r[i])); + } + + s.wait (task_count); + assert (task_count == 0); + + uint64_t n (0); + for (uint64_t v: r) + n += v; + + if (volume == 100 && difficulty == 10) + assert (n == 580); + + scheduler::stat st (s.shutdown ()); + + if (verb) + { + cerr << "result " << n << endl + << endl; + + cerr << "thread_max_active " << st.thread_max_active << endl + << "thread_max_total " << st.thread_max_total << endl + << "thread_helpers " << st.thread_helpers << endl + << "thread_max_waiting " << st.thread_max_waiting << endl + << endl + << "task_queue_depth " << st.task_queue_depth << endl + << "task_queue_full " << st.task_queue_full << endl + << endl + << "wait_queue_slots " << st.wait_queue_slots << endl + << "wait_queue_collisions " << st.wait_queue_collisions << endl; + } + + return 0; + } + + static bool + prime (uint64_t x) + { + if (x == 2 || x == 3) + return true; + + if (x < 2 || x % 2 == 0 || x % 3 == 0) + return false; + + // Test divisors starting from 5 and incrementing alternatively by 2/4. + // + for (uint64_t d (5), i (2); d * d <= x; d += i, i = 6 - i) + { + if (x % d == 0) + return false; + } + + return true; + } +} + +int +main (int argc, char* argv[]) +{ + return build2::main (argc, argv); +} diff --git a/build2/test/script/lexer+command-expansion.test.testscript b/build2/test/script/lexer+command-expansion.test.testscript new file mode 100644 index 0000000..03e3366 --- /dev/null +++ b/build2/test/script/lexer+command-expansion.test.testscript @@ -0,0 +1,248 @@ +# file : build2/test/script/lexer+command-expansion.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.arguments = command-expansion + +: pass-redirect +: +{ + : in + : + $* <:"0<|" >>EOO + '0' + <| + EOO + + : arg-in + : + $* <:"0 <|" >>EOO + '0 ' + <| + EOO + + : out + : + $* <:"1>|" >>EOO + '1' + >| + EOO + + : arg-out + : + $* <:"1 >|" >>EOO + '1 ' + >| + EOO +} + +: null-redirect +: +{ + : in + : + $* <:"0<-" >>EOO + '0' + <- + EOO + + : arg-in + : + $* <:"0 <-" >>EOO + '0 ' + <- + EOO + + : out + : + $* <:"1>-" >>EOO + '1' + >- + EOO + + : arg-out + : + $* <:"1 >-" >>EOO + '1 ' + >- + EOO +} + +: trace-redirect +: +{ + : out + : + $* <:"1>!" >>EOO + '1' + >! + EOO + + : arg-out + : + $* <:"1 >!" >>EOO + '1 ' + >! + EOO +} + +: merge-redirect +: +{ + : out + : + $* <:"1>&2" >>EOO + '1' + >& + '2' + EOO + + : arg-out + : + $* <:"1 >&2" >>EOO + '1 ' + >& + '2' + EOO +} + +: str-redirect +: +{ + : in + : + { + : newline + : + $* <:"0>EOO + '0' + < + 'a b' + EOO + + : no-newline + : + $* <:"0<:a b" >>EOO + '0' + <: + 'a b' + EOO + } + + : out + : + { + : newline + : + $* <:"1>a b" >>EOO + '1' + > + 'a b' + EOO + + : no-newline + : + $* <:"1>:a b" >>EOO + '1' + >: + 'a b' + EOO + } +} + +: doc-redirect +: +{ + : in + : + { + : newline + : + $* <:"0<>EOO + '0' + << + 'E O I' + EOO + + : no-newline + : + $* <:"0<<:E O I" >>EOO + '0' + <<: + 'E O I' + EOO + } + + : out + : + { + : newline + : + $* <:"1>>E O O" >>EOO + '1' + >> + 'E O O' + EOO + + : no-newline + : + $* <:"1>>:E O O" >>EOO + '1' + >>: + 'E O O' + EOO + } +} + +: file-redirect +: +{ + : in + : + $* <:"0<<>EOO + '0' + <<< + 'a b' + EOO + + : out + : + $* <:"1>=a b" >>EOO + '1' + >= + 'a b' + EOO + + : out-app + : + $* <:"1>+a b" >>EOO + '1' + >+ + 'a b' + EOO +} + +: cleanup +: +{ + : always + : + $* <:"&file" >>EOO + & + 'file' + EOO + + : maybe + : + $* <:"&?file" >>EOO + &? + 'file' + EOO + + : never + : + $* <:"&!file" >>EOO + &! + 'file' + EOO +} diff --git a/build2/test/script/lexer+command-line.test.testscript b/build2/test/script/lexer+command-line.test.testscript new file mode 100644 index 0000000..65be837 --- /dev/null +++ b/build2/test/script/lexer+command-line.test.testscript @@ -0,0 +1,208 @@ +# file : build2/test/script/lexer+command-line.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.arguments = command-line + +: semi +{ + : immediate + : + $* <"cmd;" >>EOO + 'cmd' + ; + + EOO + + : separated + : + $* <"cmd ;" >>EOO + 'cmd' + ; + + EOO + + : only + : + $* <";" >>EOO + ; + + EOO +} + +: colon +: +{ + : immediate + : + $* <"cmd: dsc" >>EOO + 'cmd' + : + 'dsc' + + EOO + + : separated + : + $* <"cmd :dsc" >>EOO + 'cmd' + : + 'dsc' + + EOO + + : only + : + $* <":" >>EOO + : + + EOO +} + +: redirect +: +{ + : pass + : + $* <"cmd <| 1>|" >>EOO + 'cmd' + <| + '1' + >| + + EOO + + : null + : + $* <"cmd <- 1>-" >>EOO + 'cmd' + <- + '1' + >- + + EOO + + : trace + : + $* <"cmd 1>!" >>EOO + 'cmd' + '1' + >! + + EOO + + : merge + : + $* <"cmd 1>&2" >>EOO + 'cmd' + '1' + >& + '2' + + EOO + + : str + : + $* <"cmd b" >>EOO + 'cmd' + < + 'a' + '1' + > + 'b' + + EOO + + : str-nn + : + $* <"cmd <:a 1>:b" >>EOO + 'cmd' + <: + 'a' + '1' + >: + 'b' + + EOO + + : doc + : + $* <"cmd <>EOO" >>EOO + 'cmd' + << + 'EOI' + '1' + >> + 'EOO' + + EOO + + : doc-nn + : + $* <"cmd <<:EOI 1>>:EOO" >>EOO + 'cmd' + <<: + 'EOI' + '1' + >>: + 'EOO' + + EOO + + : file-cmp + : + $* <"cmd <<>>out 2>>>err" >>EOO + 'cmd' + <<< + 'in' + >>> + 'out' + '2' + >>> + 'err' + + EOO + + : file-write + : + $* <"cmd >=out 2>+err" >>EOO + 'cmd' + >= + 'out' + '2' + >+ + 'err' + + EOO +} + +: cleanup +: +{ + : always + : + $* <"cmd &file" >>EOO + 'cmd' + & + 'file' + + EOO + + : maybe + : + $* <"cmd &?file" >>EOO + 'cmd' + &? + 'file' + + EOO + + : never + : + $* <"cmd &!file" >>EOO + 'cmd' + &! + 'file' + + EOO +} diff --git a/build2/test/script/lexer+description-line.test.testscript b/build2/test/script/lexer+description-line.test.testscript new file mode 100644 index 0000000..2d87d24 --- /dev/null +++ b/build2/test/script/lexer+description-line.test.testscript @@ -0,0 +1,33 @@ +# file : build2/test/script/lexer+description-line.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.arguments = description-line + +: full +: +$* <" foo bar " >>EOO +' foo bar ' + +EOO + +: space +: +$* <" " >>EOO +' ' + +EOO + +: empty +: +$* <"" >>EOO + +EOO + +: eof +: +$* <:"foo" >>EOO 2>>EOE != 0 +'foo' +EOO +stdin:1:4: error: expected newline at the end of description line +EOE diff --git a/build2/test/script/lexer+first-token.test.testscript b/build2/test/script/lexer+first-token.test.testscript new file mode 100644 index 0000000..f20f261 --- /dev/null +++ b/build2/test/script/lexer+first-token.test.testscript @@ -0,0 +1,97 @@ +# file : build2/test/script/lexer+first-token.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Note: this mode auto-expires after each token. +# +test.arguments = first-token + +: dot +: +$* <"." >>EOO +. + +EOO + +: semi +: +$* <";" >>EOO +; + +EOO + +: colon +: +$* <":" >>EOO +: + +EOO + +: lcbrace +: +$* <"{" >>EOO +{ + +EOO + +: rcbrace +: +$* <"}" >>EOO +} + +EOO + +: setup +: +$* <"+foo" >>EOO ++ +'foo' + +EOO + +: tdown +: +$* <"- foo" >>EOO +- +'foo' + +EOO + +: plus-leading +: +$* <"foo+bar" >>EOO +'foo+bar' + +EOO + +: minus-leading +: +$* <"foo- x" >>EOO +'foo-' +'x' + +EOO + +: assign +: +$* <"foo=" >>EOO +'foo' +'=' + +EOO + +: append +: +$* <"foo+=" >>EOO +'foo' +'+=' + +EOO + +: prepend +: +$* <"foo=+" >>EOO +'foo' +'=+' + +EOO diff --git a/build2/test/script/lexer+second-token.test.testscript b/build2/test/script/lexer+second-token.test.testscript new file mode 100644 index 0000000..8fdee23 --- /dev/null +++ b/build2/test/script/lexer+second-token.test.testscript @@ -0,0 +1,68 @@ +# file : build2/test/script/lexer+second-token.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Note: this mode auto-expires after each token. +# +test.arguments = second-token + +: semi +: +$* <";" >>EOO +; + +EOO + +: colon +: +$* <":" >>EOO +: + +EOO + +: assign +: +$* <"=foo" >>EOO += +'foo' + +EOO + +: append +: +$* <"+= foo" >>EOO ++= +'foo' + +EOO + +: prepend +: +$* <" =+ foo" >>EOO +=+ +'foo' + +EOO + +: assign-leading +: +$* <"foo=bar" >>EOO +'foo=bar' + +EOO + +: append-leading +: +$* <"foo+= bar" >>EOO +'foo+=' +'bar' + +EOO + +: prepend-leading +: +$* <"foo =+bar" >>EOO +'foo' +'=+bar' + +EOO diff --git a/build2/test/script/lexer+variable-line.test.testscript b/build2/test/script/lexer+variable-line.test.testscript new file mode 100644 index 0000000..b9c558d --- /dev/null +++ b/build2/test/script/lexer+variable-line.test.testscript @@ -0,0 +1,28 @@ +# file : build2/test/script/lexer+variable-line.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.arguments = variable-line + +: semi +: +$* <"cmd;" >>EOO +'cmd' +; + +EOO + +: semi-separated +: +$* <"cmd ;" >>EOO +'cmd' +; + +EOO + +: semi-only +: +$* <";" >>EOO +; + +EOO diff --git a/build2/test/script/lexer+variable.test.testscript b/build2/test/script/lexer+variable.test.testscript new file mode 100644 index 0000000..0ec323b --- /dev/null +++ b/build2/test/script/lexer+variable.test.testscript @@ -0,0 +1,70 @@ +# file : build2/test/script/lexer+variable.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test handling custom variable names ($*, $~, $NN). +# +test.arguments = variable + +: command +: +{ + : only + : + $* <"*" >>EOO + '*' + + EOO + + : followed + : + $* <"*abc" >>EOO + '*' + 'abc' + + EOO +} + +: working-dir +: +{ + : only + : + $* <"~" >>EOO + '~' + + EOO + + : followed + : + $* <"~123" >>EOO + '~' + '123' + + EOO +} + +: arg +: +{ + : only + : + $* <"0" >>EOO + '0' + + EOO + + : followed + : + $* <"1abc" >>EOO + '1' + 'abc' + + EOO + + : multi-digit + : + $* <"10" 2>>EOE != 0 + stdin:1:1: error: multi-digit special variable name + EOE +} diff --git a/build2/test/script/lexer.test.cxx b/build2/test/script/lexer.test.cxx new file mode 100644 index 0000000..56418b7 --- /dev/null +++ b/build2/test/script/lexer.test.cxx @@ -0,0 +1,85 @@ +// file : build2/test/script/lexer.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include +#include + +using namespace std; + +namespace build2 +{ + namespace test + { + namespace script + { + // Usage: argv[0] + // + int + main (int argc, char* argv[]) + { + lexer_mode m; + { + assert (argc == 2); + string s (argv[1]); + + if (s == "command-line") m = lexer_mode::command_line; + else if (s == "first-token") m = lexer_mode::first_token; + else if (s == "second-token") m = lexer_mode::second_token; + else if (s == "variable-line") m = lexer_mode::variable_line; + else if (s == "command-expansion") m = lexer_mode::command_expansion; + else if (s == "here-line-single") m = lexer_mode::here_line_single; + else if (s == "here-line-double") m = lexer_mode::here_line_double; + else if (s == "description-line") m = lexer_mode::description_line; + else if (s == "variable") m = lexer_mode::variable; + else assert (false); + } + + try + { + cin.exceptions (istream::failbit | istream::badbit); + + // Some modes auto-expire so we need something underneath. + // + bool u (m == lexer_mode::first_token || + m == lexer_mode::second_token || + m == lexer_mode::variable_line || + m == lexer_mode::description_line || + m == lexer_mode::variable); + + lexer l (cin, path ("stdin"), u ? lexer_mode::command_line : m); + if (u) + l.mode (m); + + // No use printing eos since we will either get it or loop forever. + // + for (token t (l.next ()); t.type != token_type::eos; t = l.next ()) + { + // Print each token on a separate line without quoting operators. + // + t.printer (cout, t, false); + cout << endl; + } + } + catch (const failed&) + { + return 1; + } + + return 0; + } + } + } +} + +int +main (int argc, char* argv[]) +{ + return build2::test::script::main (argc, argv); +} diff --git a/build2/test/script/parser+cleanup.test.testscript b/build2/test/script/parser+cleanup.test.testscript new file mode 100644 index 0000000..2c94afc --- /dev/null +++ b/build2/test/script/parser+cleanup.test.testscript @@ -0,0 +1,58 @@ +# file : build2/test/script/parser+cleanup.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: always +: +$* <>EOO +cmd &file +EOI +cmd &file +EOO + +: maybe +: +$* <>EOO +cmd &?file +EOI +cmd &?file +EOO + +: never +: +$* <>EOO +cmd &!file +EOI +cmd &!file +EOO + +: empty +: +$* <>EOE != 0 +cmd &"" +EOI +testscript:1:6: error: empty cleanup path +EOE + +: missed-before +: +{ + : token + : + : Path missed before command next token + : + $* <>EOE != 0 + cmd & >file + EOI + testscript:1:7: error: missing cleanup path + EOE + + : end + : Test path missed before end of command + : + $* <>EOE != 0 + cmd & + EOI + testscript:1:6: error: missing cleanup path + EOE +} diff --git a/build2/test/script/parser+command-if.test.testscript b/build2/test/script/parser+command-if.test.testscript new file mode 100644 index 0000000..ab6e6d5 --- /dev/null +++ b/build2/test/script/parser+command-if.test.testscript @@ -0,0 +1,548 @@ +# file : build2/test/script/parser+command-if.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: if +: +{ + : true + : + $* <>EOO + if true foo + cmd1 + cmd2 + end + EOI + ? true foo + cmd1 + cmd2 + EOO + + : false + : + $* <>EOO + if false foo + cmd1 + cmd2 + end + EOI + ? false foo + EOO + + : not-true + : + $* <>EOO + if! true foo + cmd1 + cmd2 + end + EOI + ? true foo + EOO + + : not-false + : + $* <>EOO + if! false foo + cmd1 + cmd2 + end + EOI + ? false foo + cmd1 + cmd2 + EOO + + : without-command + : + $* <>EOE != 0 + if + cmd + end + EOI + testscript:1:3: error: missing program + EOE + + : after-semi + : + $* -s <>EOO + cmd1; + if true + cmd2 + end + EOI + { + { + cmd1 + ? true + cmd2 + } + } + EOO + + : setup + : + $* -s <>EOO + +if true + cmd + end + EOI + { + ? true + +cmd + } + EOO + + : tdown + : + $* -s <>EOO + -if true + cmd + end + EOI + { + ? true + -cmd + } + EOO +} + +: elif +: +{ + : true + : + $* <>EOO + if false + cmd1 + cmd2 + elif true + cmd3 + cmd4 + end + EOI + ? false + ? true + cmd3 + cmd4 + EOO + + : false + : + $* <>EOO + if false + cmd1 + cmd2 + elif false + cmd3 + cmd4 + end + EOI + ? false + ? false + EOO + + : not-true + : + $* <>EOO + if false + cmd1 + cmd2 + elif! true + cmd3 + cmd4 + end + EOI + ? false + ? true + EOO + + : not-false + : + $* <>EOO + if false + cmd1 + cmd2 + elif! false + cmd3 + cmd4 + end + EOI + ? false + ? false + cmd3 + cmd4 + EOO + + : without-if + : + $* <>EOE != 0 + cmd + elif true + cmd + end + EOI + testscript:2:1: error: 'elif' without preceding 'if' + EOE + + : not-without-if + : + $* <>EOE != 0 + cmd + elif! true + cmd + end + EOI + testscript:2:1: error: 'elif!' without preceding 'if' + EOE + + : after-else + : + $* <>EOE != 0 + if false + cmd + else + cmd + elif true + cmd + end + EOI + testscript:5:1: error: 'elif' after 'else' + EOE +} + +: else +: +{ + : true + : + $* <>EOO + if false + cmd1 + cmd2 + else + cmd3 + cmd4 + end + EOI + ? false + cmd3 + cmd4 + EOO + + : false + : + $* <>EOO + if true + cmd1 + cmd2 + else + cmd3 + cmd4 + end + EOI + ? true + cmd1 + cmd2 + EOO + + : chain + : + $* <>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 + + : command-after + : + $* <>EOE != 0 + if true + cmd + else cmd + cmd + end + EOI + testscript:3:6: error: expected newline instead of 'cmd' + EOE + + : without-if + : + $* <>EOE != 0 + cmd + else + cmd + end + EOI + testscript:2:1: error: 'else' without preceding 'if' + EOE + + : after-else + : + $* <>EOE != 0 + if false + cmd + else + cmd + else + cmd + end + EOI + testscript:5:1: error: 'else' after 'else' + EOE +} + +: end +{ + : without-if + : + $* <>EOE != 0 + cmd + end + EOI + testscript:2:1: error: 'end' without preceding 'if' + EOE + + : before + { + : semi + : + $* -s <>EOO + if true + cmd1 + end; + cmd2 + EOI + { + { + ? true + cmd1 + cmd2 + } + } + EOO + + : command + : + $* <>EOE != 0 + if true + cmd + end cmd + EOI + testscript:3:5: error: expected newline instead of 'cmd' + EOE + + : colon + : + $* -s <>EOO + if true + cmd1 + cmd2 + end : test + EOI + { + : id:test + { + ? true + cmd1 + cmd2 + } + } + EOO + } +} + +: nested +: +{ + : take + : + $* <>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 + + : skip + : + $* <>EOO + if false + cmd1 + if false + cmd + elif false + if true + cmd + end + else + cmd2 + end + cmd3 + else + cmd + end + EOI + ? false + cmd + EOO +} + +: contained +{ + : semi + : + $* <>EOE != 0 + if + cmd; + cmd + end + EOI + testscript:2:3: error: ';' inside 'if' + EOE + + : colon-leading + : + $* <>EOE != 0 + if + : foo + cmd + end + EOI + testscript:2:3: error: description inside 'if' + EOE + + : colon-trailing + : + $* <>EOE != 0 + if + cmd : foo + end + EOI + testscript:2:3: error: description inside 'if' + EOE + + : eos + : + $* <>EOE != 0 + if + EOI + testscript:2:1: error: expected closing 'end' + EOE + + : scope + : + $* <>EOE != 0 + if + cmd + { + } + end + EOI + testscript:3:3: error: expected closing 'end' + EOE + + : setup + : + $* <>EOE != 0 + if + +cmd + end + EOI + testscript:2:3: error: setup command inside 'if' + EOE + + : tdown + : + $* <>EOE != 0 + if + -cmd + end + EOI + testscript:2:3: error: teardown command inside 'if' + EOE +} + +: line-index +: +$* -l <>EOO +if false + cmd + if true + cmd + end + cmd +elif false + cmd +else + cmd +end +EOI +? false # 1 +? false # 6 +cmd # 8 +EOO + +: var +: +$* <>EOO +if true + x = foo +else + x = bar +end; +cmd $x +EOI +? true +cmd foo +EOO + +: leading-and-trailing-description +: +$* <>EOE != 0 +: foo +if true + cmd +end : bar +EOI +testscript:4:1: error: both leading and trailing descriptions +EOE diff --git a/build2/test/script/parser+command-re-parse.test.testscript b/build2/test/script/parser+command-re-parse.test.testscript new file mode 100644 index 0000000..ef030de --- /dev/null +++ b/build2/test/script/parser+command-re-parse.test.testscript @@ -0,0 +1,12 @@ +# file : build2/test/script/parser+command-re-parse.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: double-quote +: +$* <>EOO +x = cmd \">-\" "'<-'" +$x +EOI +cmd '>-' '<-' +EOO diff --git a/build2/test/script/parser+description.test.testscript b/build2/test/script/parser+description.test.testscript new file mode 100644 index 0000000..7d840c3 --- /dev/null +++ b/build2/test/script/parser+description.test.testscript @@ -0,0 +1,486 @@ +# file : build2/test/script/parser+description.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: id +: +{ + : lead + : + $* <>EOO + : foo + cmd + EOI + : id:foo + cmd + EOO + + : trail + : + $* <>EOO + cmd : foo + EOI + : id:foo + cmd + EOO + + : dup + : Id uniqueness + : + { + : test + : + { + : test + : + $* <>EOE != 0 + : foo + cmd + : foo + cmd + EOI + testscript:3:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : group + : + $* <>EOE != 0 + : foo + cmd + : foo + { + cmd + cmd + } + EOI + testscript:3:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : derived + : + $* <>EOE != 0 + : 3 + cmd + cmd + EOI + testscript:3:1: error: duplicate id 3 + testscript:1:1: info: previously used here + EOE + } + + : group + : + { + : test + : + $* <>EOE != 0 + : foo + { + cmd + cmd + } + : foo + cmd + EOI + testscript:6:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : group + : + $* <>EOE != 0 + : foo + { + cmd + cmd + } + : foo + { + cmd + cmd + } + EOI + testscript:6:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : derived + : + $* <>EOE != 0 + : 3 + cmd + { + cmd + cmd + } + EOI + testscript:3:1: error: duplicate id 3 + testscript:1:1: info: previously used here + EOE + } + } +} + +: summary +{ + : lead + : + $* <>EOO + : foo bar + cmd + EOI + : sm:foo bar + cmd + EOO + + : trail + : + $* <>EOO + cmd: foo bar + EOI + : sm:foo bar + cmd + EOO + + : id + : + $* <>EOO + : foo-bar + : foo bar + cmd + EOI + : id:foo-bar + : sm:foo bar + cmd + EOO +} + +: details +{ + : id + : + $* <>EOO + : foo-bar + : + : foo bar + : bar baz + cmd + EOI + : id:foo-bar + : + : foo bar + : bar baz + cmd + EOO + + : summary + : + { + : only + : + $* <>EOO + : foo bar + : + : foo bar + : bar baz + cmd + EOI + : sm:foo bar + : + : foo bar + : bar baz + cmd + EOO + + : assumed + : + $* <>EOO + : foo bar + : bar baz + cmd + EOI + : foo bar + : bar baz + cmd + EOO + + : id + : + $* <>EOO + : foo-bar + : foo bar + : + : foo bar + : bar baz + cmd + EOI + : id:foo-bar + : sm:foo bar + : + : foo bar + : bar baz + cmd + EOO + + : id-assumed + : + $* <>EOO + : foo-bar + : bar baz + : baz fox + cmd + EOI + : foo-bar + : bar baz + : baz fox + cmd + EOO + } +} + +: legal +: +: Legal places for description. +: +{ + : var + : + $* <>EOO + : foo bar + x = y; + cmd $x + EOI + : sm:foo bar + cmd y + EOO +} + +: illegal +: +: Illegal places for description. +: +{ + : eof + : + $* <": foo" 2>>EOE != 0 + testscript:2:1: error: description before + EOE + + : rcbrace + : + $* <>EOE != 0 + { + cmd + : foo + } + EOI + testscript:4:1: error: description before '}' + EOE + + : setup + : + $* <>EOE != 0 + : foo + +cmd + EOI + testscript:2:1: error: description before setup command + EOE + + : tdown + : + $* <>EOE != 0 + : foo + -cmd + EOI + testscript:2:1: error: description before teardown command + EOE + + : var + : + $* <>EOE != 0 + : foo + x = y + EOI + testscript:2:1: error: description before setup/teardown variable + EOE + + : var-if + : + $* <>EOE != 0 + : foo + if true + x = y + end + EOI + testscript:2:1: error: description before/after setup/teardown variable-if + EOE + + : var-if-after + : + $* <>EOE != 0 + if true + x = y + end : foo + EOI + testscript:1:1: error: description before/after setup/teardown variable-if + EOE + + : test + : + $* <>EOE != 0 + cmd1; + : foo + cmd2 + EOI + testscript:2:1: error: description inside test + EOE +} + +: test-scope +: +: Interaction with test scope merging. +: +{ + : both + : + : No merge since both have description. + : + $* -s -i <>EOO + : foo + { + : bar + cmd + } + EOI + { + : id:foo + { # foo + : id:bar + { # foo/bar + cmd + } + } + } + EOO + + : test + : + : No merge since test has description. + : + $* -s -i <>EOO + { + : foo-bar + : foo bar + cmd + } + EOI + { + { # 1 + : id:foo-bar + : sm:foo bar + { # 1/foo-bar + cmd + } + } + } + EOO + + : group + : + $* -s -i <>EOO + : foo-bar + : foo bar + { + cmd + } + EOI + { + : id:foo-bar + : sm:foo bar + { # foo-bar + cmd + } + } + EOO +} + +: blanks +: +$* <>EOO +: +: +: foo bar +: bar baz +: +: baz fox +: +: +cmd +EOI +: foo bar +: bar baz +: +: baz fox +cmd +EOO + +: strip +: +$* <>EOO +: foo-bar +: bar baz +: +: baz fox +: fox biz +:biz buz +: +cmd +EOI +: id:foo-bar +: sm:bar baz +: +: baz fox +: fox biz +: biz buz +cmd +EOO + +: trail-compound +: +$* <>EOO +cmd1; +cmd2: foo +EOI +: id:foo +cmd1 +cmd2 +EOO + +: empty +: +$* <>EOE != 0 +: +: +cmd +EOI +testscript:1:1: error: empty description +EOE + +: trail-empty +: +$* <>EOE != 0 +cmd: +EOI +testscript:1:4: error: empty description +EOE + +: both +: +$* <>EOE != 0 +: foo +cmd : bar +EOI +testscript:2:1: error: both leading and trailing descriptions +EOE diff --git a/build2/test/script/parser+directive.test.testscript b/build2/test/script/parser+directive.test.testscript new file mode 100644 index 0000000..addd874 --- /dev/null +++ b/build2/test/script/parser+directive.test.testscript @@ -0,0 +1,74 @@ +# file : build2/test/script/parser+directive.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: not-directive +: +$* <>EOO +x = x +".include" foo.testscript +\.include foo.testscript +EOI +.include foo.testscript +.include foo.testscript +EOO + +: expected-name +: +$* <>EOE != 0 +.$ +EOI +testscript:1:2: error: expected directive name instead of '$' +EOE + +: unknown-name +: +$* <>EOE != 0 +.bogus +EOI +testscript:1:2: error: unknown directive 'bogus' +EOE + +: separated +: +touch foo.testscript; +$* <="foo-$(build.verson.project).testscript"; +cmd +EOI +$* <>EOO +.include "foo-$(build.verson.project).testscript" +EOI +cmd +EOO + +: after-semi +: +$* <>EOE != 0 +cmd; +.include foo.testscript +EOI +testscript:2:1: error: directive after ';' +EOE + +: semi-after +: +$* <>EOE != 0 +.include foo.testscript; +cmd +EOI +testscript:1:24: error: ';' after directive +EOE diff --git a/build2/test/script/parser+exit.test.testscript b/build2/test/script/parser+exit.test.testscript new file mode 100644 index 0000000..014afa4 --- /dev/null +++ b/build2/test/script/parser+exit.test.testscript @@ -0,0 +1,27 @@ +# file : build2/test/script/parser+exit.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: eq +: +$* <>EOO +cmd == 1 +EOI +cmd == 1 +EOO + +: ne +: +$* <>EOO +cmd!=1 +EOI +cmd != 1 +EOO + +: end +: +$* <>EOE != 0 +cmd != 1 <"foo" +EOI +testscript:1:10: error: unexpected '<' after command exit status +EOE diff --git a/build2/test/script/parser+expansion.test.testscript b/build2/test/script/parser+expansion.test.testscript new file mode 100644 index 0000000..71a21b3 --- /dev/null +++ b/build2/test/script/parser+expansion.test.testscript @@ -0,0 +1,36 @@ +# file : build2/test/script/parser+expansion.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: quote +: +: Make sure everything expanded as strings. +: +$* <>EOO +x = dir/ proj% proj%name proj%proj%dir/type{name name {name}} +cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} +cmd $x +EOI +cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} +cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} +EOO + +: unterm-quoted-seq +: +$* <>EOE != 0 +x = "'a bc" +cmd xy$x +EOI +:1:8: error: unterminated single-quoted sequence + testscript:2:5: info: while parsing string 'xy'a bc' +EOE + +: invalid-redirect +: +$* <>EOE != 0 +x = "1>&a" +cmd $x +EOI +:1:4: error: stdout merge redirect file descriptor must be 2 + testscript:2:5: info: while parsing string '1>&a' +EOE diff --git a/build2/test/script/parser+here-document.test.testscript b/build2/test/script/parser+here-document.test.testscript new file mode 100644 index 0000000..5e99a26 --- /dev/null +++ b/build2/test/script/parser+here-document.test.testscript @@ -0,0 +1,213 @@ +# file : build2/test/script/parser+here-document.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: end-marker +: +{ + : missing-newline + : + $* <'cmd <<' 2>>EOE != 0 + testscript:1:7: error: expected here-document end marker + EOE + + : missing-exit + : + $* <'cmd << != 0' 2>>EOE != 0 + testscript:1:8: error: expected here-document end marker + EOE + + : missing-empty + : + $* <'cmd <<""' 2>>EOE != 0 + testscript:1:7: error: expected here-document end marker + EOE + + : unseparated-expansion + : + $* <'cmd <>EOE != 0 + testscript:1:10: error: here-document end marker must be literal + EOE + + : quoted-single-partial + : + $* <"cmd <>EOE != 0 + testscript:1:7: error: partially-quoted here-document end marker + EOE + + : quoted-double-partial + : + $* <'cmd <<"FO"O' 2>>EOE != 0 + testscript:1:7: error: partially-quoted here-document end marker + EOE + + : quoted-mixed + : + $* <"cmd <<\"FO\"'O'" 2>>EOE != 0 + testscript:1:7: error: partially-quoted here-document end marker + EOE + + : unseparated + : + $* <>EOO + cmd <>EOO + cmd <<'EOF' + foo + EOF + EOI + cmd <>EOO + cmd <<"EOF" + foo + EOF + EOI + cmd <>EOO + cmd <>EOO + cmd <>EOO + cmd <>EOO + x = foo bar + cmd <<"EOF" + $x + EOF + EOI + cmd <>EOO + x = foo + cmd <<"EOF" + $x bar $x + EOF + EOI + cmd <>EOE != 0 + cmd <>EOO +cmd <>EOO +cmd <<"EOF" +'single' +"double" +b'o't"h" +('single' "double") +EOF +EOI +cmd <>EOO +cmd <"" +EOI +cmd <'' +EOO + +: empty-nn +: +$* <>EOO +cmd <:"" +EOI +cmd <:'' +EOO diff --git a/build2/test/script/parser+include.test.testscript b/build2/test/script/parser+include.test.testscript new file mode 100644 index 0000000..65be149 --- /dev/null +++ b/build2/test/script/parser+include.test.testscript @@ -0,0 +1,104 @@ +# file : build2/test/script/parser+include.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: none +: +$* <=foo.testscript; +$* <>EOO +.include foo.testscript +EOI +cmd +EOO + +: multiple +: +cat <"cmd foo" >=foo.testscript; +cat <"cmd bar" >=bar.testscript; +$* <>EOO +.include foo.testscript bar.testscript +EOI +cmd foo +cmd bar +EOO + +: once +: +cat <"cmd" >=foo.testscript; +$* <>EOO +.include foo.testscript +x +.include --once foo.testscript +.include --once bar/../foo.testscript +y +.include ../once/foo.testscript +EOI +cmd +x +y +cmd +EOO + +: group-id +: +cat <=foo.testscript; +{ + x = b +} +EOI +$* -s -i <>EOO +x = a +.include foo.testscript +EOI +{ + { # 2-foo-1 + } +} +EOO + +: test-id +: +cat <=foo.testscript; +cmd +EOI +$* -s -i <>EOO +x = a +.include foo.testscript +EOI +{ + { # 2-foo-1 + cmd + } +} +EOO + +: invalid-path +: +$* <>EOE != 0 +.include "" +EOI +testscript:1:2: error: invalid testscript include path '' +EOE + +: unable-open +: +$* <>~/EOE/ != 0 +.include foo.testscript +EOI +/testscript:1:2: error: unable to read testscript foo.testscript: .+/ +EOE diff --git a/build2/test/script/parser+pipe-expr.test.testscript b/build2/test/script/parser+pipe-expr.test.testscript new file mode 100644 index 0000000..18eb660 --- /dev/null +++ b/build2/test/script/parser+pipe-expr.test.testscript @@ -0,0 +1,133 @@ +# file : build2/test/script/parser+pipe-expr.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: pipe +: +$* <>EOO +cmd1 | cmd2|cmd3 +EOI +cmd1 | cmd2 | cmd3 +EOO + +: log +: +$* <>EOO +cmd1 || cmd2&&cmd3 +EOI +cmd1 || cmd2 && cmd3 +EOO + +: pipe-log +: +$* <>EOO +cmd1 | cmd2 && cmd3 | cmd4 +EOI +cmd1 | cmd2 && cmd3 | cmd4 +EOO + +: exit +: +$* <>EOO +cmd1|cmd2==1&&cmd3!=0|cmd4 +EOI +cmd1 | cmd2 == 1 && cmd3 != 0 | cmd4 +EOO + +: here-doc +: +$* <>EOO +cmd1 <>EOO2 && cmd3 <&1 | cmd4 2>>EOE4 >>EOO4 +input +one +EOI1 +ouput +two +EOO2 +input +three +EOI3 +error +four +EOE4 +output +four +EOO4 +EOI +cmd1 <>EOO2 && cmd3 <&1 | cmd4 >>EOO4 2>>EOE4 +input +one +EOI1 +ouput +two +EOO2 +input +three +EOI3 +output +four +EOO4 +error +four +EOE4 +EOO + +: leading +: +$* <>EOE != 0 +| cmd +EOI +testscript:1:1: error: missing program +EOE + +: trailing +: +$* <>EOE != 0 +cmd && +EOI +testscript:1:7: error: missing program +EOE + +: redirected +: +{ + : input + : + { + : first + : + $* <>EOO + cmd1 >EOE != 0 + cmd1 | cmd2 >EOO + cmd1 | cmd2 >foo + EOI + cmd1 | cmd2 >foo + EOO + + : non-last + : + $* <>EOE != 0 + cmd1 >foo | cmd2 + EOI + testscript:1:11: error: stdout is both redirected and piped + EOE + } +} diff --git a/build2/test/script/parser+pre-parse.test.testscript b/build2/test/script/parser+pre-parse.test.testscript new file mode 100644 index 0000000..7d9eb6c --- /dev/null +++ b/build2/test/script/parser+pre-parse.test.testscript @@ -0,0 +1,23 @@ +# file : build2/test/script/parser+pre-parse.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: attribute +: +{ + : pair + : + $* <>EOE != 0 + x = [foo=bar] + EOI + testscript:1:5: error: unknown value attribute foo=bar + EOE + + : pair-empty + : + $* <>EOE != 0 + x = [foo=] + EOI + testscript:1:5: error: unknown value attribute foo + EOE +} diff --git a/build2/test/script/parser+redirect.test.testscript b/build2/test/script/parser+redirect.test.testscript new file mode 100644 index 0000000..b0b967a --- /dev/null +++ b/build2/test/script/parser+redirect.test.testscript @@ -0,0 +1,356 @@ +# file : build2/test/script/parser+redirect.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# @@ Add tests for redirects other than trace, here-*, file and merge. +# @@ Does it make sense to split into separate files - one per redirect type? +# + +: trace +: +{ + $* <'cmd >!' >'cmd >!' : out + $* <'cmd 2>!' >'cmd 2>!' : err +} + +: str +: +{ + : literal + : + { + : portable-path + : + $* <>EOO + cmd /bar 2>/baz + EOI + cmd /bar 2>/baz + EOO + } + + : regex + : + { + : portable-path + : + $* <>EOO + cmd >/~%foo% 2>/~%bar% + EOI + cmd >/~%foo% 2>/~%bar% + EOO + } +} + +: doc +: +{ + : literal + : + { + : portable-path + : + $* <>EOO + cmd </EOO_ 2>/EOE_ + foo + EOI_ + bar + EOO_ + baz + EOE_ + EOI + cmd </EOO_ 2>/EOE_ + foo + EOI_ + bar + EOO_ + baz + EOE_ + EOO + + : sharing + : + { + : in-out + : + $* <>EOO + cmd <<:/EOF >>:/EOF + foo + EOF + EOI + cmd <<:/EOF >>:/EOF + foo + EOF + EOO + + : different + : + { + : modifiers + : + $* <>EOE != 0 + cmd <<:/EOF >>:EOF + foo + EOF + EOI + testscript:1:16: error: different modifiers for shared here-document 'EOF' + EOE + + : quoting + : + $* <>EOE != 0 + cmd <>"EOF" + foo + EOF + EOI + testscript:1:13: error: different quoting for shared here-document 'EOF' + EOE + } + } + } + + : regex + : + { + : portable-path + : + $* <>EOO + cmd >/~%EOF% 2>/~%EOE% + foo + EOF + bar + EOE + EOI + cmd >/~%EOF% 2>/~%EOE% + foo + EOF + bar + EOE + EOO + + : sharing + : + { + : in-out + : + $* <>EOO + cmd >>~/EOF/ 2>>~/EOF/ + foo + EOF + EOI + cmd >>~/EOF/ 2>>~/EOF/ + foo + EOF + EOO + + : different + : + { + : introducers + : + $* <>EOE != 0 + cmd >>~/EOF/ 2>>~%EOF% + foo + EOF + EOI + testscript:1:18: error: different introducers for shared here-document regex 'EOF' + EOE + + : flags + : + $* <>EOE != 0 + cmd >>~/EOF/ 2>>~/EOF/i + foo + EOF + EOI + testscript:1:18: error: different global flags for shared here-document regex 'EOF' + EOE + } + } + } +} + +: file +: +{ + : cmp + : + $* <>EOO + cmd 0<<>>b 2>>>c + EOI + cmd <<>>b 2>>>c + EOO + + : write + : + $* <>EOO + cmd 1>=b 2>+c + EOI + cmd >=b 2>+c + EOO + + : quote + : + $* <>EOO + cmd 0<<<"a f" 1>="b f" 2>+"c f" + EOI + cmd <<<'a f' >='b f' 2>+'c f' + EOO + + : in + : + { + : missed + : + $* <>EOE !=0 + cmd <<< + EOI + testscript:1:8: error: missing stdin file + EOE + + : empty + : + $* <>EOE !=0 + cmd <<<"" + EOI + testscript:1:8: error: empty stdin redirect path + EOE + } + + : out + : + { + : missed + : + $* <>EOE !=0 + cmd >= + EOI + testscript:1:7: error: missing stdout file + EOE + + : empty + : + $* <>EOE !=0 + cmd >="" + EOI + testscript:1:7: error: empty stdout redirect path + EOE + } + + : err + : + { + : missed + : + $* <>EOE !=0 + cmd 2>= + EOI + testscript:1:8: error: missing stderr file + EOE + + : empty + : + $* <>EOE !=0 + cmd 2>="" + EOI + testscript:1:8: error: empty stderr redirect path + EOE + } +} + +: merge +{ + : out + : + { + : err + : + $* <>EOO + cmd 1>&2 + EOI + cmd >&2 + EOO + + : no-mutual + : + $* <>EOO + cmd 1>&2 2>&1 2>a + EOI + cmd >&2 2>a + EOO + + : not-descriptor + : + $* <>EOE != 0 + cmd 1>&a + EOI + testscript:1:8: error: stdout merge redirect file descriptor must be 2 + EOE + + : self + : + $* <>EOE != 0 + cmd 1>&1 + EOI + testscript:1:8: error: stdout merge redirect file descriptor must be 2 + EOE + + : missed + : + $* <>EOE != 0 + cmd 1>& + EOI + testscript:1:8: error: missing stdout file descriptor + EOE + } + + : err + { + : out + : + $* <>EOO + cmd 2>&1 + EOI + cmd 2>&1 + EOO + + : no-mutual + : + $* <>EOO + cmd 1>&2 2>&1 >a + EOI + cmd >a 2>&1 + EOO + + : not-descriptor + : + $* <>EOE != 0 + cmd 2>&a + EOI + testscript:1:8: error: stderr merge redirect file descriptor must be 1 + EOE + + : self + : + $* <>EOE != 0 + cmd 2>&2 + EOI + testscript:1:8: error: stderr merge redirect file descriptor must be 1 + EOE + + : missed + : + $* <>EOE != 0 + cmd 2>& + EOI + testscript:1:8: error: missing stderr file descriptor + EOE + } + + : mutual + : + $* <>EOE != 0 + cmd 1>&2 2>&1 + EOI + testscript:1:14: error: stdout and stderr redirected to each other + EOE +} diff --git a/build2/test/script/parser+regex.test.testscript b/build2/test/script/parser+regex.test.testscript new file mode 100644 index 0000000..031492e --- /dev/null +++ b/build2/test/script/parser+regex.test.testscript @@ -0,0 +1,223 @@ +# file : build2/test/script/parser+regex.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: here-string +: +{ + : stdout + : + { + : missed + : + $* <'cmd >~' 2>>EOE != 0 + testscript:1:7: error: missing stdout here-string regex + EOE + + : no-introducer + : + $* <'cmd >~""' 2>>EOE != 0 + testscript:1:7: error: no introducer character in stdout regex redirect + EOE + + : no-term-introducer + : + $* <'cmd >~/' 2>>EOE != 0 + testscript:1:7: error: no closing introducer character in stdout regex redirect + EOE + + : portable-path-introducer + : + $* <'cmd >/~/foo/' 2>>EOE != 0 + testscript:1:8: error: portable path modifier and '/' introducer in stdout regex redirect + EOE + + : empty + : + $* <'cmd >~//' 2>>EOE != 0 + testscript:1:7: error: stdout regex redirect is empty + EOE + + : no-flags + : + $* <'cmd >~/fo*/' >'cmd >~/fo*/' + + : idot + : + $* <'cmd >~/fo*/d' >'cmd >~/fo*/d' + + : icase + : + $* <'cmd >~/fo*/i' >'cmd >~/fo*/i' + + : invalid-flags1 + : + $* <'cmd >~/foo/z' 2>>EOE != 0 + testscript:1:7: error: junk at the end of stdout regex redirect + EOE + + : invalid-flags2 + : + $* <'cmd >~/foo/iz' 2>>EOE != 0 + testscript:1:7: error: junk at the end of stdout regex redirect + EOE + + : no-newline + : + $* <'cmd >:~/fo*/' >'cmd >:~/fo*/' + } + + : stderr + : + { + : missed + : + $* <'cmd 2>~' 2>>EOE != 0 + testscript:1:8: error: missing stderr here-string regex + EOE + + : no-introducer + : + : Note that there is no need to reproduce all the errors as for stdout. + : All we need is to make sure that the proper description is passed to + : the parse_regex() function. + : + $* <'cmd 2>~""' 2>>EOE != 0 + testscript:1:8: error: no introducer character in stderr regex redirect + EOE + } + + : modifier-last + : + $* <'cmd >~/x' 2>>EOE != 0 + testscript:1:7: error: no closing introducer character in stdout regex redirect + EOE +} + +: here-doc +: +{ + : stdout + : + { + : missed + : + $* <'cmd >>~' 2>>EOE != 0 + testscript:1:8: error: expected here-document regex end marker + EOE + + : portable-path-introducer + : + $* <>EOE != 0 + cmd >>/~/EOO/ + foo + EOO + EOI + testscript:1:5: error: portable path modifier and '/' introducer in here-document regex end marker + EOE + + : unterminated-line-char + : + $* <>EOE != 0 + cmd >>~/EOO/ + / + EOO + EOI + testscript:2:1: error: no syntax line characters + EOE + + : empty + : + $* <>EOE != 0 + cmd >>:~/EOO/ + EOO + EOI + testscript:2:1: error: empty here-document regex + EOE + + : no-flags + : + $* <>EOO + cmd 2>>~/EOE/ + foo + /? + /foo/ + /foo/* + /foo/i + /foo/i* + + // + //* + EOE + EOI + cmd 2>>~/EOE/ + foo + /? + /foo/ + /foo/* + /foo/i + /foo/i* + + // + //* + EOE + EOO + + : no-newline + : + $* <'cmd >:~/fo*/' >'cmd >:~/fo*/' + $* <>EOO + cmd 2>>:~/EOE/ + foo + EOE + EOI + cmd 2>>:~/EOE/ + foo + EOE + EOO + + : end-marker-restore + : + { + : idot + : + $* <>EOO + cmd 2>>~/EOE/d + foo + EOE + EOI + cmd 2>>~/EOE/d + foo + EOE + EOO + + : icase + : + $* <>EOO + cmd 2>>~/EOE/i + foo + EOE + EOI + cmd 2>>~/EOE/i + foo + EOE + EOO + } + } + + : stderr + : + { + : missed + : + $* <'cmd 2>>~' 2>>EOE != 0 + testscript:1:9: error: expected here-document regex end marker + EOE + } + + : modifier-last + : + $* <'cmd >>~:/FOO/' 2>>EOE != 0 + testscript:1:8: error: expected here-document regex end marker + EOE +} diff --git a/build2/test/script/parser+scope-if.test.testscript b/build2/test/script/parser+scope-if.test.testscript new file mode 100644 index 0000000..faae297 --- /dev/null +++ b/build2/test/script/parser+scope-if.test.testscript @@ -0,0 +1,554 @@ +# file : build2/test/script/parser+scope-if.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: if +: +{ + : true + : + $* -s <>EOO + if true foo + { + cmd + } + EOI + { + ? true foo + { + cmd + } + } + EOO + + : false + : + $* -s <>EOO + if false foo + { + cmd + } + EOI + { + ? false foo + } + EOO + + : not-true + : + $* -s <>EOO + if! true + { + cmd + } + EOI + { + ? true + } + EOO + + : not-false + : + $* -s <>EOO + if! false + { + cmd + } + EOI + { + ? false + { + cmd + } + } + EOO + + : eos-inside + : + $* <>EOE != 0 + if + { + EOI + testscript:3:1: error: expected '}' at the end of the scope + EOE + +} + +: elif +: +{ + : true + : + $* -s <>EOO + if false + { + cmd + } + elif true + { + cmd1 + } + EOI + { + ? false + ? true + { + cmd1 + } + } + EOO + + : false + : + $* -s <>EOO + if false + { + cmd + } + elif false + { + cmd + } + EOI + { + ? false + ? false + } + EOO + + : not-false + : + $* -s <>EOO + if false + { + cmd + } + elif! false + { + cmd1 + } + EOI + { + ? false + ? false + { + cmd1 + } + } + EOO + + : not-true + : + $* -s <>EOO + if false + { + cmd + } + elif! true + { + cmd + } + EOI + { + ? false + ? true + } + EOO + + : after-else + : + $* <>EOE != 0 + if false + { + cmd + } + else + { + cmd + } + elif true + { + cmd + } + EOI + testscript:9:1: error: 'elif' after 'else' + EOE +} + +: else +: +{ + : true + : + $* -s <>EOO + if false + { + cmd + } + else + { + cmd1 + } + EOI + { + ? false + { + cmd1 + } + } + EOO + + : false + : + $* -s <>EOO + if true + { + cmd1 + } + else + { + cmd + } + EOI + { + ? true + { + cmd1 + } + } + EOO + + : chain + : + $* -s <>EOO + if false + { + cmd + } + elif false + { + cmd + cmd + } + elif false + { + cmd + } + elif true + { + cmd1 + cmd2 + } + elif false + { + cmd + } + else + { + cmd + cmd + } + EOI + { + ? false + ? false + ? false + ? true + { + { + cmd1 + } + { + cmd2 + } + } + } + EOO + + : scope-expected + : + $* <>EOE != 0 + if + { + cmd + } + else + cmd + EOI + testscript:5:1: error: expected scope after 'else' + EOE + + : after-else + : + $* <>EOE != 0 + if false + { + cmd + } + else + { + cmd + } + else + { + cmd + } + EOI + testscript:9:1: error: 'else' after 'else' + EOE +} + +: nested +: +{ + : take + : + $* -s <>EOO + if true + { + cmd1 + if false + { + cmd + } + elif false + { + if true + { + cmd + } + } + else + { + cmd2 + } + cmd3 + } + EOI + { + ? true + { + { + cmd1 + } + ? false + ? false + { + { + cmd2 + } + } + { + cmd3 + } + } + } + EOO + + : skip + : + $* -s <>EOO + if false + { + cmd1 + if false + { + cmd + } + elif false + { + if true + { + cmd + } + } + else + { + cmd2 + } + cmd3 + } + else + { + cmd + } + EOI + { + ? false + { + { + cmd + } + } + } + EOO +} + +: demote +: +{ + : group + : Chain remains a group + : + $* -s <>EOO + if false + { + cmd + } + elif true + { + cmd1 + cmd2 + } + else + { + cmd + } + EOI + { + ? false + ? true + { + { + cmd1 + } + { + cmd2 + } + } + } + EOO + + : test + : Chain demoted to test + : + $* -s <>EOO + if false + { + cmd + } + elif true + { + cmd1 + } + else + { + cmd + } + EOI + { + ? false + ? true + { + cmd1 + } + } + EOO +} + +: line-index +: Make sure command line index spans setup/if/teardown +: +$* -s -l <>EOO ++setup # 1 + +if false one # 2 +{ + cmd +} +elif false two # 3 +{ + cmd +} +elif true # 4 +{ + cmd1 +} +elif false # 5 +{ + cmd +} +else +{ + cmd +} + +if false one # 6 +{ + cmd +} +elif false two # 7 +{ + cmd +} +else +{ + cmd2 +} + +-tdown # 8 +EOI +{ + +setup # 1 + ? false one # 2 + ? false two # 3 + ? true # 4 + { + cmd1 # 0 + } + ? false one # 6 + ? false two # 7 + { + cmd2 # 0 + } + -tdown # 8 +} +EOO + +: scope-comman-if +: +$* -s <>EOO +if true +{ + cmd +} +if true + cmd1 + cmd2 +end +EOI +{ + ? true + { + cmd + } + { + ? true + cmd1 + cmd2 + } +} +EOO + +: shared-id-desc +: +$* -s -i <>EOO +: test summary +: +if false +{ + cmd +} +else +{ + cmd1 +} +EOI +{ + ? false + : sm:test summary + { # 3 + cmd1 + } +} +EOO diff --git a/build2/test/script/parser+scope.test.testscript b/build2/test/script/parser+scope.test.testscript new file mode 100644 index 0000000..9147161 --- /dev/null +++ b/build2/test/script/parser+scope.test.testscript @@ -0,0 +1,280 @@ +# file : build2/test/script/parser+scope.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +$* testscript <'cmd $@' >"cmd 1" : id-testscript +$* foo.testscript <'cmd $@' >"cmd foo/1" : id + +: wd-testscript +: +$* testscript <'cmd "$~"' >~"%cmd '?.+[/\\\\]test-driver[/\\\\]1'?%" + +: wd +: +$* foo.testscript <'cmd "$~"' >~"%cmd '?.+[/\\\\]test-driver[/\\\\]foo[/\\\\]1'?%" + +: group +: +{ + : empty + : + $* -s <>EOO + { + cmd1 + cmd2 + } + EOI + { + { + { + cmd1 + } + { + cmd2 + } + } + } + EOO +} + +: test +: +{ + : explicit + : + { + : one-level + : + $* -s -i <>EOO + { + cmd + } + EOI + { + { # 1 + cmd + } + } + EOO + + : nested + : + $* -s -i <>EOO + { + { + cmd + } + } + EOI + { + { # 1 + cmd + } + } + EOO + + : var + : + $* -s -i <>EOO + { + x = abc + cmd $x + } + EOI + { + { # 1 + cmd abc + } + } + EOO + + : setup + : + $* -s -i <>EOO + { + x = abc + +setup + cmd $x + } + EOI + { + { # 1 + +setup + { # 1/4 + cmd abc + } + } + } + EOO + } + + : implicit + { + : one-cmd + : + $* -s <>EOO + cmd1 + EOI + { + { + cmd1 + } + } + EOO + + : two-cmd + : + $* -s <>EOO + cmd1; + cmd2 + EOI + { + { + cmd1 + cmd2 + } + } + EOO + + : three-cmd + : + $* -s <>EOO + cmd1; + cmd2; + cmd3 + EOI + { + { + cmd1 + cmd2 + cmd3 + } + } + EOO + + : var + : + $* -s <>EOO + cmd1; + x = abc; + cmd2 $x + EOI + { + { + cmd1 + cmd2 abc + } + } + EOO + + : var-first + : + $* -s <>EOO + x = abc; + cmd $x + EOI + { + { + cmd abc + } + } + EOO + + : var-setup-tdown + : + $* -s <>EOO + x = abc + cmd $x + y = 123 + EOI + { + { + cmd abc + } + } + EOO + + : after-tdown + : + $* <>EOE != 0 + cmd1 + x = abc + cmd2 + EOI + testscript:3:1: error: test after teardown + testscript:2:1: info: last teardown line appears here + EOE + } +} + +: expected +{ + : newline-lcbrace + : + $* <:"{x" 2>>EOE != 0 + testscript:1:2: error: expected newline after '{' + EOE + + : rcbrace + : + $* <"{" 2>>EOE != 0 + testscript:2:1: error: expected '}' at the end of the scope + EOE + + : line-rcbrace + : + $* <>EOE != 0 + { + cmd; + } + EOI + testscript:3:1: error: expected another line after ';' + EOE + + : newline-rcbrace + : + $* <<:EOI 2>>EOE != 0 + { + } + EOI + testscript:2:2: error: expected newline after '}' + EOE + + : line-eof + : + $* <>EOE != 0 + cmd; + EOI + testscript:2:1: error: expected another line after ';' + EOE + + : newline-cmd + : + $* <<:EOI 2>>EOE != 0 + cmd; + EOI + testscript:1:5: error: expected newline instead of + EOE + + : newline-var + : + $* <:"x = abc;" 2>>EOE != 0 + testscript:1:9: error: expected newline instead of + EOE +} diff --git a/build2/test/script/parser+setup-teardown.test.testscript b/build2/test/script/parser+setup-teardown.test.testscript new file mode 100644 index 0000000..9d67309 --- /dev/null +++ b/build2/test/script/parser+setup-teardown.test.testscript @@ -0,0 +1,151 @@ +# file : build2/test/script/parser+setup-teardown.test.testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: setup +: +{ + : followed + : + { + : semi + : + $* <"+cmd;" 2>>EOE != 0 + testscript:1:5: error: ';' after setup command + EOE + + : colon + : + $* <"+cmd:" 2>>EOE != 0 + testscript:1:5: error: ':' after setup command + EOE + } + + : after + : + { + : test + : + $* <>EOE != 0 + cmd + +cmd + EOI + testscript:2:1: error: setup command after tests + EOE + + : after-tdownt + : + $* <>EOE != 0 + -cmd + +cmd + EOI + testscript:2:1: error: setup command after teardown + EOE + } + + : in-test + : + $* <>EOE != 0 + cmd; + +cmd + EOI + testscript:2:1: error: setup command in test + EOE +} + +: tdown +: +{ + : followed + : + { + : semi + : + $* <"-cmd;" 2>>EOE != 0 + testscript:1:5: error: ';' after teardown command + EOE + + : colon + : + $* <"-cmd:" 2>>EOE != 0 + testscript:1:5: error: ':' after teardown command + EOE + } + + : in-test + : + $* <>EOE != 0 + cmd; + -cmd + EOI + testscript:2:1: error: teardown command in test + EOE +} + +: var +: +{ + : between-tests + : + $* <>EOE != 0 + cmd + x = y + cmd + EOI + testscript:3:1: error: test after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-scope + : + $* <>EOE != 0 + cmd + x = y + { + cmd + } + EOI + testscript:3:1: error: scope after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-command-if + : + $* <>EOE != 0 + cmd + x = y + if true + cmd + end + EOI + testscript:3:1: error: test after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-scope-if + : + $* <>EOE != 0 + cmd + x = y + if true + { + cmd + } + EOI + testscript:3:1: error: scope after teardown + testscript:2:1: info: last teardown line appears here + EOE + + : between-tests-variable-if + : + $* <>EOO + cmd + x = y + if true + y = x + end + EOI + cmd + ? true + EOO +} diff --git a/build2/test/script/parser.test.cxx b/build2/test/script/parser.test.cxx new file mode 100644 index 0000000..1862f98 --- /dev/null +++ b/build2/test/script/parser.test.cxx @@ -0,0 +1,242 @@ +// file : build2/test/script/parser.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include +#include // reset() +#include + +#include + +#include +#include +#include + +using namespace std; + +namespace build2 +{ + namespace test + { + namespace script + { + // Here we assume we are running serially. + // + class print_runner: public runner + { + public: + print_runner (bool scope, bool id, bool line) + : scope_ (scope), id_ (id), line_ (line) {} + + virtual bool + test (scope&) const override + { + return true; + } + + virtual void + enter (scope& s, const location&) override + { + if (s.desc) + { + const auto& d (*s.desc); + + if (!d.id.empty ()) + cout << ind_ << ": id:" << d.id << endl; + + if (!d.summary.empty ()) + cout << ind_ << ": sm:" << d.summary << endl; + + if (!d.details.empty ()) + { + if (!d.id.empty () || !d.summary.empty ()) + cout << ind_ << ":" << endl; // Blank. + + const auto& s (d.details); + for (size_t b (0), e (0), n; e != string::npos; b = e + 1) + { + e = s.find ('\n', b); + n = ((e != string::npos ? e : s.size ()) - b); + + cout << ind_ << ':'; + if (n != 0) + { + cout << ' '; + cout.write (s.c_str () + b, static_cast (n)); + } + cout << endl; + } + } + } + + if (scope_) + { + cout << ind_ << "{"; + + if (id_ && !s.id_path.empty ()) // Skip empty root scope id. + cout << " # " << s.id_path.string (); + + cout << endl; + + ind_ += " "; + } + } + + virtual void + run (scope&, + const command_expr& e, command_type t, + size_t i, + const location&) override + { + const char* s (nullptr); + + switch (t) + { + case command_type::test: s = ""; break; + case command_type::setup: s = "+"; break; + case command_type::teardown: s = "-"; break; + } + + cout << ind_ << s << 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 + leave (scope&, const location&) override + { + if (scope_) + { + ind_.resize (ind_.size () - 2); + cout << ind_ << "}" << endl; + } + } + + private: + bool scope_; + bool id_; + bool line_; + string ind_; + }; + + // Usage: argv[0] [-s] [-i] [-l] [] + // + int + main (int argc, char* argv[]) + { + tracer trace ("main"); + + init (argv[0], 1); // Fake build system driver, default verbosity. + sched.startup (1); // Serial execution. + reset (strings ()); // No command line variables. + + bool scope (false); + bool id (false); + bool line (false); + path name; + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-s") + scope = true; + else if (a == "-i") + id = true; + else if (a == "-l") + line = true; + else + { + name = path (move (a)); + break; + } + } + + if (name.empty ()) + name = path ("testscript"); + + assert (!id || scope); // Id can only be printed with scope. + + try + { + 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", + string (), + trace)); + + value& v ( + tt.assign ( + var_pool.rw ().insert ( + "test.target", variable_visibility::project))); + + v = cast ((*global_scope)["build.host"]); + + testscript& st ( + targets.insert (work, + dir_path (), + name.leaf ().base ().string (), + name.leaf ().extension (), + trace)); + + tt.path (path ("driver")); + st.path (name); + + // Parse and run. + // + parser p; + script s (tt, st, dir_path (work) /= "test-driver"); + p.pre_parse (cin, s); + + print_runner r (scope, id, line); + p.execute (s, r); + } + catch (const failed&) + { + return 1; + } + + return 0; + } + } + } +} + +int +main (int argc, char* argv[]) +{ + return build2::test::script::main (argc, argv); +} diff --git a/build2/test/script/regex.test.cxx b/build2/test/script/regex.test.cxx new file mode 100644 index 0000000..7b89e4d --- /dev/null +++ b/build2/test/script/regex.test.cxx @@ -0,0 +1,301 @@ +// file : build2/test/script/regex.test.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include // is_pod, is_array + +#include + +using namespace std; +using namespace build2::test::script::regex; + +int +main () +{ + using lc = line_char; + using ls = line_string; + using lr = line_regex; + using cf = char_flags; + using cr = char_regex; + + // Test line_char. + // + { + static_assert (is_pod::value && !is_array::value, + "line_char must be char-like"); + + // Zero-initialed line_char should be the null-char as required by + // char_traits<>::length() specification. + // + assert (lc () == lc::nul); + + line_pool p; + + assert (lc::eof == -1); + assert (lc::nul == 0); + + enum meta {mn = 'n', mp = 'p'}; + + // Special roundtrip. + // + assert (lc ('0').special () == '0'); + assert (lc (0).special () == 0); + assert (lc (-1).special () == -1); + assert (lc ('p').special () == 'p'); + assert (lc (u'\u2028').special () == u'\u2028'); + + // Special comparison. + // + assert (lc ('0') == lc ('0')); + assert (lc ('0') == '0'); + assert (lc ('n') == mn); + assert (mn == static_cast (lc ('n'))); + + assert (lc ('0') != lc ('1')); + assert (lc ('0') != '1'); + assert (lc ('n') != mp); + assert (lc ('0') != lc ("0", p)); + assert (lc ('0') != lc (cr ("0"), p)); + + assert (lc ('0') < lc ('1')); + assert (lc ('0') < '1'); + assert (lc ('1') < lc ("0", p)); + assert (lc ('n') < mp); + + assert (lc ('0') <= '1'); + assert (lc ('0') <= lc ('1')); + assert (lc ('n') <= mn); + assert (lc ('1') <= lc ("0", p)); + + // Literal roundtrip. + // + assert (*lc ("abc", p).literal () == "abc"); + + // Literal comparison. + // + assert (lc ("a", p) == lc ("a", p)); + assert (lc ("a", p).literal () == lc ("a", p).literal ()); + assert (char (lc ("a", p)) == '\a'); + + assert (lc ("a", p) != lc ("b", p)); + assert (!(lc ("a", p) != lc (cr ("a"), p))); + assert (lc ("a", p) != lc (cr ("b"), p)); + + assert (lc ("a", p) < lc ("b", p)); + assert (!(lc ("a", p) < lc (cr ("a"), p))); + + assert (lc ("a", p) <= lc ("b", p)); + assert (lc ("a", p) <= lc (cr ("a"), p)); + assert (lc ("a", p) < lc (cr ("c"), p)); + + // Regex roundtrip. + // + assert (regex_match ("abc", *lc (cr ("abc"), p).regex ())); + + // Regex flags. + // + // icase + // + assert (regex_match ("ABC", cr ("abc", cf::icase))); + + // idot + // + assert (!regex_match ("a", cr ("[.]", cf::idot))); + assert (!regex_match ("a", cr ("[\\.]", cf::idot))); + + assert (regex_match ("a", cr ("."))); + assert (!regex_match ("a", cr (".", cf::idot))); + assert (regex_match ("a", cr ("\\.", cf::idot))); + assert (!regex_match ("a", cr ("\\."))); + + // regex::transform() + // + // The function is static and we can't test it directly. So we will test + // it indirectly via regex matches. + // + // @@ Would be nice to somehow address the inability to test internals (not + // exposed via headers). As a part of utility library support? + // + assert (regex_match (".a[.", cr (".\\.\\[[.]", cf::idot))); + assert (regex_match (".a[.", cr (".\\.\\[[\\.]", cf::idot))); + assert (!regex_match ("ba[.", cr (".\\.\\[[.]", cf::idot))); + assert (!regex_match (".a[b", cr (".\\.\\[[.]", cf::idot))); + assert (!regex_match (".a[b", cr (".\\.\\[[\\.]", cf::idot))); + + // Regex comparison. + // + assert (lc ("a", p) == lc (cr ("a|b"), p)); + assert (lc (cr ("a|b"), p) == lc ("a", p)); + } + + // Test char_traits. + // + { + using ct = char_traits; + using vc = vector; + + lc c; + ct::assign (c, '0'); + assert (c == ct::char_type ('0')); + + assert (ct::to_char_type (c) == c); + assert (ct::to_int_type (c) == c); + + assert (ct::eq_int_type (c, c)); + assert (!ct::eq_int_type (c, lc::eof)); + + assert (ct::eof () == lc::eof); + + assert (ct::not_eof (c) == c); + assert (ct::not_eof (lc::eof) != lc::eof); + + ct::assign (&c, 1, '1'); + assert (c == ct::int_type ('1')); + + assert (ct::eq (lc ('0'), lc ('0'))); + assert (ct::lt (lc ('0'), lc ('1'))); + + vc v1 ({'0', '1', '2'}); + vc v2 (3, lc::nul); + + assert (ct::find (v1.data (), 3, '1') == v1.data () + 1); + + ct::copy (v2.data (), v1.data (), 3); + assert (v2 == v1); + + v2.push_back (lc::nul); + assert (ct::length (v2.data ()) == 3); + + // Overlaping ranges. + // + ct::move (v1.data () + 1, v1.data (), 2); + assert (v1 == vc ({'0', '0', '1'})); + + v1 = vc ({'0', '1', '2'}); + ct::move (v1.data (), v1.data () + 1, 2); + assert (v1 == vc ({'1', '2', '2'})); + } + + // Test line_char_locale and ctype (only non-trivial functions). + // + { + using ct = ctype; + + line_char_locale l; + assert (has_facet (l)); + + // It is better not to create q facet on stack as it is + // reference-countable. + // + const ct& t (use_facet (l)); + line_pool p; + + assert (t.is (ct::digit, '0')); + assert (!t.is (ct::digit, '?')); + assert (!t.is (ct::digit, lc ("0", p))); + + const lc chars[] = { '0', '?' }; + ct::mask m[2]; + + const lc* b (chars); + const lc* e (chars + 2); + + // Cast flag value to mask type and compare to mask. + // + auto fl = [] (ct::mask m, ct::mask f) {return m == f;}; + + t.is (b, e, m); + assert (fl (m[0], ct::digit) && fl (m[1], 0)); + + assert (t.scan_is (ct::digit, b, e) == b); + assert (t.scan_is (0, b, e) == b + 1); + + assert (t.scan_not (ct::digit, b, e) == b + 1); + assert (t.scan_not (0, b, e) == b); + + { + char nr[] = "0?"; + lc wd[2]; + t.widen (nr, nr + 2, wd); + assert (wd[0] == b[0] && wd[1] == b[1]); + } + + { + lc wd[] = {'0', lc ("a", p)}; + char nr[2]; + t.narrow (wd, wd + 2, '-', nr); + assert (nr[0] == '0' && nr[1] == '-'); + } + } + + // Test regex_traits. Functions other that value() are trivial. + // + { + regex_traits t; + + const int radix[] = {8, 10}; // Radix 16 is not supported by line_char. + const char digits[] = "0123456789ABCDEF"; + + for (size_t r (0); r < 2; ++r) + { + for (int i (0); i < radix[r]; ++i) + assert (t.value (digits[i], radix[r]) == i); + } + } + + // Test line_regex construction. + // + { + line_pool p; + lr r1 ({lc ("foo", p), lc (cr ("ba(r|z)"), p)}, move (p)); + + lr r2 (move (r1)); + assert (regex_match (ls ({lc ("foo", r2.pool), lc ("bar", r2.pool)}), r2)); + assert (!regex_match (ls ({lc ("foo", r2.pool), lc ("ba", r2.pool)}), r2)); + } + + // Test line_regex match. + // + { + line_pool p; + + const lc foo ("foo", p); + const lc bar ("bar", p); + const lc baz ("baz", p); + const lc blank ("", p); + + assert (regex_match (ls ({foo, bar}), lr ({foo, bar}))); + assert (!regex_match (ls ({foo, baz}), lr ({foo, bar}))); + + assert (regex_match (ls ({bar, foo}), + lr ({'(', foo, '|', bar, ')', '+'}))); + + assert (regex_match (ls ({foo, foo, bar}), + lr ({'(', foo, ')', '\\', '1', bar}))); + + assert (regex_match (ls ({foo}), lr ({lc (cr ("fo+"), p)}))); + assert (regex_match (ls ({foo}), lr ({lc (cr (".*"), p)}))); + assert (regex_match (ls ({blank}), lr ({lc (cr (".*"), p)}))); + + assert (regex_match (ls ({blank, blank, foo}), + lr ({blank, '*', foo, blank, '*'}))); + + assert (regex_match (ls ({blank, blank, foo}), lr ({'.', '*'}))); + + assert (regex_match (ls ({blank, blank}), + lr ({blank, '*', foo, '?', blank, '*'}))); + + assert (regex_match (ls ({foo}), lr ({foo, '{', '1', '}'}))); + assert (regex_match (ls ({foo, foo}), lr ({foo, '{', '1', ',', '}'}))); + + assert (regex_match (ls ({foo, foo}), + lr ({foo, '{', '1', ',', '2', '}'}))); + + assert (!regex_match (ls ({foo, foo}), + lr ({foo, '{', '3', ',', '4', '}'}))); + + assert (regex_match (ls ({foo}), lr ({'(', '?', '=', foo, ')', foo}))); + assert (regex_match (ls ({foo}), lr ({'(', '?', '!', bar, ')', foo}))); + } +} diff --git a/buildfile b/buildfile index 5828d9d..fa23190 100644 --- a/buildfile +++ b/buildfile @@ -9,5 +9,4 @@ # Don't install tests or the INSTALL file. # tests/: install = false -unit-tests/: install = false doc{INSTALL}@./: install = false diff --git a/unit-tests/.gitignore b/unit-tests/.gitignore deleted file mode 100644 index ababe77..0000000 --- a/unit-tests/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -driver - -# The immediate test/ sub-directory shouldn't be ignored. -# -*/**/test/ -test-*/ diff --git a/unit-tests/cc/lexer/buildfile b/unit-tests/cc/lexer/buildfile deleted file mode 100644 index 4eaef44..0000000 --- a/unit-tests/cc/lexer/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/cc/lexer/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../../build2/ -exe{driver}: {hxx cxx}{*} ../../../build2/libue{b} testscript{*} diff --git a/unit-tests/cc/lexer/char-literal.testscript b/unit-tests/cc/lexer/char-literal.testscript deleted file mode 100644 index cbcb462..0000000 --- a/unit-tests/cc/lexer/char-literal.testscript +++ /dev/null @@ -1,67 +0,0 @@ -# file : unit-tests/cc/lexer/char-literal.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test character literals. -# - -: normal -: -$* <>EOO -'a' -'aa' -'"' -EOI - - - -EOO - -: prefix -: -$* <>EOO -L'a' -U'a' -u'a' -u8'a' -u8R'a' -EOI - - - - -'u8R' - -EOO - -: suffix -: -$* <>EOO -'a'x -'a'_X123 -EOI - - -EOO - -: escape -: -$* <>EOO -'\'' -'\\' -'\\\'' -'\n' -U'\U0001f34c' -EOI - - - - - -EOO - -: unterminated -: -$* <"'a" 2>>EOE != 0 -stdin:1:1: error: unterminated character literal -EOE diff --git a/unit-tests/cc/lexer/comment.testscript b/unit-tests/cc/lexer/comment.testscript deleted file mode 100644 index 347c2e7..0000000 --- a/unit-tests/cc/lexer/comment.testscript +++ /dev/null @@ -1,88 +0,0 @@ -# file : unit-tests/cc/lexer/comment.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test C and C++ comments. -# - -: c-comment -: -$* <"';'" -// /* -; -// */ -EOI - -: c-unterminated -: -$* <>EOE != 0 -/* -comment -EOI -stdin:1:2: error: unterminated comment -EOE - -: cxx-unterminated -: -$* <<:EOI -// comment -EOI - -: in-char-literal -: -$* <>EOO -'//' -'/*'*/ -EOI - - - - -EOO - -: in-string-literal -: -$* <>EOO -"//foo" -"/*"*/ -EOI - - - - -EOO - -: in-raw-string-literal -: -$* <>EOO -R"X( -// foo -/* bar -)X"*/ -EOI - - - -EOO diff --git a/unit-tests/cc/lexer/driver.cxx b/unit-tests/cc/lexer/driver.cxx deleted file mode 100644 index ebbb9ab..0000000 --- a/unit-tests/cc/lexer/driver.cxx +++ /dev/null @@ -1,80 +0,0 @@ -// file : unit-tests/cc/lexer/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include -#include - -#include -#include - -#include - -using namespace std; -using namespace butl; - -namespace build2 -{ - namespace cc - { - // Usage: argv[0] [-l] [] - // - int - main (int argc, char* argv[]) - { - bool loc (false); - const char* file (nullptr); - - for (int i (1); i != argc; ++i) - { - string a (argv[i]); - - if (a == "-l") - loc = true; - else - { - file = argv[i]; - break; - } - } - - try - { - ifdstream is; - if (file != nullptr) - is.open (file); - else - { - file = "stdin"; - is.open (fddup (stdin_fd ())); - } - - lexer l (is, path (file)); - - // No use printing eos since we will either get it or loop forever. - // - for (token t; l.next (t) != token_type::eos; ) - { - cout << t; - - if (loc) - cout << ' ' << t.file << ':' << t.line << ':' << t.column; - - cout << endl; - } - } - catch (const failed&) - { - return 1; - } - - return 0; - } - } -} - -int -main (int argc, char* argv[]) -{ - return build2::cc::main (argc, argv); -} diff --git a/unit-tests/cc/lexer/line.testscript b/unit-tests/cc/lexer/line.testscript deleted file mode 100644 index 9dcd7e3..0000000 --- a/unit-tests/cc/lexer/line.testscript +++ /dev/null @@ -1,67 +0,0 @@ -# file : unit-tests/cc/lexer/line.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test line continuations. -# - -: identifier -: -$* <"'foo123'" -fo\ -o\ -1\ -2\ -3 -EOI - -: punctuation -: -$* <'' -.\ -.\ -. -EOI - -: c-comment -: -$* <>EOO -\abc -EOI - -'abc' -EOO - -: multiple -: -$* <>EOO -\\ -EOI - -EOO - -: unterminated -: -$* <<:EOI >'' -\ -EOI diff --git a/unit-tests/cc/lexer/number.testscript b/unit-tests/cc/lexer/number.testscript deleted file mode 100644 index 0b4c888..0000000 --- a/unit-tests/cc/lexer/number.testscript +++ /dev/null @@ -1,48 +0,0 @@ -# file : unit-tests/cc/lexer/number.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test numbers. -# - -$* <'1' >'' -$* <'.1' >'' -$* <'1.' >'' - -$* <'0b101' >'' -$* <'0123' >'' -$* <'0X12AB' >'' - -$* <'1e10' >'' -$* <'1E+10' >'' -$* <'0x1.p10' >'' -$* <'0x1.P-10' >'' - -$* <"123'456" >'' -$* <"0xff00'00ff" >'' - -$* <'123f' >'' -$* <'123UL' >'' -$* <'123_X' >'' - -: separate-punctuation -: -$* <'123;' >>EOO - -';' -EOO - -: separate-plus-minus -: -$* <'1.0_a+2.0' >>EOO - - - -EOO - -: separate-whitespace -: -$* <'123 abc' >>EOO - -'abc' -EOO diff --git a/unit-tests/cc/lexer/preprocessor.testscript b/unit-tests/cc/lexer/preprocessor.testscript deleted file mode 100644 index e826144..0000000 --- a/unit-tests/cc/lexer/preprocessor.testscript +++ /dev/null @@ -1,73 +0,0 @@ -# file : unit-tests/cc/lexer/preprocessor.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test preprocessor lines. -# - -: normal -: -$* <>EOO -; -# 1 "test.cxx" 2 -; - ; -# 4 -; -#line 8 "z:\\tmp\\test.hxx" -; -#line 10 -; -# 5 "test.cxx" -; -EOI -';' stdin:1:1 -';' test.cxx:1:1 -';' test.cxx:2:3 -';' test.cxx:4:1 -';' z:\tmp\test.hxx:8:1 -';' z:\tmp\test.hxx:10:1 -';' test.cxx:5:1 -EOO - -: include -: -$* <>EOE != 0 -#include -EOI -stdin:1:1: error: unexpected #include directive -EOE - -: nested -: -$* <>EOO -#define FOO(x) #y -; -EOI -';' -EOO diff --git a/unit-tests/cc/lexer/raw-string-literal.testscript b/unit-tests/cc/lexer/raw-string-literal.testscript deleted file mode 100644 index 4ab08f7..0000000 --- a/unit-tests/cc/lexer/raw-string-literal.testscript +++ /dev/null @@ -1,90 +0,0 @@ -# file : unit-tests/cc/lexer/raw-string-literal.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test raw string literals. -# - -: normal -: -$* <>EOO -R"()" -R"(ab)" -R"(a"b)" -R"(a)b)" -R"%(a%)b)%" -R"X(a - b)X" -R"X(a\ - b)X" -EOI - - - - - - - -EOO - -: prefix -: -$* <>EOO -LR"(ab)" -UR"(ab)" -uR"(ab)" -u8R"(ab)" -EOI - - - - -EOO - -: suffix -: -$* <>EOO -R"(ab)"x -R"(ab)"_X123 -EOI - - -EOO - -: escape -: -$* <>EOO -R"(\)" -EOI - -EOO - -: invalid-no-paren -: -$* <'R"a"' 2>>EOE != 0 -stdin:1:2: error: invalid raw string literal -EOE - -: invalid-paren -: -$* <'R")()("' 2>>EOE != 0 -stdin:1:2: error: invalid raw string literal -EOE - -: invalid-unterminated-paren -: -$* <'R"(abc"' 2>>EOE != 0 -stdin:1:2: error: invalid raw string literal -EOE - -: invalid-unterminated-delimiter -: -$* <'R"X(abc)"' 2>>EOE != 0 -stdin:1:2: error: invalid raw string literal -EOE - -: invalid-unterminated-quote -: -$* <'R"X(abc)X' 2>>EOE != 0 -stdin:1:2: error: invalid raw string literal -EOE diff --git a/unit-tests/cc/lexer/string-literal.testscript b/unit-tests/cc/lexer/string-literal.testscript deleted file mode 100644 index db3798f..0000000 --- a/unit-tests/cc/lexer/string-literal.testscript +++ /dev/null @@ -1,65 +0,0 @@ -# file : unit-tests/cc/lexer/string-literal.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test string literals (except raw). -# - -: normal -: -$* <>EOO -"aa" -"'" -"a""b" -EOI - - - - -EOO - -: prefix -: -$* <>EOO -L"ab" -U"ab" -u"ab" -u8"ab" -EOI - - - - -EOO - -: suffix -: -$* <>EOO -"ab"x -"ab"_X123 -EOI - - -EOO - -: escape -: -$* <>EOO -"\"\"" -"\\\\" -"\\\"\\" -"\n\t" -U"a\U0001f34c" -EOI - - - - - -EOO - -: unterminated -: -$* <'"ab' 2>>EOE != 0 -stdin:1:1: error: unterminated string literal -EOE diff --git a/unit-tests/cc/parser/buildfile b/unit-tests/cc/parser/buildfile deleted file mode 100644 index d9e3e28..0000000 --- a/unit-tests/cc/parser/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/cc/parser/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../../build2/ -exe{driver}: {hxx cxx}{*} ../../../build2/libue{b} testscript{*} diff --git a/unit-tests/cc/parser/driver.cxx b/unit-tests/cc/parser/driver.cxx deleted file mode 100644 index 19a2133..0000000 --- a/unit-tests/cc/parser/driver.cxx +++ /dev/null @@ -1,66 +0,0 @@ -// file : unit-tests/cc/parser/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include -#include - -#include -#include - -#include - -using namespace std; -using namespace butl; - -namespace build2 -{ - namespace cc - { - // Usage: argv[0] [] - // - int - main (int argc, char* argv[]) - { - try - { - const char* file; - - ifdstream is; - if (argc > 1) - { - file = argv[1]; - is.open (file); - } - else - { - file = "stdin"; - is.open (fddup (stdin_fd ())); - } - - parser p; - translation_unit u (p.parse (is, path (file))); - - for (const module_import& m: u.mod.imports) - cout << (m.exported ? "export " : "") - << "import " << m.name << ';' << endl; - - if (!u.mod.name.empty ()) - cout << (u.mod.iface ? "export " : "") - << "module " << u.mod.name << ';' << endl; - } - catch (const failed&) - { - return 1; - } - - return 0; - } - } -} - -int -main (int argc, char* argv[]) -{ - return build2::cc::main (argc, argv); -} diff --git a/unit-tests/cc/parser/module.testscript b/unit-tests/cc/parser/module.testscript deleted file mode 100644 index dc7f3e4..0000000 --- a/unit-tests/cc/parser/module.testscript +++ /dev/null @@ -1,149 +0,0 @@ -# file : unit-tests/cc/parser/module.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test C++ module constructs. -# - -: import -: -$* <>EOI -import foo; -import foo.bar; -import foo.bar.baz; -EOI - -: module-implementation -: -$* <>EOI -module foo; -EOI - -: module-interface -: -$* <>EOI -export module foo; -EOI - -: export-imported -: -$* <>EOO -export import foo; -EOI -export import foo; -EOO - -: export-imported-block -: -$* <>EOO -import bar; - -export {import foo;} - -export -{ - namespace foo - { - class c {}; - } - - template int f (); - - import bar; -} -EOI -export import bar; -export import foo; -EOO - -: non-module -: -$* <>EOO -import foo [[export({import})]]; -module bar [[module({module})]]; -EOI -import foo; -module bar; -EOO - -: import-duplicate -: -$* <>EOO -import foo; -import bar.baz; -import foo; -import bar . baz; -EOI -import foo; -import bar.baz; -EOO - -: brace-missing -: -$* <>EOE != 0 -export -{ - class foo - { - //}; - module foo; -} -EOI -stdin:8:1: error: {}-imbalance detected -EOE - -: brace-stray -: -$* <>EOE != 0 -export -{ - class foo - { - };} -} -module foo; -EOI -stdin:6:1: error: {}-imbalance detected -EOE - -: import-missing-name -: -$* <>EOE != 0 -import ; -EOI -stdin:1:8: error: module name expected instead of ';' -EOE - -: module-missing-name -: -$* <>EOE != 0 -module ; -EOI -stdin:1:1: error: module declaration expected after leading module marker -EOE - -: import-missing-semi -: -$* <>EOE != 0 -import foo -EOI -stdin:2:1: error: ';' expected instead of -EOE - -: module-missing-semi -: -$* <>EOE != 0 -export module foo -EOI -stdin:2:1: error: ';' expected instead of -EOE diff --git a/unit-tests/function/buildfile b/unit-tests/function/buildfile deleted file mode 100644 index 68dae02..0000000 --- a/unit-tests/function/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/function/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../build2/ -exe{driver}: {hxx cxx}{*} ../../build2/libue{b} testscript{*} diff --git a/unit-tests/function/call.testscript b/unit-tests/function/call.testscript deleted file mode 100644 index 36234a1..0000000 --- a/unit-tests/function/call.testscript +++ /dev/null @@ -1,161 +0,0 @@ -# file : unit-tests/function/call.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: qual-implicit -: -$* <'print $dummy.dummy0()' >'abc' - -: qual-explicit -: -$* <'print $dummy.qual()' >'abc' - -: qual-fail -: -$* <'print $qual()' 2>>EOE != 0 -buildfile:1:8: error: unmatched call to qual() - info: candidate: dummy.qual() -EOE - -: derived-base -: Test derived-to-base overload resolution -: -$* <'print $dummy.abs([dir_path] .)' >'false'; -$* <'print $dummy.abs([abs_dir_path] .)' >'true' - -: variadic -: -$* <'print $variadic([bool] true, foo, bar)' >'3' - -: fail -: -$* <'$fail()' 2>>EOE != 0 -error: failed -buildfile:1:2: info: while calling fail() -EOE - -: fail-invalid-arg -: -$* <'$fail_arg(abc)' 2>>EOE != 0 -error: invalid argument: invalid uint64 value: 'abc' -buildfile:1:2: info: while calling fail_arg() -EOE - -: no-match-name -: -$* <'$bogus()' 2>>EOE != 0 -buildfile:1:2: error: unmatched call to bogus() -EOE - -: no-match-count -: -$* <'$dummy0(abc)' 2>>EOE != 0 -buildfile:1:2: error: unmatched call to dummy0() - info: candidate: dummy0(), qualified name dummy.dummy0 -EOE - -: no-match-type -: -$* <'$dummy1([uint64] 123)' 2>>EOE != 0 -buildfile:1:2: error: unmatched call to dummy1(uint64) - info: candidate: dummy1(string), qualified name dummy.dummy1 -EOE - -: ambig -: -$* <'$ambig(abc)' 2>>~/EOE/ != 0 -buildfile:1:2: error: ambiguous call to ambig() -/(( - info: candidate: ambig( [, uint64]), qualified name dummy.ambig - info: candidate: ambig( [, string]), qualified name dummy.ambig -/)|( - info: candidate: ambig( [, string]), qualified name dummy.ambig - info: candidate: ambig( [, uint64]), qualified name dummy.ambig -/)) -EOE - -: unmatched -: -$* <'$ambig(abc, def)' 2>>~/EOE/ != 0 -buildfile:1:2: error: unmatched call to ambig(, ) -/(( - info: candidate: ambig( [, uint64]), qualified name dummy.ambig - info: candidate: ambig( [, string]), qualified name dummy.ambig -/)|( - info: candidate: ambig( [, string]), qualified name dummy.ambig - info: candidate: ambig( [, uint64]), qualified name dummy.ambig -/)) -EOE - -: reverse -: -$* <'print $reverse([string] abc)' >'abc' - -: optional-absent -: -$* <'print $optional()' >'true' - -: optional-present -: -$* <'print $optional(abc)' >'false' - -: null-true -: -$* <'print $nullable([null])' >'true' - -: null-false -: -$* <'print $nullable(nonull)' >'false' - -: null-fail -: -$* <'$dummy1([string null])' 2>>EOE != 0 -error: invalid argument: null value -buildfile:1:2: info: while calling dummy1(string) -EOE - -: print-call-1-untyped -: -$* <'$bogus(abc)' 2>>EOE != 0 -buildfile:1:2: error: unmatched call to bogus() -EOE - -: print-call-1-typed -: -$* <'$bogus([uint64] 123)' 2>>EOE != 0 -buildfile:1:2: error: unmatched call to bogus(uint64) -EOE - -: print-call-2 -: -$* <'$bogus(abc, [uint64] 123)' 2>>EOE != 0 -buildfile:1:2: error: unmatched call to bogus(, uint64) -EOE - -: print-fovl -: -$* <'$ambig([bool] true)' 2>>~/EOE/ != 0 -buildfile:1:2: error: ambiguous call to ambig(bool) -/(( - info: candidate: ambig( [, uint64]), qualified name dummy.ambig - info: candidate: ambig( [, string]), qualified name dummy.ambig -/)|( - info: candidate: ambig( [, string]), qualified name dummy.ambig - info: candidate: ambig( [, uint64]), qualified name dummy.ambig -/)) -EOE - -: print-fovl-variadic -: -$* <'$variadic(abc)' 2>>EOE != 0 -buildfile:1:2: error: unmatched call to variadic() - info: candidate: variadic(bool [, ...]) -EOE - -: member-function -: -$* <'print $dummy.length([path] abc)' >'3' - -: data-member -: -$* <'print $dummy.type([name] cxx{foo})' >'cxx' diff --git a/unit-tests/function/driver.cxx b/unit-tests/function/driver.cxx deleted file mode 100644 index 0e128e7..0000000 --- a/unit-tests/function/driver.cxx +++ /dev/null @@ -1,131 +0,0 @@ -// file : unit-tests/function/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include - -#include -#include - -#include -#include -#include -#include -#include - -using namespace std; - -namespace build2 -{ - static const optional arg_bool[1] = - { - &value_traits::value_type - }; - - static dir_path - scoped (const scope*, dir_path d) - { - return d; - } - - static void - scoped_void (const scope*, dir_path) - { - } - - int - main (int, char* argv[]) - { - init (argv[0], 1); // Fake build system driver, default verbosity. - reset (strings ()); // No command line variables. - - function_family f ("dummy"); - - f["fail"] = []() {fail << "failed" << endf;}; - f["fail_arg"] = [](names a) {return convert (move (a[0]));}; - - f["nullable"] = [](names* a) {return a == nullptr;}; - f["optional"] = [](optional a) {return !a;}; - - f["dummy0"] = []() {return "abc";}; - f["dummy1"] = [](string s) {return s;}; - f["dummy2"] = [](uint64_t x, uint64_t y) {return x + y;}; - - f["ambig"] = [](names a, optional) {return a;}; - f["ambig"] = [](names a, optional) {return a;}; - - f["reverse"] = [](names a) {return a;}; - - f["scoped"] = [](const scope*, names a) {return a;}; - f["scoped_void"] = [](const scope*, names) {}; - f["scoped"] = &scoped; - f["scoped_void"] = &scoped_void; - - f[".qual"] = []() {return "abc";}; - - f[".length"] = &path::size; // Member function. - f[".type"] = &name::type; // Data member. - - f[".abs"] = [](dir_path d) {return d.absolute ();}; - - // Variadic function with first required argument of type bool. Returns - // number of arguments passed. - // - functions.insert ( - "variadic", - function_overload ( - nullptr, - 1, - function_overload::arg_variadic, - function_overload::types (arg_bool, 1), - [] (const scope*, vector_view args, const function_overload&) - { - return value (static_cast (args.size ())); - })); - - // Dump arguments. - // - functions.insert ( - "dump", - function_overload ( - nullptr, - 0, - function_overload::arg_variadic, - function_overload::types (), - [] (const scope*, vector_view args, const function_overload&) - { - for (value& a: args) - { - if (a.null) - cout << "[null]"; - else if (!a.empty ()) - { - names storage; - cout << reverse (a, storage); - } - cout << endl; - } - return value (nullptr); - })); - - try - { - scope& s (*scope::global_); - - parser p; - p.parse_buildfile (cin, path ("buildfile"), s, s); - } - catch (const failed&) - { - return 1; - } - - return 0; - } -} - -int -main (int argc, char* argv[]) -{ - return build2::main (argc, argv); -} diff --git a/unit-tests/function/syntax.testscript b/unit-tests/function/syntax.testscript deleted file mode 100644 index 6af5f7e..0000000 --- a/unit-tests/function/syntax.testscript +++ /dev/null @@ -1,29 +0,0 @@ -# file : unit-tests/function/syntax.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -$* <'$dump()' >:'' : none -$* <'$dump( )' >:'' : none-in-spaces -$* <'$dump("")' >'{}' : one-empty -$* <'$dump(a)' >'a' : one-single -$* <'$dump(a b c)' >'a b c' : one-list -$* <'$dump(d/t{x y z})' >'d/t{x} d/t{y} d/t{z}' : one-names - -$* <'print a$dummy1([string] b)c' >'abc' : concat -$* <'print $dummy2([uint64] 123, [uint64] 321)' >'444' : multi-arg - -: quoting -: Verify we can inhibit function call with quoting -: -$* <>EOO -foo = FOO -bar = BAR - -print $foo"($bar)" -print "$foo"($bar) -print "$foo""($bar)" -EOI -FOOBAR -FOOBAR -FOOBAR -EOO diff --git a/unit-tests/lexer/buildfile b/unit-tests/lexer/buildfile deleted file mode 100644 index b7cc4c6..0000000 --- a/unit-tests/lexer/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/lexer/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../build2/ -exe{driver}: {hxx cxx}{*} ../../build2/libue{b} testscript{*} diff --git a/unit-tests/lexer/buildspec.testscript b/unit-tests/lexer/buildspec.testscript deleted file mode 100644 index 71568ae..0000000 --- a/unit-tests/lexer/buildspec.testscript +++ /dev/null @@ -1,16 +0,0 @@ -# file : unit-tests/lexer/buildspec.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -test.arguments = buildspec - -: punctuation -: -$* <:'x,x(x)' >>EOO -'x' -, -'x' - ( -'x' -) -EOO diff --git a/unit-tests/lexer/comment.testscript b/unit-tests/lexer/comment.testscript deleted file mode 100644 index 44e1866..0000000 --- a/unit-tests/lexer/comment.testscript +++ /dev/null @@ -1,139 +0,0 @@ -# file : unit-tests/lexer/comment.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: single-line -: -{ - : only - : - $* <>:EOO - # comment - EOI - EOO - - : first - : - $* <>EOO - # comment - foo - EOI - 'foo' - - EOO - - : last - : - $* <>EOO - foo - # comment - EOI - 'foo' - - EOO - - : few - : - $* <>EOO - foo - # comment - # comment - EOI - 'foo' - - EOO - - : cont - : - $* <>EOO - foo - # comment\\ - bar - EOI - 'foo' - - 'bar' - - EOO - - : same - : - $* <>EOO - foo # comment - bar # comment - EOI - 'foo' - - 'bar' - - EOO -} - -: multi-line -: -{ - : only - : - $* <>:EOO - #\ - comment - comment - #\ - EOI - EOO - - : empty - : - $* <>:EOO - #\ - #\ - EOI - EOO - - : start-same - : - $* <>EOO - foo #\ - comment - comment - #\ - EOI - 'foo' - - EOO - - : end-same - : - $* <>EOO - #\ - comment - comment - foo #\ - bar - EOI - 'bar' - - EOO - - : end-not - : - $* <>EOO - #\ - comment - #\ not an end - foo #\ - bar - EOI - 'bar' - - EOO - - : unterm - : - $* <>EOE != 0 - #\ - comment - EOI - stdin:3:1: error: unterminated multi-line comment - EOE -} diff --git a/unit-tests/lexer/driver.cxx b/unit-tests/lexer/driver.cxx deleted file mode 100644 index a5cdb8d..0000000 --- a/unit-tests/lexer/driver.cxx +++ /dev/null @@ -1,98 +0,0 @@ -// file : unit-tests/lexer/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include -#include - -#include -#include - -#include -#include - -using namespace std; - -namespace build2 -{ - // Usage: argv[0] [-q] [] - // - int - main (int argc, char* argv[]) - { - bool quote (false); - lexer_mode m (lexer_mode::normal); - - for (int i (1); i != argc; ++i) - { - string a (argv[i]); - - if (a == "-q") - quote = true; - else - { - if (a == "normal") m = lexer_mode::normal; - else if (a == "variable") m = lexer_mode::variable; - else if (a == "value") m = lexer_mode::value; - else if (a == "attribute") m = lexer_mode::attribute; - else if (a == "eval") m = lexer_mode::eval; - else if (a == "buildspec") m = lexer_mode::buildspec; - else assert (false); - break; - } - } - - try - { - cin.exceptions (istream::failbit | istream::badbit); - - // Most alternative modes auto-expire so we need something underneath. - // - lexer l (cin, path ("stdin")); - - if (m != lexer_mode::normal) - l.mode (m); - - // No use printing eos since we will either get it or loop forever. - // - for (token t (l.next ()); t.type != token_type::eos; t = l.next ()) - { - if (t.separated && t.type != token_type::newline) - cout << ' '; - - // Print each token on a separate line without quoting operators. - // - t.printer (cout, t, false); - - if (quote) - { - char q ('\0'); - switch (t.qtype) - { - case quote_type::single: q = 'S'; break; - case quote_type::double_: q = 'D'; break; - case quote_type::mixed: q = 'M'; break; - case quote_type::unquoted: break; - } - - if (q != '\0') - cout << " [" << q << (t.qcomp ? "/C" : "/P") << ']'; - } - - cout << endl; - } - } - catch (const failed&) - { - return 1; - } - - return 0; - } -} - -int -main (int argc, char* argv[]) -{ - return build2::main (argc, argv); -} diff --git a/unit-tests/lexer/eval.testscript b/unit-tests/lexer/eval.testscript deleted file mode 100644 index 6768756..0000000 --- a/unit-tests/lexer/eval.testscript +++ /dev/null @@ -1,76 +0,0 @@ -# file : unit-tests/lexer/eval.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -test.arguments = eval - -: punctuation -: -$* <:'x:x{x}x[x]x$x?x,x(x)' >>EOO -'x' -: -'x' -{ -'x' -} -'x' -[ -'x' -] -'x' -$ -'x' -? -'x' -, -'x' -( -'x' -) -EOO - -: logical -: -$* <:'x|x||x&x&&x!x!!x)' >>EOO -'x|x' -|| -'x&x' -&& -'x' -! -'x' -! -! -'x' -) -EOO - -: comparison -: -$* <:'x=x==x!=xx>=)' >>EOO -'x=x' -== -'x' -!= -'x' -< -'x' -<= -'x' -> -'x' ->= -) -EOO - -: newline -: -$* <'x' >- 2>>EOE != 0 -stdin:1:2: error: newline in evaluation context -EOE - -: eof -: -$* <:'' 2>>EOE != 0 -stdin:1:1: error: unterminated evaluation context -EOE diff --git a/unit-tests/lexer/quoting.testscript b/unit-tests/lexer/quoting.testscript deleted file mode 100644 index e9767f2..0000000 --- a/unit-tests/lexer/quoting.testscript +++ /dev/null @@ -1,108 +0,0 @@ -# file : unit-tests/lexer/quoting.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -test.options += -q - -: unquoted -: -$* <'foo' >>EOO -'foo' - -EOO - -: comp -: -{ - : single - : - $* <":'foo':" >>EOO - : - 'foo' [S/C] - : - - EOO - - : double - : - $* <':"foo":' >>EOO - : - 'foo' [D/C] - : - - EOO - - : single-empty - : - $* <"''" >>EOO - '' [S/C] - - EOO - - : double-empty - : - $* <'""' >>EOO - '' [D/C] - - EOO -} - -: part -{ - : quoted - { - : start - : Token start already quoted - : - $* <'"$foo"' >>EOO - '' [D/P] - $ [D/C] - 'foo' [D/P] - - EOO - - : end - : Token end still quoted - : - $* <'"foo$"' >>EOO - 'foo' [D/P] - $ [D/C] - '' [D/P] - - EOO - } - - : unquoted - { - : start - : Token starts with unquoted character - : - $* <'f"oo"' >>EOO - 'foo' [D/P] - - EOO - - : end - : Token continous with unquoted character - : - $* <'"fo"o' >>EOO - 'foo' [D/P] - - EOO - - : escape - : Token continous with unquoted escaped character - : - $* <'"fo"\"' >>EOO - 'fo"' [D/P] - - EOO - } -} - -: mixed -: -$* <"\"fo\"'o'" >>EOO -'foo' [M/P] - -EOO diff --git a/unit-tests/name/buildfile b/unit-tests/name/buildfile deleted file mode 100644 index dfd729e..0000000 --- a/unit-tests/name/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/name/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../build2/ -exe{driver}: {hxx cxx}{*} ../../build2/libue{b} diff --git a/unit-tests/name/driver.cxx b/unit-tests/name/driver.cxx deleted file mode 100644 index 69d3e2d..0000000 --- a/unit-tests/name/driver.cxx +++ /dev/null @@ -1,96 +0,0 @@ -// file : unit-tests/name/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include - -#include -#include - -#include // Includes name. -#include - -#include - -using namespace std; - -namespace build2 -{ - int - main (int, char*[]) - { - using dir = dir_path; - - // Test string representation. - // - { - auto ts = [] (const name& n) {return to_string (n);}; - - assert (ts (name ()) == ""); - - assert (ts (name ("foo")) == "foo"); - - assert (ts (name (dir ("bar/"))) == "bar/"); - assert (ts (name (dir ("bar/baz/"))) == "bar/baz/"); - - assert (ts (name (dir ("bar/"), "dir", "")) == "dir{bar/}"); - assert (ts (name (dir ("bar/baz/"), "dir", "")) == "bar/dir{baz/}"); - - assert (ts (name (dir ("bar/"), "foo")) == "bar/foo"); - - assert (ts (name (dir ("bar/"), "dir", "foo")) == "bar/dir{foo}"); - assert (ts (name (dir ("bar/baz/"), "dir", "foo")) == "bar/baz/dir{foo}"); - } - - // Test stream representation. - // - { - auto ts = [] (const name& n, bool quote = true) - { - ostringstream os; - stream_verb (os, stream_verbosity (0, 1)); - to_stream (os, n, quote); - return os.str (); - }; - - assert (ts (name ()) == "''"); - assert (ts (name (), false) == "{}"); - - assert (ts (name ("foo")) == "foo"); - - assert (ts (name (dir ("bar/"))) == "bar/"); - assert (ts (name (dir ("bar/baz/"))) == "bar/baz/"); - - assert (ts (name (dir ("bar/"), "dir", "")) == "dir{bar/}"); - assert (ts (name (dir ("bar/baz/"), "dir", "")) == "bar/dir{baz/}"); - - assert (ts (name (dir ("bar/"), "foo")) == "bar/foo"); - - assert (ts (name (dir ("bar/"), "dir", "foo")) == "bar/dir{foo}"); - assert (ts (name (dir ("bar/baz/"), "dir", "foo")) == "bar/baz/dir{foo}"); - - // Quoting. - // - assert (ts (name (dir ("bar baz/"), "dir", "foo fox")) == "'bar baz/'dir{'foo fox'}"); - - // Relative logic. - // -#ifndef _WIN32 - dir rb ("/bar/"); - relative_base = &rb; - - assert (ts (name (dir ("/bar/"), "dir", "")) == "dir{./}"); - assert (ts (name (dir ("/bar/"), "", "foo")) == "foo"); - assert (ts (name (dir ("/bar/baz/"), "dir", "")) == "dir{baz/}"); -#endif - } - - return 0; - } -} - -int -main (int argc, char* argv[]) -{ - return build2::main (argc, argv); -} diff --git a/unit-tests/scheduler/buildfile b/unit-tests/scheduler/buildfile deleted file mode 100644 index c666bb1..0000000 --- a/unit-tests/scheduler/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/scheduler/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../build2/ -exe{driver}: {hxx cxx}{*} ../../build2/libue{b} diff --git a/unit-tests/scheduler/driver.cxx b/unit-tests/scheduler/driver.cxx deleted file mode 100644 index 5f03523..0000000 --- a/unit-tests/scheduler/driver.cxx +++ /dev/null @@ -1,187 +0,0 @@ -// file : unit-tests/scheduler/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include -#include - -#include -#include - -#include -#include - -#include - -using namespace std; - -namespace build2 -{ - // Usage argv[0] [-v ] [-d ] [-c ] - // [-q ] - // - // -v task tree volume (affects both depth and width), for example 100 - // -d computational difficulty of each task, for example 10 - // -c max active threads, if unspecified or 0, then hardware concurrency - // -q task queue depth, if unspecified or 0, then appropriate default used - // - // Specifying any option also turns on the verbose mode. - // - // Notes on testing: - // - // 1. Ideally you would want to test things on an SMP machine. - // - // 2. When need to compare performance, disable turbo boost since its - // availability depends on CPU utilization/temperature: - // - // # echo '1' >/sys/devices/system/cpu/intel_pstate/no_turbo - // - // 3. Use turbostat(1) to see per-CPU details (utlization, frequency): - // - // $ sudo turbostat --interval 1 ./driver -d 8 -v 300 - // - static bool - prime (uint64_t); - - // Find # of primes in the [x, y) range. - // - static void - inner (uint64_t x, uint64_t y, uint64_t& r) - { - for (; x != y; ++x) - if (prime (x)) - r++; - }; - - int - main (int argc, char* argv[]) - { - bool verb (false); - - // Adjust assert() below if changing these defaults. - // - size_t volume (100); - uint32_t difficulty (10); - - size_t max_active (0); - size_t queue_depth (0); - - for (int i (1); i != argc; ++i) - { - string a (argv[i]); - - if (a == "-v") - volume = stoul (argv[++i]); - else if (a == "-d") - difficulty = stoul (argv[++i]); - else if (a == "-c") - max_active = stoul (argv[++i]); - else if (a == "-q") - queue_depth = stoul (argv[++i]); - else - assert (false); - - verb = true; - } - - if (max_active == 0) - max_active = scheduler::hardware_concurrency (); - - scheduler s (max_active, 1, 0, queue_depth); - - // Find # prime counts of primes in [i, d*i*i) ranges for i in (0, n]. - // - auto outer = [difficulty, &s] (size_t n, vector& o, uint64_t& r) - { - scheduler::atomic_count task_count (0); - - for (size_t i (1); i <= n; ++i) - { - o[i - 1] = 0; - s.async (task_count, - inner, - i, - i * i * difficulty, - ref (o[i - 1])); - } - - s.wait (task_count); - assert (task_count == 0); - - for (uint64_t v: o) - r += prime (v) ? 1 : 0; - }; - - vector r (volume, 0); - vector> o (volume, vector ()); - - scheduler::atomic_count task_count (0); - - for (size_t i (0); i != volume; ++i) - { - o[i].resize (i); - s.async (task_count, - outer, - i, - ref (o[i]), - ref (r[i])); - } - - s.wait (task_count); - assert (task_count == 0); - - uint64_t n (0); - for (uint64_t v: r) - n += v; - - if (volume == 100 && difficulty == 10) - assert (n == 580); - - scheduler::stat st (s.shutdown ()); - - if (verb) - { - cerr << "result " << n << endl - << endl; - - cerr << "thread_max_active " << st.thread_max_active << endl - << "thread_max_total " << st.thread_max_total << endl - << "thread_helpers " << st.thread_helpers << endl - << "thread_max_waiting " << st.thread_max_waiting << endl - << endl - << "task_queue_depth " << st.task_queue_depth << endl - << "task_queue_full " << st.task_queue_full << endl - << endl - << "wait_queue_slots " << st.wait_queue_slots << endl - << "wait_queue_collisions " << st.wait_queue_collisions << endl; - } - - return 0; - } - - static bool - prime (uint64_t x) - { - if (x == 2 || x == 3) - return true; - - if (x < 2 || x % 2 == 0 || x % 3 == 0) - return false; - - // Test divisors starting from 5 and incrementing alternatively by 2/4. - // - for (uint64_t d (5), i (2); d * d <= x; d += i, i = 6 - i) - { - if (x % d == 0) - return false; - } - - return true; - } -} - -int -main (int argc, char* argv[]) -{ - return build2::main (argc, argv); -} diff --git a/unit-tests/test/script/lexer/buildfile b/unit-tests/test/script/lexer/buildfile deleted file mode 100644 index 190d586..0000000 --- a/unit-tests/test/script/lexer/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/test/script/lexer/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../../../build2/ -exe{driver}: {hxx cxx}{*} ../../../../build2/libue{b} testscript{*} diff --git a/unit-tests/test/script/lexer/command-expansion.testscript b/unit-tests/test/script/lexer/command-expansion.testscript deleted file mode 100644 index 581e13c..0000000 --- a/unit-tests/test/script/lexer/command-expansion.testscript +++ /dev/null @@ -1,248 +0,0 @@ -# file : unit-tests/test/script/lexer/command-expansion.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -test.arguments = command-expansion - -: pass-redirect -: -{ - : in - : - $* <:"0<|" >>EOO - '0' - <| - EOO - - : arg-in - : - $* <:"0 <|" >>EOO - '0 ' - <| - EOO - - : out - : - $* <:"1>|" >>EOO - '1' - >| - EOO - - : arg-out - : - $* <:"1 >|" >>EOO - '1 ' - >| - EOO -} - -: null-redirect -: -{ - : in - : - $* <:"0<-" >>EOO - '0' - <- - EOO - - : arg-in - : - $* <:"0 <-" >>EOO - '0 ' - <- - EOO - - : out - : - $* <:"1>-" >>EOO - '1' - >- - EOO - - : arg-out - : - $* <:"1 >-" >>EOO - '1 ' - >- - EOO -} - -: trace-redirect -: -{ - : out - : - $* <:"1>!" >>EOO - '1' - >! - EOO - - : arg-out - : - $* <:"1 >!" >>EOO - '1 ' - >! - EOO -} - -: merge-redirect -: -{ - : out - : - $* <:"1>&2" >>EOO - '1' - >& - '2' - EOO - - : arg-out - : - $* <:"1 >&2" >>EOO - '1 ' - >& - '2' - EOO -} - -: str-redirect -: -{ - : in - : - { - : newline - : - $* <:"0>EOO - '0' - < - 'a b' - EOO - - : no-newline - : - $* <:"0<:a b" >>EOO - '0' - <: - 'a b' - EOO - } - - : out - : - { - : newline - : - $* <:"1>a b" >>EOO - '1' - > - 'a b' - EOO - - : no-newline - : - $* <:"1>:a b" >>EOO - '1' - >: - 'a b' - EOO - } -} - -: doc-redirect -: -{ - : in - : - { - : newline - : - $* <:"0<>EOO - '0' - << - 'E O I' - EOO - - : no-newline - : - $* <:"0<<:E O I" >>EOO - '0' - <<: - 'E O I' - EOO - } - - : out - : - { - : newline - : - $* <:"1>>E O O" >>EOO - '1' - >> - 'E O O' - EOO - - : no-newline - : - $* <:"1>>:E O O" >>EOO - '1' - >>: - 'E O O' - EOO - } -} - -: file-redirect -: -{ - : in - : - $* <:"0<<>EOO - '0' - <<< - 'a b' - EOO - - : out - : - $* <:"1>=a b" >>EOO - '1' - >= - 'a b' - EOO - - : out-app - : - $* <:"1>+a b" >>EOO - '1' - >+ - 'a b' - EOO -} - -: cleanup -: -{ - : always - : - $* <:"&file" >>EOO - & - 'file' - EOO - - : maybe - : - $* <:"&?file" >>EOO - &? - 'file' - EOO - - : never - : - $* <:"&!file" >>EOO - &! - 'file' - EOO -} diff --git a/unit-tests/test/script/lexer/command-line.testscript b/unit-tests/test/script/lexer/command-line.testscript deleted file mode 100644 index 55344b3..0000000 --- a/unit-tests/test/script/lexer/command-line.testscript +++ /dev/null @@ -1,208 +0,0 @@ -# file : unit-tests/test/script/lexer/command-line.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -test.arguments = command-line - -: semi -{ - : immediate - : - $* <"cmd;" >>EOO - 'cmd' - ; - - EOO - - : separated - : - $* <"cmd ;" >>EOO - 'cmd' - ; - - EOO - - : only - : - $* <";" >>EOO - ; - - EOO -} - -: colon -: -{ - : immediate - : - $* <"cmd: dsc" >>EOO - 'cmd' - : - 'dsc' - - EOO - - : separated - : - $* <"cmd :dsc" >>EOO - 'cmd' - : - 'dsc' - - EOO - - : only - : - $* <":" >>EOO - : - - EOO -} - -: redirect -: -{ - : pass - : - $* <"cmd <| 1>|" >>EOO - 'cmd' - <| - '1' - >| - - EOO - - : null - : - $* <"cmd <- 1>-" >>EOO - 'cmd' - <- - '1' - >- - - EOO - - : trace - : - $* <"cmd 1>!" >>EOO - 'cmd' - '1' - >! - - EOO - - : merge - : - $* <"cmd 1>&2" >>EOO - 'cmd' - '1' - >& - '2' - - EOO - - : str - : - $* <"cmd b" >>EOO - 'cmd' - < - 'a' - '1' - > - 'b' - - EOO - - : str-nn - : - $* <"cmd <:a 1>:b" >>EOO - 'cmd' - <: - 'a' - '1' - >: - 'b' - - EOO - - : doc - : - $* <"cmd <>EOO" >>EOO - 'cmd' - << - 'EOI' - '1' - >> - 'EOO' - - EOO - - : doc-nn - : - $* <"cmd <<:EOI 1>>:EOO" >>EOO - 'cmd' - <<: - 'EOI' - '1' - >>: - 'EOO' - - EOO - - : file-cmp - : - $* <"cmd <<>>out 2>>>err" >>EOO - 'cmd' - <<< - 'in' - >>> - 'out' - '2' - >>> - 'err' - - EOO - - : file-write - : - $* <"cmd >=out 2>+err" >>EOO - 'cmd' - >= - 'out' - '2' - >+ - 'err' - - EOO -} - -: cleanup -: -{ - : always - : - $* <"cmd &file" >>EOO - 'cmd' - & - 'file' - - EOO - - : maybe - : - $* <"cmd &?file" >>EOO - 'cmd' - &? - 'file' - - EOO - - : never - : - $* <"cmd &!file" >>EOO - 'cmd' - &! - 'file' - - EOO -} diff --git a/unit-tests/test/script/lexer/description-line.testscript b/unit-tests/test/script/lexer/description-line.testscript deleted file mode 100644 index dc9fd9c..0000000 --- a/unit-tests/test/script/lexer/description-line.testscript +++ /dev/null @@ -1,33 +0,0 @@ -# file : unit-tests/test/script/lexer/description-line.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -test.arguments = description-line - -: full -: -$* <" foo bar " >>EOO -' foo bar ' - -EOO - -: space -: -$* <" " >>EOO -' ' - -EOO - -: empty -: -$* <"" >>EOO - -EOO - -: eof -: -$* <:"foo" >>EOO 2>>EOE != 0 -'foo' -EOO -stdin:1:4: error: expected newline at the end of description line -EOE diff --git a/unit-tests/test/script/lexer/driver.cxx b/unit-tests/test/script/lexer/driver.cxx deleted file mode 100644 index 14d142c..0000000 --- a/unit-tests/test/script/lexer/driver.cxx +++ /dev/null @@ -1,85 +0,0 @@ -// file : unit-tests/test/script/lexer/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include -#include - -#include -#include - -#include -#include - -using namespace std; - -namespace build2 -{ - namespace test - { - namespace script - { - // Usage: argv[0] - // - int - main (int argc, char* argv[]) - { - lexer_mode m; - { - assert (argc == 2); - string s (argv[1]); - - if (s == "command-line") m = lexer_mode::command_line; - else if (s == "first-token") m = lexer_mode::first_token; - else if (s == "second-token") m = lexer_mode::second_token; - else if (s == "variable-line") m = lexer_mode::variable_line; - else if (s == "command-expansion") m = lexer_mode::command_expansion; - else if (s == "here-line-single") m = lexer_mode::here_line_single; - else if (s == "here-line-double") m = lexer_mode::here_line_double; - else if (s == "description-line") m = lexer_mode::description_line; - else if (s == "variable") m = lexer_mode::variable; - else assert (false); - } - - try - { - cin.exceptions (istream::failbit | istream::badbit); - - // Some modes auto-expire so we need something underneath. - // - bool u (m == lexer_mode::first_token || - m == lexer_mode::second_token || - m == lexer_mode::variable_line || - m == lexer_mode::description_line || - m == lexer_mode::variable); - - lexer l (cin, path ("stdin"), u ? lexer_mode::command_line : m); - if (u) - l.mode (m); - - // No use printing eos since we will either get it or loop forever. - // - for (token t (l.next ()); t.type != token_type::eos; t = l.next ()) - { - // Print each token on a separate line without quoting operators. - // - t.printer (cout, t, false); - cout << endl; - } - } - catch (const failed&) - { - return 1; - } - - return 0; - } - } - } -} - -int -main (int argc, char* argv[]) -{ - return build2::test::script::main (argc, argv); -} diff --git a/unit-tests/test/script/lexer/first-token.testscript b/unit-tests/test/script/lexer/first-token.testscript deleted file mode 100644 index 45cb085..0000000 --- a/unit-tests/test/script/lexer/first-token.testscript +++ /dev/null @@ -1,97 +0,0 @@ -# file : unit-tests/test/script/lexer/first-token.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Note: this mode auto-expires after each token. -# -test.arguments = first-token - -: dot -: -$* <"." >>EOO -. - -EOO - -: semi -: -$* <";" >>EOO -; - -EOO - -: colon -: -$* <":" >>EOO -: - -EOO - -: lcbrace -: -$* <"{" >>EOO -{ - -EOO - -: rcbrace -: -$* <"}" >>EOO -} - -EOO - -: setup -: -$* <"+foo" >>EOO -+ -'foo' - -EOO - -: tdown -: -$* <"- foo" >>EOO -- -'foo' - -EOO - -: plus-leading -: -$* <"foo+bar" >>EOO -'foo+bar' - -EOO - -: minus-leading -: -$* <"foo- x" >>EOO -'foo-' -'x' - -EOO - -: assign -: -$* <"foo=" >>EOO -'foo' -'=' - -EOO - -: append -: -$* <"foo+=" >>EOO -'foo' -'+=' - -EOO - -: prepend -: -$* <"foo=+" >>EOO -'foo' -'=+' - -EOO diff --git a/unit-tests/test/script/lexer/second-token.testscript b/unit-tests/test/script/lexer/second-token.testscript deleted file mode 100644 index e6a72d3..0000000 --- a/unit-tests/test/script/lexer/second-token.testscript +++ /dev/null @@ -1,68 +0,0 @@ -# file : unit-tests/test/script/lexer/second-token.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Note: this mode auto-expires after each token. -# -test.arguments = second-token - -: semi -: -$* <";" >>EOO -; - -EOO - -: colon -: -$* <":" >>EOO -: - -EOO - -: assign -: -$* <"=foo" >>EOO -= -'foo' - -EOO - -: append -: -$* <"+= foo" >>EOO -+= -'foo' - -EOO - -: prepend -: -$* <" =+ foo" >>EOO -=+ -'foo' - -EOO - -: assign-leading -: -$* <"foo=bar" >>EOO -'foo=bar' - -EOO - -: append-leading -: -$* <"foo+= bar" >>EOO -'foo+=' -'bar' - -EOO - -: prepend-leading -: -$* <"foo =+bar" >>EOO -'foo' -'=+bar' - -EOO diff --git a/unit-tests/test/script/lexer/variable-line.testscript b/unit-tests/test/script/lexer/variable-line.testscript deleted file mode 100644 index ffbcefb..0000000 --- a/unit-tests/test/script/lexer/variable-line.testscript +++ /dev/null @@ -1,28 +0,0 @@ -# file : unit-tests/test/script/lexer/variable-line.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -test.arguments = variable-line - -: semi -: -$* <"cmd;" >>EOO -'cmd' -; - -EOO - -: semi-separated -: -$* <"cmd ;" >>EOO -'cmd' -; - -EOO - -: semi-only -: -$* <";" >>EOO -; - -EOO diff --git a/unit-tests/test/script/lexer/variable.testscript b/unit-tests/test/script/lexer/variable.testscript deleted file mode 100644 index 243a9c4..0000000 --- a/unit-tests/test/script/lexer/variable.testscript +++ /dev/null @@ -1,70 +0,0 @@ -# file : unit-tests/test/script/lexer/variable.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Test handling custom variable names ($*, $~, $NN). -# -test.arguments = variable - -: command -: -{ - : only - : - $* <"*" >>EOO - '*' - - EOO - - : followed - : - $* <"*abc" >>EOO - '*' - 'abc' - - EOO -} - -: working-dir -: -{ - : only - : - $* <"~" >>EOO - '~' - - EOO - - : followed - : - $* <"~123" >>EOO - '~' - '123' - - EOO -} - -: arg -: -{ - : only - : - $* <"0" >>EOO - '0' - - EOO - - : followed - : - $* <"1abc" >>EOO - '1' - 'abc' - - EOO - - : multi-digit - : - $* <"10" 2>>EOE != 0 - stdin:1:1: error: multi-digit special variable name - EOE -} diff --git a/unit-tests/test/script/parser/buildfile b/unit-tests/test/script/parser/buildfile deleted file mode 100644 index 952ec7a..0000000 --- a/unit-tests/test/script/parser/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/test/script/parser/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../../../build2/ -exe{driver}: {hxx cxx}{*} ../../../../build2/libue{b} testscript{*} diff --git a/unit-tests/test/script/parser/cleanup.testscript b/unit-tests/test/script/parser/cleanup.testscript deleted file mode 100644 index 962fea0..0000000 --- a/unit-tests/test/script/parser/cleanup.testscript +++ /dev/null @@ -1,58 +0,0 @@ -# file : unit-tests/test/script/parser/cleanup.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: always -: -$* <>EOO -cmd &file -EOI -cmd &file -EOO - -: maybe -: -$* <>EOO -cmd &?file -EOI -cmd &?file -EOO - -: never -: -$* <>EOO -cmd &!file -EOI -cmd &!file -EOO - -: empty -: -$* <>EOE != 0 -cmd &"" -EOI -testscript:1:6: error: empty cleanup path -EOE - -: missed-before -: -{ - : token - : - : Path missed before command next token - : - $* <>EOE != 0 - cmd & >file - EOI - testscript:1:7: error: missing cleanup path - EOE - - : end - : Test path missed before end of command - : - $* <>EOE != 0 - cmd & - EOI - testscript:1:6: error: missing cleanup path - EOE -} diff --git a/unit-tests/test/script/parser/command-if.testscript b/unit-tests/test/script/parser/command-if.testscript deleted file mode 100644 index 274e81e..0000000 --- a/unit-tests/test/script/parser/command-if.testscript +++ /dev/null @@ -1,548 +0,0 @@ -# file : unit-tests/test/script/parser/command-if.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: if -: -{ - : true - : - $* <>EOO - if true foo - cmd1 - cmd2 - end - EOI - ? true foo - cmd1 - cmd2 - EOO - - : false - : - $* <>EOO - if false foo - cmd1 - cmd2 - end - EOI - ? false foo - EOO - - : not-true - : - $* <>EOO - if! true foo - cmd1 - cmd2 - end - EOI - ? true foo - EOO - - : not-false - : - $* <>EOO - if! false foo - cmd1 - cmd2 - end - EOI - ? false foo - cmd1 - cmd2 - EOO - - : without-command - : - $* <>EOE != 0 - if - cmd - end - EOI - testscript:1:3: error: missing program - EOE - - : after-semi - : - $* -s <>EOO - cmd1; - if true - cmd2 - end - EOI - { - { - cmd1 - ? true - cmd2 - } - } - EOO - - : setup - : - $* -s <>EOO - +if true - cmd - end - EOI - { - ? true - +cmd - } - EOO - - : tdown - : - $* -s <>EOO - -if true - cmd - end - EOI - { - ? true - -cmd - } - EOO -} - -: elif -: -{ - : true - : - $* <>EOO - if false - cmd1 - cmd2 - elif true - cmd3 - cmd4 - end - EOI - ? false - ? true - cmd3 - cmd4 - EOO - - : false - : - $* <>EOO - if false - cmd1 - cmd2 - elif false - cmd3 - cmd4 - end - EOI - ? false - ? false - EOO - - : not-true - : - $* <>EOO - if false - cmd1 - cmd2 - elif! true - cmd3 - cmd4 - end - EOI - ? false - ? true - EOO - - : not-false - : - $* <>EOO - if false - cmd1 - cmd2 - elif! false - cmd3 - cmd4 - end - EOI - ? false - ? false - cmd3 - cmd4 - EOO - - : without-if - : - $* <>EOE != 0 - cmd - elif true - cmd - end - EOI - testscript:2:1: error: 'elif' without preceding 'if' - EOE - - : not-without-if - : - $* <>EOE != 0 - cmd - elif! true - cmd - end - EOI - testscript:2:1: error: 'elif!' without preceding 'if' - EOE - - : after-else - : - $* <>EOE != 0 - if false - cmd - else - cmd - elif true - cmd - end - EOI - testscript:5:1: error: 'elif' after 'else' - EOE -} - -: else -: -{ - : true - : - $* <>EOO - if false - cmd1 - cmd2 - else - cmd3 - cmd4 - end - EOI - ? false - cmd3 - cmd4 - EOO - - : false - : - $* <>EOO - if true - cmd1 - cmd2 - else - cmd3 - cmd4 - end - EOI - ? true - cmd1 - cmd2 - EOO - - : chain - : - $* <>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 - - : command-after - : - $* <>EOE != 0 - if true - cmd - else cmd - cmd - end - EOI - testscript:3:6: error: expected newline instead of 'cmd' - EOE - - : without-if - : - $* <>EOE != 0 - cmd - else - cmd - end - EOI - testscript:2:1: error: 'else' without preceding 'if' - EOE - - : after-else - : - $* <>EOE != 0 - if false - cmd - else - cmd - else - cmd - end - EOI - testscript:5:1: error: 'else' after 'else' - EOE -} - -: end -{ - : without-if - : - $* <>EOE != 0 - cmd - end - EOI - testscript:2:1: error: 'end' without preceding 'if' - EOE - - : before - { - : semi - : - $* -s <>EOO - if true - cmd1 - end; - cmd2 - EOI - { - { - ? true - cmd1 - cmd2 - } - } - EOO - - : command - : - $* <>EOE != 0 - if true - cmd - end cmd - EOI - testscript:3:5: error: expected newline instead of 'cmd' - EOE - - : colon - : - $* -s <>EOO - if true - cmd1 - cmd2 - end : test - EOI - { - : id:test - { - ? true - cmd1 - cmd2 - } - } - EOO - } -} - -: nested -: -{ - : take - : - $* <>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 - - : skip - : - $* <>EOO - if false - cmd1 - if false - cmd - elif false - if true - cmd - end - else - cmd2 - end - cmd3 - else - cmd - end - EOI - ? false - cmd - EOO -} - -: contained -{ - : semi - : - $* <>EOE != 0 - if - cmd; - cmd - end - EOI - testscript:2:3: error: ';' inside 'if' - EOE - - : colon-leading - : - $* <>EOE != 0 - if - : foo - cmd - end - EOI - testscript:2:3: error: description inside 'if' - EOE - - : colon-trailing - : - $* <>EOE != 0 - if - cmd : foo - end - EOI - testscript:2:3: error: description inside 'if' - EOE - - : eos - : - $* <>EOE != 0 - if - EOI - testscript:2:1: error: expected closing 'end' - EOE - - : scope - : - $* <>EOE != 0 - if - cmd - { - } - end - EOI - testscript:3:3: error: expected closing 'end' - EOE - - : setup - : - $* <>EOE != 0 - if - +cmd - end - EOI - testscript:2:3: error: setup command inside 'if' - EOE - - : tdown - : - $* <>EOE != 0 - if - -cmd - end - EOI - testscript:2:3: error: teardown command inside 'if' - EOE -} - -: line-index -: -$* -l <>EOO -if false - cmd - if true - cmd - end - cmd -elif false - cmd -else - cmd -end -EOI -? false # 1 -? false # 6 -cmd # 8 -EOO - -: var -: -$* <>EOO -if true - x = foo -else - x = bar -end; -cmd $x -EOI -? true -cmd foo -EOO - -: leading-and-trailing-description -: -$* <>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/command-re-parse.testscript b/unit-tests/test/script/parser/command-re-parse.testscript deleted file mode 100644 index 62a1c7b..0000000 --- a/unit-tests/test/script/parser/command-re-parse.testscript +++ /dev/null @@ -1,12 +0,0 @@ -# file : unit-tests/test/script/parser/command-re-parse.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: double-quote -: -$* <>EOO -x = cmd \">-\" "'<-'" -$x -EOI -cmd '>-' '<-' -EOO diff --git a/unit-tests/test/script/parser/description.testscript b/unit-tests/test/script/parser/description.testscript deleted file mode 100644 index 20e6ec0..0000000 --- a/unit-tests/test/script/parser/description.testscript +++ /dev/null @@ -1,486 +0,0 @@ -# file : unit-tests/test/script/parser/description.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: id -: -{ - : lead - : - $* <>EOO - : foo - cmd - EOI - : id:foo - cmd - EOO - - : trail - : - $* <>EOO - cmd : foo - EOI - : id:foo - cmd - EOO - - : dup - : Id uniqueness - : - { - : test - : - { - : test - : - $* <>EOE != 0 - : foo - cmd - : foo - cmd - EOI - testscript:3:1: error: duplicate id foo - testscript:1:1: info: previously used here - EOE - - : group - : - $* <>EOE != 0 - : foo - cmd - : foo - { - cmd - cmd - } - EOI - testscript:3:1: error: duplicate id foo - testscript:1:1: info: previously used here - EOE - - : derived - : - $* <>EOE != 0 - : 3 - cmd - cmd - EOI - testscript:3:1: error: duplicate id 3 - testscript:1:1: info: previously used here - EOE - } - - : group - : - { - : test - : - $* <>EOE != 0 - : foo - { - cmd - cmd - } - : foo - cmd - EOI - testscript:6:1: error: duplicate id foo - testscript:1:1: info: previously used here - EOE - - : group - : - $* <>EOE != 0 - : foo - { - cmd - cmd - } - : foo - { - cmd - cmd - } - EOI - testscript:6:1: error: duplicate id foo - testscript:1:1: info: previously used here - EOE - - : derived - : - $* <>EOE != 0 - : 3 - cmd - { - cmd - cmd - } - EOI - testscript:3:1: error: duplicate id 3 - testscript:1:1: info: previously used here - EOE - } - } -} - -: summary -{ - : lead - : - $* <>EOO - : foo bar - cmd - EOI - : sm:foo bar - cmd - EOO - - : trail - : - $* <>EOO - cmd: foo bar - EOI - : sm:foo bar - cmd - EOO - - : id - : - $* <>EOO - : foo-bar - : foo bar - cmd - EOI - : id:foo-bar - : sm:foo bar - cmd - EOO -} - -: details -{ - : id - : - $* <>EOO - : foo-bar - : - : foo bar - : bar baz - cmd - EOI - : id:foo-bar - : - : foo bar - : bar baz - cmd - EOO - - : summary - : - { - : only - : - $* <>EOO - : foo bar - : - : foo bar - : bar baz - cmd - EOI - : sm:foo bar - : - : foo bar - : bar baz - cmd - EOO - - : assumed - : - $* <>EOO - : foo bar - : bar baz - cmd - EOI - : foo bar - : bar baz - cmd - EOO - - : id - : - $* <>EOO - : foo-bar - : foo bar - : - : foo bar - : bar baz - cmd - EOI - : id:foo-bar - : sm:foo bar - : - : foo bar - : bar baz - cmd - EOO - - : id-assumed - : - $* <>EOO - : foo-bar - : bar baz - : baz fox - cmd - EOI - : foo-bar - : bar baz - : baz fox - cmd - EOO - } -} - -: legal -: -: Legal places for description. -: -{ - : var - : - $* <>EOO - : foo bar - x = y; - cmd $x - EOI - : sm:foo bar - cmd y - EOO -} - -: illegal -: -: Illegal places for description. -: -{ - : eof - : - $* <": foo" 2>>EOE != 0 - testscript:2:1: error: description before - EOE - - : rcbrace - : - $* <>EOE != 0 - { - cmd - : foo - } - EOI - testscript:4:1: error: description before '}' - EOE - - : setup - : - $* <>EOE != 0 - : foo - +cmd - EOI - testscript:2:1: error: description before setup command - EOE - - : tdown - : - $* <>EOE != 0 - : foo - -cmd - EOI - testscript:2:1: error: description before teardown command - EOE - - : var - : - $* <>EOE != 0 - : foo - x = y - EOI - testscript:2:1: error: description before setup/teardown variable - EOE - - : var-if - : - $* <>EOE != 0 - : foo - if true - x = y - end - EOI - testscript:2:1: error: description before/after setup/teardown variable-if - EOE - - : var-if-after - : - $* <>EOE != 0 - if true - x = y - end : foo - EOI - testscript:1:1: error: description before/after setup/teardown variable-if - EOE - - : test - : - $* <>EOE != 0 - cmd1; - : foo - cmd2 - EOI - testscript:2:1: error: description inside test - EOE -} - -: test-scope -: -: Interaction with test scope merging. -: -{ - : both - : - : No merge since both have description. - : - $* -s -i <>EOO - : foo - { - : bar - cmd - } - EOI - { - : id:foo - { # foo - : id:bar - { # foo/bar - cmd - } - } - } - EOO - - : test - : - : No merge since test has description. - : - $* -s -i <>EOO - { - : foo-bar - : foo bar - cmd - } - EOI - { - { # 1 - : id:foo-bar - : sm:foo bar - { # 1/foo-bar - cmd - } - } - } - EOO - - : group - : - $* -s -i <>EOO - : foo-bar - : foo bar - { - cmd - } - EOI - { - : id:foo-bar - : sm:foo bar - { # foo-bar - cmd - } - } - EOO -} - -: blanks -: -$* <>EOO -: -: -: foo bar -: bar baz -: -: baz fox -: -: -cmd -EOI -: foo bar -: bar baz -: -: baz fox -cmd -EOO - -: strip -: -$* <>EOO -: foo-bar -: bar baz -: -: baz fox -: fox biz -:biz buz -: -cmd -EOI -: id:foo-bar -: sm:bar baz -: -: baz fox -: fox biz -: biz buz -cmd -EOO - -: trail-compound -: -$* <>EOO -cmd1; -cmd2: foo -EOI -: id:foo -cmd1 -cmd2 -EOO - -: empty -: -$* <>EOE != 0 -: -: -cmd -EOI -testscript:1:1: error: empty description -EOE - -: trail-empty -: -$* <>EOE != 0 -cmd: -EOI -testscript:1:4: error: empty description -EOE - -: both -: -$* <>EOE != 0 -: foo -cmd : bar -EOI -testscript:2:1: error: both leading and trailing descriptions -EOE diff --git a/unit-tests/test/script/parser/directive.testscript b/unit-tests/test/script/parser/directive.testscript deleted file mode 100644 index 0fc0b7a..0000000 --- a/unit-tests/test/script/parser/directive.testscript +++ /dev/null @@ -1,74 +0,0 @@ -# file : unit-tests/test/script/parser/directive.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: not-directive -: -$* <>EOO -x = x -".include" foo.testscript -\.include foo.testscript -EOI -.include foo.testscript -.include foo.testscript -EOO - -: expected-name -: -$* <>EOE != 0 -.$ -EOI -testscript:1:2: error: expected directive name instead of '$' -EOE - -: unknown-name -: -$* <>EOE != 0 -.bogus -EOI -testscript:1:2: error: unknown directive 'bogus' -EOE - -: separated -: -touch foo.testscript; -$* <="foo-$(build.verson.project).testscript"; -cmd -EOI -$* <>EOO -.include "foo-$(build.verson.project).testscript" -EOI -cmd -EOO - -: after-semi -: -$* <>EOE != 0 -cmd; -.include foo.testscript -EOI -testscript:2:1: error: directive after ';' -EOE - -: semi-after -: -$* <>EOE != 0 -.include foo.testscript; -cmd -EOI -testscript:1:24: error: ';' after directive -EOE diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx deleted file mode 100644 index d17c76b..0000000 --- a/unit-tests/test/script/parser/driver.cxx +++ /dev/null @@ -1,242 +0,0 @@ -// file : unit-tests/test/script/parser/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include -#include - -#include -#include - -#include -#include // reset() -#include - -#include - -#include -#include -#include - -using namespace std; - -namespace build2 -{ - namespace test - { - namespace script - { - // Here we assume we are running serially. - // - class print_runner: public runner - { - public: - print_runner (bool scope, bool id, bool line) - : scope_ (scope), id_ (id), line_ (line) {} - - virtual bool - test (scope&) const override - { - return true; - } - - virtual void - enter (scope& s, const location&) override - { - if (s.desc) - { - const auto& d (*s.desc); - - if (!d.id.empty ()) - cout << ind_ << ": id:" << d.id << endl; - - if (!d.summary.empty ()) - cout << ind_ << ": sm:" << d.summary << endl; - - if (!d.details.empty ()) - { - if (!d.id.empty () || !d.summary.empty ()) - cout << ind_ << ":" << endl; // Blank. - - const auto& s (d.details); - for (size_t b (0), e (0), n; e != string::npos; b = e + 1) - { - e = s.find ('\n', b); - n = ((e != string::npos ? e : s.size ()) - b); - - cout << ind_ << ':'; - if (n != 0) - { - cout << ' '; - cout.write (s.c_str () + b, static_cast (n)); - } - cout << endl; - } - } - } - - if (scope_) - { - cout << ind_ << "{"; - - if (id_ && !s.id_path.empty ()) // Skip empty root scope id. - cout << " # " << s.id_path.string (); - - cout << endl; - - ind_ += " "; - } - } - - virtual void - run (scope&, - const command_expr& e, command_type t, - size_t i, - const location&) override - { - const char* s (nullptr); - - switch (t) - { - case command_type::test: s = ""; break; - case command_type::setup: s = "+"; break; - case command_type::teardown: s = "-"; break; - } - - cout << ind_ << s << 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 - leave (scope&, const location&) override - { - if (scope_) - { - ind_.resize (ind_.size () - 2); - cout << ind_ << "}" << endl; - } - } - - private: - bool scope_; - bool id_; - bool line_; - string ind_; - }; - - // Usage: argv[0] [-s] [-i] [-l] [] - // - int - main (int argc, char* argv[]) - { - tracer trace ("main"); - - init (argv[0], 1); // Fake build system driver, default verbosity. - sched.startup (1); // Serial execution. - reset (strings ()); // No command line variables. - - bool scope (false); - bool id (false); - bool line (false); - path name; - - for (int i (1); i != argc; ++i) - { - string a (argv[i]); - - if (a == "-s") - scope = true; - else if (a == "-i") - id = true; - else if (a == "-l") - line = true; - else - { - name = path (move (a)); - break; - } - } - - if (name.empty ()) - name = path ("testscript"); - - assert (!id || scope); // Id can only be printed with scope. - - try - { - 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", - string (), - trace)); - - value& v ( - tt.assign ( - var_pool.rw ().insert ( - "test.target", variable_visibility::project))); - - v = cast ((*global_scope)["build.host"]); - - testscript& st ( - targets.insert (work, - dir_path (), - name.leaf ().base ().string (), - name.leaf ().extension (), - trace)); - - tt.path (path ("driver")); - st.path (name); - - // Parse and run. - // - parser p; - script s (tt, st, dir_path (work) /= "test-driver"); - p.pre_parse (cin, s); - - print_runner r (scope, id, line); - p.execute (s, r); - } - catch (const failed&) - { - return 1; - } - - return 0; - } - } - } -} - -int -main (int argc, char* argv[]) -{ - return build2::test::script::main (argc, argv); -} diff --git a/unit-tests/test/script/parser/exit.testscript b/unit-tests/test/script/parser/exit.testscript deleted file mode 100644 index 75867d6..0000000 --- a/unit-tests/test/script/parser/exit.testscript +++ /dev/null @@ -1,27 +0,0 @@ -# file : unit-tests/test/script/parser/exit.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: eq -: -$* <>EOO -cmd == 1 -EOI -cmd == 1 -EOO - -: ne -: -$* <>EOO -cmd!=1 -EOI -cmd != 1 -EOO - -: end -: -$* <>EOE != 0 -cmd != 1 <"foo" -EOI -testscript:1:10: error: unexpected '<' after command exit status -EOE diff --git a/unit-tests/test/script/parser/expansion.testscript b/unit-tests/test/script/parser/expansion.testscript deleted file mode 100644 index ea952af..0000000 --- a/unit-tests/test/script/parser/expansion.testscript +++ /dev/null @@ -1,36 +0,0 @@ -# file : unit-tests/test/script/parser/expansion.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: quote -: -: Make sure everything expanded as strings. -: -$* <>EOO -x = dir/ proj% proj%name proj%proj%dir/type{name name {name}} -cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} -cmd $x -EOI -cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} -cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} -EOO - -: unterm-quoted-seq -: -$* <>EOE != 0 -x = "'a bc" -cmd xy$x -EOI -:1:8: error: unterminated single-quoted sequence - testscript:2:5: info: while parsing string 'xy'a bc' -EOE - -: invalid-redirect -: -$* <>EOE != 0 -x = "1>&a" -cmd $x -EOI -:1:4: error: stdout merge redirect file descriptor must be 2 - testscript:2:5: info: while parsing string '1>&a' -EOE diff --git a/unit-tests/test/script/parser/here-document.testscript b/unit-tests/test/script/parser/here-document.testscript deleted file mode 100644 index de6255e..0000000 --- a/unit-tests/test/script/parser/here-document.testscript +++ /dev/null @@ -1,213 +0,0 @@ -# file : unit-tests/test/script/parser/here-document.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: end-marker -: -{ - : missing-newline - : - $* <'cmd <<' 2>>EOE != 0 - testscript:1:7: error: expected here-document end marker - EOE - - : missing-exit - : - $* <'cmd << != 0' 2>>EOE != 0 - testscript:1:8: error: expected here-document end marker - EOE - - : missing-empty - : - $* <'cmd <<""' 2>>EOE != 0 - testscript:1:7: error: expected here-document end marker - EOE - - : unseparated-expansion - : - $* <'cmd <>EOE != 0 - testscript:1:10: error: here-document end marker must be literal - EOE - - : quoted-single-partial - : - $* <"cmd <>EOE != 0 - testscript:1:7: error: partially-quoted here-document end marker - EOE - - : quoted-double-partial - : - $* <'cmd <<"FO"O' 2>>EOE != 0 - testscript:1:7: error: partially-quoted here-document end marker - EOE - - : quoted-mixed - : - $* <"cmd <<\"FO\"'O'" 2>>EOE != 0 - testscript:1:7: error: partially-quoted here-document end marker - EOE - - : unseparated - : - $* <>EOO - cmd <>EOO - cmd <<'EOF' - foo - EOF - EOI - cmd <>EOO - cmd <<"EOF" - foo - EOF - EOI - cmd <>EOO - cmd <>EOO - cmd <>EOO - cmd <>EOO - x = foo bar - cmd <<"EOF" - $x - EOF - EOI - cmd <>EOO - x = foo - cmd <<"EOF" - $x bar $x - EOF - EOI - cmd <>EOE != 0 - cmd <>EOO -cmd <>EOO -cmd <<"EOF" -'single' -"double" -b'o't"h" -('single' "double") -EOF -EOI -cmd <>EOO -cmd <"" -EOI -cmd <'' -EOO - -: empty-nn -: -$* <>EOO -cmd <:"" -EOI -cmd <:'' -EOO diff --git a/unit-tests/test/script/parser/include.testscript b/unit-tests/test/script/parser/include.testscript deleted file mode 100644 index c5241a1..0000000 --- a/unit-tests/test/script/parser/include.testscript +++ /dev/null @@ -1,104 +0,0 @@ -# file : unit-tests/test/script/parser/include.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: none -: -$* <=foo.testscript; -$* <>EOO -.include foo.testscript -EOI -cmd -EOO - -: multiple -: -cat <"cmd foo" >=foo.testscript; -cat <"cmd bar" >=bar.testscript; -$* <>EOO -.include foo.testscript bar.testscript -EOI -cmd foo -cmd bar -EOO - -: once -: -cat <"cmd" >=foo.testscript; -$* <>EOO -.include foo.testscript -x -.include --once foo.testscript -.include --once bar/../foo.testscript -y -.include ../once/foo.testscript -EOI -cmd -x -y -cmd -EOO - -: group-id -: -cat <=foo.testscript; -{ - x = b -} -EOI -$* -s -i <>EOO -x = a -.include foo.testscript -EOI -{ - { # 2-foo-1 - } -} -EOO - -: test-id -: -cat <=foo.testscript; -cmd -EOI -$* -s -i <>EOO -x = a -.include foo.testscript -EOI -{ - { # 2-foo-1 - cmd - } -} -EOO - -: invalid-path -: -$* <>EOE != 0 -.include "" -EOI -testscript:1:2: error: invalid testscript include path '' -EOE - -: unable-open -: -$* <>~/EOE/ != 0 -.include foo.testscript -EOI -/testscript:1:2: error: unable to read testscript foo.testscript: .+/ -EOE diff --git a/unit-tests/test/script/parser/pipe-expr.testscript b/unit-tests/test/script/parser/pipe-expr.testscript deleted file mode 100644 index a66a4ac..0000000 --- a/unit-tests/test/script/parser/pipe-expr.testscript +++ /dev/null @@ -1,133 +0,0 @@ -# file : unit-tests/test/script/parser/pipe-expr.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: pipe -: -$* <>EOO -cmd1 | cmd2|cmd3 -EOI -cmd1 | cmd2 | cmd3 -EOO - -: log -: -$* <>EOO -cmd1 || cmd2&&cmd3 -EOI -cmd1 || cmd2 && cmd3 -EOO - -: pipe-log -: -$* <>EOO -cmd1 | cmd2 && cmd3 | cmd4 -EOI -cmd1 | cmd2 && cmd3 | cmd4 -EOO - -: exit -: -$* <>EOO -cmd1|cmd2==1&&cmd3!=0|cmd4 -EOI -cmd1 | cmd2 == 1 && cmd3 != 0 | cmd4 -EOO - -: here-doc -: -$* <>EOO -cmd1 <>EOO2 && cmd3 <&1 | cmd4 2>>EOE4 >>EOO4 -input -one -EOI1 -ouput -two -EOO2 -input -three -EOI3 -error -four -EOE4 -output -four -EOO4 -EOI -cmd1 <>EOO2 && cmd3 <&1 | cmd4 >>EOO4 2>>EOE4 -input -one -EOI1 -ouput -two -EOO2 -input -three -EOI3 -output -four -EOO4 -error -four -EOE4 -EOO - -: leading -: -$* <>EOE != 0 -| cmd -EOI -testscript:1:1: error: missing program -EOE - -: trailing -: -$* <>EOE != 0 -cmd && -EOI -testscript:1:7: error: missing program -EOE - -: redirected -: -{ - : input - : - { - : first - : - $* <>EOO - cmd1 >EOE != 0 - cmd1 | cmd2 >EOO - cmd1 | cmd2 >foo - EOI - cmd1 | cmd2 >foo - EOO - - : non-last - : - $* <>EOE != 0 - cmd1 >foo | cmd2 - EOI - testscript:1:11: error: stdout is both redirected and piped - EOE - } -} diff --git a/unit-tests/test/script/parser/pre-parse.testscript b/unit-tests/test/script/parser/pre-parse.testscript deleted file mode 100644 index 1afd566..0000000 --- a/unit-tests/test/script/parser/pre-parse.testscript +++ /dev/null @@ -1,23 +0,0 @@ -# file : unit-tests/test/script/parser/pre-parse.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: attribute -: -{ - : pair - : - $* <>EOE != 0 - x = [foo=bar] - EOI - testscript:1:5: error: unknown value attribute foo=bar - EOE - - : pair-empty - : - $* <>EOE != 0 - x = [foo=] - EOI - testscript:1:5: error: unknown value attribute foo - EOE -} diff --git a/unit-tests/test/script/parser/redirect.testscript b/unit-tests/test/script/parser/redirect.testscript deleted file mode 100644 index 09074cd..0000000 --- a/unit-tests/test/script/parser/redirect.testscript +++ /dev/null @@ -1,356 +0,0 @@ -# file : unit-tests/test/script/parser/redirect.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# @@ Add tests for redirects other than trace, here-*, file and merge. -# @@ Does it make sense to split into separate files - one per redirect type? -# - -: trace -: -{ - $* <'cmd >!' >'cmd >!' : out - $* <'cmd 2>!' >'cmd 2>!' : err -} - -: str -: -{ - : literal - : - { - : portable-path - : - $* <>EOO - cmd /bar 2>/baz - EOI - cmd /bar 2>/baz - EOO - } - - : regex - : - { - : portable-path - : - $* <>EOO - cmd >/~%foo% 2>/~%bar% - EOI - cmd >/~%foo% 2>/~%bar% - EOO - } -} - -: doc -: -{ - : literal - : - { - : portable-path - : - $* <>EOO - cmd </EOO_ 2>/EOE_ - foo - EOI_ - bar - EOO_ - baz - EOE_ - EOI - cmd </EOO_ 2>/EOE_ - foo - EOI_ - bar - EOO_ - baz - EOE_ - EOO - - : sharing - : - { - : in-out - : - $* <>EOO - cmd <<:/EOF >>:/EOF - foo - EOF - EOI - cmd <<:/EOF >>:/EOF - foo - EOF - EOO - - : different - : - { - : modifiers - : - $* <>EOE != 0 - cmd <<:/EOF >>:EOF - foo - EOF - EOI - testscript:1:16: error: different modifiers for shared here-document 'EOF' - EOE - - : quoting - : - $* <>EOE != 0 - cmd <>"EOF" - foo - EOF - EOI - testscript:1:13: error: different quoting for shared here-document 'EOF' - EOE - } - } - } - - : regex - : - { - : portable-path - : - $* <>EOO - cmd >/~%EOF% 2>/~%EOE% - foo - EOF - bar - EOE - EOI - cmd >/~%EOF% 2>/~%EOE% - foo - EOF - bar - EOE - EOO - - : sharing - : - { - : in-out - : - $* <>EOO - cmd >>~/EOF/ 2>>~/EOF/ - foo - EOF - EOI - cmd >>~/EOF/ 2>>~/EOF/ - foo - EOF - EOO - - : different - : - { - : introducers - : - $* <>EOE != 0 - cmd >>~/EOF/ 2>>~%EOF% - foo - EOF - EOI - testscript:1:18: error: different introducers for shared here-document regex 'EOF' - EOE - - : flags - : - $* <>EOE != 0 - cmd >>~/EOF/ 2>>~/EOF/i - foo - EOF - EOI - testscript:1:18: error: different global flags for shared here-document regex 'EOF' - EOE - } - } - } -} - -: file -: -{ - : cmp - : - $* <>EOO - cmd 0<<>>b 2>>>c - EOI - cmd <<>>b 2>>>c - EOO - - : write - : - $* <>EOO - cmd 1>=b 2>+c - EOI - cmd >=b 2>+c - EOO - - : quote - : - $* <>EOO - cmd 0<<<"a f" 1>="b f" 2>+"c f" - EOI - cmd <<<'a f' >='b f' 2>+'c f' - EOO - - : in - : - { - : missed - : - $* <>EOE !=0 - cmd <<< - EOI - testscript:1:8: error: missing stdin file - EOE - - : empty - : - $* <>EOE !=0 - cmd <<<"" - EOI - testscript:1:8: error: empty stdin redirect path - EOE - } - - : out - : - { - : missed - : - $* <>EOE !=0 - cmd >= - EOI - testscript:1:7: error: missing stdout file - EOE - - : empty - : - $* <>EOE !=0 - cmd >="" - EOI - testscript:1:7: error: empty stdout redirect path - EOE - } - - : err - : - { - : missed - : - $* <>EOE !=0 - cmd 2>= - EOI - testscript:1:8: error: missing stderr file - EOE - - : empty - : - $* <>EOE !=0 - cmd 2>="" - EOI - testscript:1:8: error: empty stderr redirect path - EOE - } -} - -: merge -{ - : out - : - { - : err - : - $* <>EOO - cmd 1>&2 - EOI - cmd >&2 - EOO - - : no-mutual - : - $* <>EOO - cmd 1>&2 2>&1 2>a - EOI - cmd >&2 2>a - EOO - - : not-descriptor - : - $* <>EOE != 0 - cmd 1>&a - EOI - testscript:1:8: error: stdout merge redirect file descriptor must be 2 - EOE - - : self - : - $* <>EOE != 0 - cmd 1>&1 - EOI - testscript:1:8: error: stdout merge redirect file descriptor must be 2 - EOE - - : missed - : - $* <>EOE != 0 - cmd 1>& - EOI - testscript:1:8: error: missing stdout file descriptor - EOE - } - - : err - { - : out - : - $* <>EOO - cmd 2>&1 - EOI - cmd 2>&1 - EOO - - : no-mutual - : - $* <>EOO - cmd 1>&2 2>&1 >a - EOI - cmd >a 2>&1 - EOO - - : not-descriptor - : - $* <>EOE != 0 - cmd 2>&a - EOI - testscript:1:8: error: stderr merge redirect file descriptor must be 1 - EOE - - : self - : - $* <>EOE != 0 - cmd 2>&2 - EOI - testscript:1:8: error: stderr merge redirect file descriptor must be 1 - EOE - - : missed - : - $* <>EOE != 0 - cmd 2>& - EOI - testscript:1:8: error: missing stderr file descriptor - EOE - } - - : mutual - : - $* <>EOE != 0 - cmd 1>&2 2>&1 - EOI - testscript:1:14: error: stdout and stderr redirected to each other - EOE -} diff --git a/unit-tests/test/script/parser/regex.testscript b/unit-tests/test/script/parser/regex.testscript deleted file mode 100644 index 216c0c4..0000000 --- a/unit-tests/test/script/parser/regex.testscript +++ /dev/null @@ -1,223 +0,0 @@ -# file : unit-tests/test/script/parser/regex.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: here-string -: -{ - : stdout - : - { - : missed - : - $* <'cmd >~' 2>>EOE != 0 - testscript:1:7: error: missing stdout here-string regex - EOE - - : no-introducer - : - $* <'cmd >~""' 2>>EOE != 0 - testscript:1:7: error: no introducer character in stdout regex redirect - EOE - - : no-term-introducer - : - $* <'cmd >~/' 2>>EOE != 0 - testscript:1:7: error: no closing introducer character in stdout regex redirect - EOE - - : portable-path-introducer - : - $* <'cmd >/~/foo/' 2>>EOE != 0 - testscript:1:8: error: portable path modifier and '/' introducer in stdout regex redirect - EOE - - : empty - : - $* <'cmd >~//' 2>>EOE != 0 - testscript:1:7: error: stdout regex redirect is empty - EOE - - : no-flags - : - $* <'cmd >~/fo*/' >'cmd >~/fo*/' - - : idot - : - $* <'cmd >~/fo*/d' >'cmd >~/fo*/d' - - : icase - : - $* <'cmd >~/fo*/i' >'cmd >~/fo*/i' - - : invalid-flags1 - : - $* <'cmd >~/foo/z' 2>>EOE != 0 - testscript:1:7: error: junk at the end of stdout regex redirect - EOE - - : invalid-flags2 - : - $* <'cmd >~/foo/iz' 2>>EOE != 0 - testscript:1:7: error: junk at the end of stdout regex redirect - EOE - - : no-newline - : - $* <'cmd >:~/fo*/' >'cmd >:~/fo*/' - } - - : stderr - : - { - : missed - : - $* <'cmd 2>~' 2>>EOE != 0 - testscript:1:8: error: missing stderr here-string regex - EOE - - : no-introducer - : - : Note that there is no need to reproduce all the errors as for stdout. - : All we need is to make sure that the proper description is passed to - : the parse_regex() function. - : - $* <'cmd 2>~""' 2>>EOE != 0 - testscript:1:8: error: no introducer character in stderr regex redirect - EOE - } - - : modifier-last - : - $* <'cmd >~/x' 2>>EOE != 0 - testscript:1:7: error: no closing introducer character in stdout regex redirect - EOE -} - -: here-doc -: -{ - : stdout - : - { - : missed - : - $* <'cmd >>~' 2>>EOE != 0 - testscript:1:8: error: expected here-document regex end marker - EOE - - : portable-path-introducer - : - $* <>EOE != 0 - cmd >>/~/EOO/ - foo - EOO - EOI - testscript:1:5: error: portable path modifier and '/' introducer in here-document regex end marker - EOE - - : unterminated-line-char - : - $* <>EOE != 0 - cmd >>~/EOO/ - / - EOO - EOI - testscript:2:1: error: no syntax line characters - EOE - - : empty - : - $* <>EOE != 0 - cmd >>:~/EOO/ - EOO - EOI - testscript:2:1: error: empty here-document regex - EOE - - : no-flags - : - $* <>EOO - cmd 2>>~/EOE/ - foo - /? - /foo/ - /foo/* - /foo/i - /foo/i* - - // - //* - EOE - EOI - cmd 2>>~/EOE/ - foo - /? - /foo/ - /foo/* - /foo/i - /foo/i* - - // - //* - EOE - EOO - - : no-newline - : - $* <'cmd >:~/fo*/' >'cmd >:~/fo*/' - $* <>EOO - cmd 2>>:~/EOE/ - foo - EOE - EOI - cmd 2>>:~/EOE/ - foo - EOE - EOO - - : end-marker-restore - : - { - : idot - : - $* <>EOO - cmd 2>>~/EOE/d - foo - EOE - EOI - cmd 2>>~/EOE/d - foo - EOE - EOO - - : icase - : - $* <>EOO - cmd 2>>~/EOE/i - foo - EOE - EOI - cmd 2>>~/EOE/i - foo - EOE - EOO - } - } - - : stderr - : - { - : missed - : - $* <'cmd 2>>~' 2>>EOE != 0 - testscript:1:9: error: expected here-document regex end marker - EOE - } - - : modifier-last - : - $* <'cmd >>~:/FOO/' 2>>EOE != 0 - testscript:1:8: error: expected here-document regex end marker - EOE -} diff --git a/unit-tests/test/script/parser/scope-if.testscript b/unit-tests/test/script/parser/scope-if.testscript deleted file mode 100644 index 461d902..0000000 --- a/unit-tests/test/script/parser/scope-if.testscript +++ /dev/null @@ -1,554 +0,0 @@ -# file : unit-tests/test/script/parser/scope-if.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: if -: -{ - : true - : - $* -s <>EOO - if true foo - { - cmd - } - EOI - { - ? true foo - { - cmd - } - } - EOO - - : false - : - $* -s <>EOO - if false foo - { - cmd - } - EOI - { - ? false foo - } - EOO - - : not-true - : - $* -s <>EOO - if! true - { - cmd - } - EOI - { - ? true - } - EOO - - : not-false - : - $* -s <>EOO - if! false - { - cmd - } - EOI - { - ? false - { - cmd - } - } - EOO - - : eos-inside - : - $* <>EOE != 0 - if - { - EOI - testscript:3:1: error: expected '}' at the end of the scope - EOE - -} - -: elif -: -{ - : true - : - $* -s <>EOO - if false - { - cmd - } - elif true - { - cmd1 - } - EOI - { - ? false - ? true - { - cmd1 - } - } - EOO - - : false - : - $* -s <>EOO - if false - { - cmd - } - elif false - { - cmd - } - EOI - { - ? false - ? false - } - EOO - - : not-false - : - $* -s <>EOO - if false - { - cmd - } - elif! false - { - cmd1 - } - EOI - { - ? false - ? false - { - cmd1 - } - } - EOO - - : not-true - : - $* -s <>EOO - if false - { - cmd - } - elif! true - { - cmd - } - EOI - { - ? false - ? true - } - EOO - - : after-else - : - $* <>EOE != 0 - if false - { - cmd - } - else - { - cmd - } - elif true - { - cmd - } - EOI - testscript:9:1: error: 'elif' after 'else' - EOE -} - -: else -: -{ - : true - : - $* -s <>EOO - if false - { - cmd - } - else - { - cmd1 - } - EOI - { - ? false - { - cmd1 - } - } - EOO - - : false - : - $* -s <>EOO - if true - { - cmd1 - } - else - { - cmd - } - EOI - { - ? true - { - cmd1 - } - } - EOO - - : chain - : - $* -s <>EOO - if false - { - cmd - } - elif false - { - cmd - cmd - } - elif false - { - cmd - } - elif true - { - cmd1 - cmd2 - } - elif false - { - cmd - } - else - { - cmd - cmd - } - EOI - { - ? false - ? false - ? false - ? true - { - { - cmd1 - } - { - cmd2 - } - } - } - EOO - - : scope-expected - : - $* <>EOE != 0 - if - { - cmd - } - else - cmd - EOI - testscript:5:1: error: expected scope after 'else' - EOE - - : after-else - : - $* <>EOE != 0 - if false - { - cmd - } - else - { - cmd - } - else - { - cmd - } - EOI - testscript:9:1: error: 'else' after 'else' - EOE -} - -: nested -: -{ - : take - : - $* -s <>EOO - if true - { - cmd1 - if false - { - cmd - } - elif false - { - if true - { - cmd - } - } - else - { - cmd2 - } - cmd3 - } - EOI - { - ? true - { - { - cmd1 - } - ? false - ? false - { - { - cmd2 - } - } - { - cmd3 - } - } - } - EOO - - : skip - : - $* -s <>EOO - if false - { - cmd1 - if false - { - cmd - } - elif false - { - if true - { - cmd - } - } - else - { - cmd2 - } - cmd3 - } - else - { - cmd - } - EOI - { - ? false - { - { - cmd - } - } - } - EOO -} - -: demote -: -{ - : group - : Chain remains a group - : - $* -s <>EOO - if false - { - cmd - } - elif true - { - cmd1 - cmd2 - } - else - { - cmd - } - EOI - { - ? false - ? true - { - { - cmd1 - } - { - cmd2 - } - } - } - EOO - - : test - : Chain demoted to test - : - $* -s <>EOO - if false - { - cmd - } - elif true - { - cmd1 - } - else - { - cmd - } - EOI - { - ? false - ? true - { - cmd1 - } - } - EOO -} - -: line-index -: Make sure command line index spans setup/if/teardown -: -$* -s -l <>EOO -+setup # 1 - -if false one # 2 -{ - cmd -} -elif false two # 3 -{ - cmd -} -elif true # 4 -{ - cmd1 -} -elif false # 5 -{ - cmd -} -else -{ - cmd -} - -if false one # 6 -{ - cmd -} -elif false two # 7 -{ - cmd -} -else -{ - cmd2 -} - --tdown # 8 -EOI -{ - +setup # 1 - ? false one # 2 - ? false two # 3 - ? true # 4 - { - cmd1 # 0 - } - ? false one # 6 - ? false two # 7 - { - cmd2 # 0 - } - -tdown # 8 -} -EOO - -: scope-comman-if -: -$* -s <>EOO -if true -{ - cmd -} -if true - cmd1 - cmd2 -end -EOI -{ - ? true - { - cmd - } - { - ? true - cmd1 - cmd2 - } -} -EOO - -: shared-id-desc -: -$* -s -i <>EOO -: test summary -: -if false -{ - cmd -} -else -{ - cmd1 -} -EOI -{ - ? false - : sm:test summary - { # 3 - cmd1 - } -} -EOO diff --git a/unit-tests/test/script/parser/scope.testscript b/unit-tests/test/script/parser/scope.testscript deleted file mode 100644 index cc254e9..0000000 --- a/unit-tests/test/script/parser/scope.testscript +++ /dev/null @@ -1,280 +0,0 @@ -# file : unit-tests/test/script/parser/scope.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -$* testscript <'cmd $@' >"cmd 1" : id-testscript -$* foo.testscript <'cmd $@' >"cmd foo/1" : id - -: wd-testscript -: -$* testscript <'cmd "$~"' >~"%cmd '?.+[/\\\\]test-driver[/\\\\]1'?%" - -: wd -: -$* foo.testscript <'cmd "$~"' >~"%cmd '?.+[/\\\\]test-driver[/\\\\]foo[/\\\\]1'?%" - -: group -: -{ - : empty - : - $* -s <>EOO - { - cmd1 - cmd2 - } - EOI - { - { - { - cmd1 - } - { - cmd2 - } - } - } - EOO -} - -: test -: -{ - : explicit - : - { - : one-level - : - $* -s -i <>EOO - { - cmd - } - EOI - { - { # 1 - cmd - } - } - EOO - - : nested - : - $* -s -i <>EOO - { - { - cmd - } - } - EOI - { - { # 1 - cmd - } - } - EOO - - : var - : - $* -s -i <>EOO - { - x = abc - cmd $x - } - EOI - { - { # 1 - cmd abc - } - } - EOO - - : setup - : - $* -s -i <>EOO - { - x = abc - +setup - cmd $x - } - EOI - { - { # 1 - +setup - { # 1/4 - cmd abc - } - } - } - EOO - } - - : implicit - { - : one-cmd - : - $* -s <>EOO - cmd1 - EOI - { - { - cmd1 - } - } - EOO - - : two-cmd - : - $* -s <>EOO - cmd1; - cmd2 - EOI - { - { - cmd1 - cmd2 - } - } - EOO - - : three-cmd - : - $* -s <>EOO - cmd1; - cmd2; - cmd3 - EOI - { - { - cmd1 - cmd2 - cmd3 - } - } - EOO - - : var - : - $* -s <>EOO - cmd1; - x = abc; - cmd2 $x - EOI - { - { - cmd1 - cmd2 abc - } - } - EOO - - : var-first - : - $* -s <>EOO - x = abc; - cmd $x - EOI - { - { - cmd abc - } - } - EOO - - : var-setup-tdown - : - $* -s <>EOO - x = abc - cmd $x - y = 123 - EOI - { - { - cmd abc - } - } - EOO - - : after-tdown - : - $* <>EOE != 0 - cmd1 - x = abc - cmd2 - EOI - testscript:3:1: error: test after teardown - testscript:2:1: info: last teardown line appears here - EOE - } -} - -: expected -{ - : newline-lcbrace - : - $* <:"{x" 2>>EOE != 0 - testscript:1:2: error: expected newline after '{' - EOE - - : rcbrace - : - $* <"{" 2>>EOE != 0 - testscript:2:1: error: expected '}' at the end of the scope - EOE - - : line-rcbrace - : - $* <>EOE != 0 - { - cmd; - } - EOI - testscript:3:1: error: expected another line after ';' - EOE - - : newline-rcbrace - : - $* <<:EOI 2>>EOE != 0 - { - } - EOI - testscript:2:2: error: expected newline after '}' - EOE - - : line-eof - : - $* <>EOE != 0 - cmd; - EOI - testscript:2:1: error: expected another line after ';' - EOE - - : newline-cmd - : - $* <<:EOI 2>>EOE != 0 - cmd; - EOI - testscript:1:5: error: expected newline instead of - EOE - - : newline-var - : - $* <:"x = abc;" 2>>EOE != 0 - testscript:1:9: error: expected newline instead of - EOE -} diff --git a/unit-tests/test/script/parser/setup-teardown.testscript b/unit-tests/test/script/parser/setup-teardown.testscript deleted file mode 100644 index 0342e73..0000000 --- a/unit-tests/test/script/parser/setup-teardown.testscript +++ /dev/null @@ -1,151 +0,0 @@ -# file : unit-tests/test/script/parser/setup-teardown.testscript -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -: setup -: -{ - : followed - : - { - : semi - : - $* <"+cmd;" 2>>EOE != 0 - testscript:1:5: error: ';' after setup command - EOE - - : colon - : - $* <"+cmd:" 2>>EOE != 0 - testscript:1:5: error: ':' after setup command - EOE - } - - : after - : - { - : test - : - $* <>EOE != 0 - cmd - +cmd - EOI - testscript:2:1: error: setup command after tests - EOE - - : after-tdownt - : - $* <>EOE != 0 - -cmd - +cmd - EOI - testscript:2:1: error: setup command after teardown - EOE - } - - : in-test - : - $* <>EOE != 0 - cmd; - +cmd - EOI - testscript:2:1: error: setup command in test - EOE -} - -: tdown -: -{ - : followed - : - { - : semi - : - $* <"-cmd;" 2>>EOE != 0 - testscript:1:5: error: ';' after teardown command - EOE - - : colon - : - $* <"-cmd:" 2>>EOE != 0 - testscript:1:5: error: ':' after teardown command - EOE - } - - : in-test - : - $* <>EOE != 0 - cmd; - -cmd - EOI - testscript:2:1: error: teardown command in test - EOE -} - -: var -: -{ - : between-tests - : - $* <>EOE != 0 - cmd - x = y - cmd - EOI - testscript:3:1: error: test after teardown - testscript:2:1: info: last teardown line appears here - EOE - - : between-tests-scope - : - $* <>EOE != 0 - cmd - x = y - { - cmd - } - EOI - testscript:3:1: error: scope after teardown - testscript:2:1: info: last teardown line appears here - EOE - - : between-tests-command-if - : - $* <>EOE != 0 - cmd - x = y - if true - cmd - end - EOI - testscript:3:1: error: test after teardown - testscript:2:1: info: last teardown line appears here - EOE - - : between-tests-scope-if - : - $* <>EOE != 0 - cmd - x = y - if true - { - cmd - } - EOI - testscript:3:1: error: scope after teardown - testscript:2:1: info: last teardown line appears here - EOE - - : between-tests-variable-if - : - $* <>EOO - cmd - x = y - if true - y = x - end - EOI - cmd - ? true - EOO -} diff --git a/unit-tests/test/script/regex/buildfile b/unit-tests/test/script/regex/buildfile deleted file mode 100644 index eb5394e..0000000 --- a/unit-tests/test/script/regex/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : unit-tests/test/script/regex/buildfile -# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -include ../../../../build2/ -exe{driver}: {hxx cxx}{*} ../../../../build2/libue{b} diff --git a/unit-tests/test/script/regex/driver.cxx b/unit-tests/test/script/regex/driver.cxx deleted file mode 100644 index cc7a2be..0000000 --- a/unit-tests/test/script/regex/driver.cxx +++ /dev/null @@ -1,301 +0,0 @@ -// file : unit-tests/test/script/regex/driver.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include -#include // is_pod, is_array - -#include - -using namespace std; -using namespace build2::test::script::regex; - -int -main () -{ - using lc = line_char; - using ls = line_string; - using lr = line_regex; - using cf = char_flags; - using cr = char_regex; - - // Test line_char. - // - { - static_assert (is_pod::value && !is_array::value, - "line_char must be char-like"); - - // Zero-initialed line_char should be the null-char as required by - // char_traits<>::length() specification. - // - assert (lc () == lc::nul); - - line_pool p; - - assert (lc::eof == -1); - assert (lc::nul == 0); - - enum meta {mn = 'n', mp = 'p'}; - - // Special roundtrip. - // - assert (lc ('0').special () == '0'); - assert (lc (0).special () == 0); - assert (lc (-1).special () == -1); - assert (lc ('p').special () == 'p'); - assert (lc (u'\u2028').special () == u'\u2028'); - - // Special comparison. - // - assert (lc ('0') == lc ('0')); - assert (lc ('0') == '0'); - assert (lc ('n') == mn); - assert (mn == static_cast (lc ('n'))); - - assert (lc ('0') != lc ('1')); - assert (lc ('0') != '1'); - assert (lc ('n') != mp); - assert (lc ('0') != lc ("0", p)); - assert (lc ('0') != lc (cr ("0"), p)); - - assert (lc ('0') < lc ('1')); - assert (lc ('0') < '1'); - assert (lc ('1') < lc ("0", p)); - assert (lc ('n') < mp); - - assert (lc ('0') <= '1'); - assert (lc ('0') <= lc ('1')); - assert (lc ('n') <= mn); - assert (lc ('1') <= lc ("0", p)); - - // Literal roundtrip. - // - assert (*lc ("abc", p).literal () == "abc"); - - // Literal comparison. - // - assert (lc ("a", p) == lc ("a", p)); - assert (lc ("a", p).literal () == lc ("a", p).literal ()); - assert (char (lc ("a", p)) == '\a'); - - assert (lc ("a", p) != lc ("b", p)); - assert (!(lc ("a", p) != lc (cr ("a"), p))); - assert (lc ("a", p) != lc (cr ("b"), p)); - - assert (lc ("a", p) < lc ("b", p)); - assert (!(lc ("a", p) < lc (cr ("a"), p))); - - assert (lc ("a", p) <= lc ("b", p)); - assert (lc ("a", p) <= lc (cr ("a"), p)); - assert (lc ("a", p) < lc (cr ("c"), p)); - - // Regex roundtrip. - // - assert (regex_match ("abc", *lc (cr ("abc"), p).regex ())); - - // Regex flags. - // - // icase - // - assert (regex_match ("ABC", cr ("abc", cf::icase))); - - // idot - // - assert (!regex_match ("a", cr ("[.]", cf::idot))); - assert (!regex_match ("a", cr ("[\\.]", cf::idot))); - - assert (regex_match ("a", cr ("."))); - assert (!regex_match ("a", cr (".", cf::idot))); - assert (regex_match ("a", cr ("\\.", cf::idot))); - assert (!regex_match ("a", cr ("\\."))); - - // regex::transform() - // - // The function is static and we can't test it directly. So we will test - // it indirectly via regex matches. - // - // @@ Would be nice to somehow address the inability to test internals (not - // exposed via headers). As a part of utility library support? - // - assert (regex_match (".a[.", cr (".\\.\\[[.]", cf::idot))); - assert (regex_match (".a[.", cr (".\\.\\[[\\.]", cf::idot))); - assert (!regex_match ("ba[.", cr (".\\.\\[[.]", cf::idot))); - assert (!regex_match (".a[b", cr (".\\.\\[[.]", cf::idot))); - assert (!regex_match (".a[b", cr (".\\.\\[[\\.]", cf::idot))); - - // Regex comparison. - // - assert (lc ("a", p) == lc (cr ("a|b"), p)); - assert (lc (cr ("a|b"), p) == lc ("a", p)); - } - - // Test char_traits. - // - { - using ct = char_traits; - using vc = vector; - - lc c; - ct::assign (c, '0'); - assert (c == ct::char_type ('0')); - - assert (ct::to_char_type (c) == c); - assert (ct::to_int_type (c) == c); - - assert (ct::eq_int_type (c, c)); - assert (!ct::eq_int_type (c, lc::eof)); - - assert (ct::eof () == lc::eof); - - assert (ct::not_eof (c) == c); - assert (ct::not_eof (lc::eof) != lc::eof); - - ct::assign (&c, 1, '1'); - assert (c == ct::int_type ('1')); - - assert (ct::eq (lc ('0'), lc ('0'))); - assert (ct::lt (lc ('0'), lc ('1'))); - - vc v1 ({'0', '1', '2'}); - vc v2 (3, lc::nul); - - assert (ct::find (v1.data (), 3, '1') == v1.data () + 1); - - ct::copy (v2.data (), v1.data (), 3); - assert (v2 == v1); - - v2.push_back (lc::nul); - assert (ct::length (v2.data ()) == 3); - - // Overlaping ranges. - // - ct::move (v1.data () + 1, v1.data (), 2); - assert (v1 == vc ({'0', '0', '1'})); - - v1 = vc ({'0', '1', '2'}); - ct::move (v1.data (), v1.data () + 1, 2); - assert (v1 == vc ({'1', '2', '2'})); - } - - // Test line_char_locale and ctype (only non-trivial functions). - // - { - using ct = ctype; - - line_char_locale l; - assert (has_facet (l)); - - // It is better not to create q facet on stack as it is - // reference-countable. - // - const ct& t (use_facet (l)); - line_pool p; - - assert (t.is (ct::digit, '0')); - assert (!t.is (ct::digit, '?')); - assert (!t.is (ct::digit, lc ("0", p))); - - const lc chars[] = { '0', '?' }; - ct::mask m[2]; - - const lc* b (chars); - const lc* e (chars + 2); - - // Cast flag value to mask type and compare to mask. - // - auto fl = [] (ct::mask m, ct::mask f) {return m == f;}; - - t.is (b, e, m); - assert (fl (m[0], ct::digit) && fl (m[1], 0)); - - assert (t.scan_is (ct::digit, b, e) == b); - assert (t.scan_is (0, b, e) == b + 1); - - assert (t.scan_not (ct::digit, b, e) == b + 1); - assert (t.scan_not (0, b, e) == b); - - { - char nr[] = "0?"; - lc wd[2]; - t.widen (nr, nr + 2, wd); - assert (wd[0] == b[0] && wd[1] == b[1]); - } - - { - lc wd[] = {'0', lc ("a", p)}; - char nr[2]; - t.narrow (wd, wd + 2, '-', nr); - assert (nr[0] == '0' && nr[1] == '-'); - } - } - - // Test regex_traits. Functions other that value() are trivial. - // - { - regex_traits t; - - const int radix[] = {8, 10}; // Radix 16 is not supported by line_char. - const char digits[] = "0123456789ABCDEF"; - - for (size_t r (0); r < 2; ++r) - { - for (int i (0); i < radix[r]; ++i) - assert (t.value (digits[i], radix[r]) == i); - } - } - - // Test line_regex construction. - // - { - line_pool p; - lr r1 ({lc ("foo", p), lc (cr ("ba(r|z)"), p)}, move (p)); - - lr r2 (move (r1)); - assert (regex_match (ls ({lc ("foo", r2.pool), lc ("bar", r2.pool)}), r2)); - assert (!regex_match (ls ({lc ("foo", r2.pool), lc ("ba", r2.pool)}), r2)); - } - - // Test line_regex match. - // - { - line_pool p; - - const lc foo ("foo", p); - const lc bar ("bar", p); - const lc baz ("baz", p); - const lc blank ("", p); - - assert (regex_match (ls ({foo, bar}), lr ({foo, bar}))); - assert (!regex_match (ls ({foo, baz}), lr ({foo, bar}))); - - assert (regex_match (ls ({bar, foo}), - lr ({'(', foo, '|', bar, ')', '+'}))); - - assert (regex_match (ls ({foo, foo, bar}), - lr ({'(', foo, ')', '\\', '1', bar}))); - - assert (regex_match (ls ({foo}), lr ({lc (cr ("fo+"), p)}))); - assert (regex_match (ls ({foo}), lr ({lc (cr (".*"), p)}))); - assert (regex_match (ls ({blank}), lr ({lc (cr (".*"), p)}))); - - assert (regex_match (ls ({blank, blank, foo}), - lr ({blank, '*', foo, blank, '*'}))); - - assert (regex_match (ls ({blank, blank, foo}), lr ({'.', '*'}))); - - assert (regex_match (ls ({blank, blank}), - lr ({blank, '*', foo, '?', blank, '*'}))); - - assert (regex_match (ls ({foo}), lr ({foo, '{', '1', '}'}))); - assert (regex_match (ls ({foo, foo}), lr ({foo, '{', '1', ',', '}'}))); - - assert (regex_match (ls ({foo, foo}), - lr ({foo, '{', '1', ',', '2', '}'}))); - - assert (!regex_match (ls ({foo, foo}), - lr ({foo, '{', '3', ',', '4', '}'}))); - - assert (regex_match (ls ({foo}), lr ({'(', '?', '=', foo, ')', foo}))); - assert (regex_match (ls ({foo}), lr ({'(', '?', '!', bar, ')', foo}))); - } -} -- cgit v1.1