diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-11-17 23:39:15 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-11-29 21:06:49 +0300 |
commit | c8775bf46f337e2dca4d161251eb89595aef4051 (patch) | |
tree | 38593dff2e970ff3cb9afb9d4df662fea6584f8e /tests | |
parent | 93c043d0bc755f6c9cffea489116ae742795a152 (diff) |
Add support for builds manifest value
Diffstat (limited to 'tests')
-rw-r--r-- | tests/build-class-expr/buildfile | 8 | ||||
-rw-r--r-- | tests/build-class-expr/driver.cxx | 101 | ||||
-rw-r--r-- | tests/build-class-expr/testscript | 125 | ||||
-rw-r--r-- | tests/manifest/testscript | 21 |
4 files changed, 255 insertions, 0 deletions
diff --git a/tests/build-class-expr/buildfile b/tests/build-class-expr/buildfile new file mode 100644 index 0000000..8d63d65 --- /dev/null +++ b/tests/build-class-expr/buildfile @@ -0,0 +1,8 @@ +# file : tests/build-class-expr/buildfile +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +import libs = libbutl%lib{butl} +import libs += libbpkg%lib{bpkg} + +exe{driver}: {hxx cxx}{*} $libs testscript diff --git a/tests/build-class-expr/driver.cxx b/tests/build-class-expr/driver.cxx new file mode 100644 index 0000000..343c3b5 --- /dev/null +++ b/tests/build-class-expr/driver.cxx @@ -0,0 +1,101 @@ +// file : tests/build-class-expr/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <ios> +#include <string> +#include <iostream> + +#include <libbutl/utility.mxx> // eof(), operator<<(ostream, exception) +#include <libbutl/optional.mxx> + +#include <libbpkg/manifest.hxx> + +// Usages: +// +// argv[0] -p +// argv[0] [<classes>] +// +// Parse stdin lines as build configuration class expressions and print them +// or evaluate. +// +// In the first form print expressions to stdout, one per line. +// +// In the second form sequentially match the configuration classes passed as +// arguments against the expressions, updating the match result. If the first +// expression has an underlying class set specified, then transform the +// combined expression, making the underlying class set a starting set for the +// original expression and a restricting set, simultaneously. +// +// On error print the exception description to stderr and exit with the two +// status. Otherwise, if the combined expression doesn't match then exit with +// the one status. Otherwise, exit with zero status. +// +int +main (int argc, char* argv[]) +{ + using namespace std; + using namespace butl; + using namespace bpkg; + + using butl::optional; + + bool print (argc != 1 && argv[1] == string ("-p")); + + assert (!print || argc == 2); + + cin.exceptions (ios::badbit); + + strings cs; + + if (print) + cout.exceptions (ios::failbit | ios::badbit); + else + { + for (int i (1); i != argc; ++i) + cs.push_back (argv[i]); + } + + try + { + string s; + bool r (false); + optional<strings> underlying_cls; + + while (!eof (getline (cin, s))) + { + build_class_expr expr (s, "" /* comment */); + + if (print) + cout << expr << endl; + else + { + if (!underlying_cls) + { + underlying_cls = move (expr.underlying_classes); + + if (!underlying_cls->empty ()) + { + build_class_expr expr (*underlying_cls, '+', "" /* comment */); + expr.match (cs, r); + } + } + + expr.match (cs, r); + } + } + + if (underlying_cls && !underlying_cls->empty ()) + { + build_class_expr expr (*underlying_cls, '&', "" /* comment */); + expr.match (cs, r); + } + + return print || r ? 0 : 1; + } + catch (const exception& e) + { + cerr << e << endl; + return 2; + } +} diff --git a/tests/build-class-expr/testscript b/tests/build-class-expr/testscript new file mode 100644 index 0000000..cfa1400 --- /dev/null +++ b/tests/build-class-expr/testscript @@ -0,0 +1,125 @@ +# file : tests/build-class-expr/testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: valid +: +{ + test.options += -p + + : roundtrip + : + $* <<EOF >>EOF + a + a b + a : -b + a : -b +c + +g + +gcc + +gcc-libc++ + +!gcc + +gcc -windows + +gcc &linux + +gcc &linux +( +msvc +windows &!optimized ) + +!windows &( +gcc +clang ) +( +windows &msvc ) + -windows + EOF + + $* <'a :' >'a' : no-expr +} + +: invalid +: +{ + test.options += -p + + $* <'' 2>"empty class expression" != 0 : empty1 + $* <'+( )' 2>"empty nested class expression" != 0 : empty2 + $* <':' 2>"underlying class set expected" != 0 : und-exprected1 + $* <': a' 2>"underlying class set expected" != 0 : und-exprected2 + $* <'~a' 2>"class name '~a' starts with '~'" != 0 : invalid-und + $* <'x : a' 2>"class term 'a' must start with '+', '-', or '&'" != 0 : no-op + $* <'+' 2>"empty class name" != 0 : no-name1 + $* <'+!' 2>"empty class name" != 0 : no-name2 + $* <'+a=b' 2>"class name 'a=b' contains '='" != 0 : invalid-char1 + $* <'+-a' 2>"class name '-a' starts with '-'" != 0 : invalid-char2 + $* <'+( +a' 2>"nested class expression must be closed with ')'" != 0 : not-closed + $* <'+a )' 2>"class term expected instead of ')'" != 0 : expected-name1 + $* <'+( +b ) )' 2>"class term expected instead of ')'" != 0 : expected-name2 + $* <'+( -a )' 2>"class term '-a' must start with '+'" != 0 : first-subtract +} + +: match +: +{ + : non-empty-class-list + : + { + test.arguments += a b c + + $* <'+a' + $* <'+!x' + $* <'+a +x' + $* <'+a +!x' + $* <'+a -x' + $* <'+a -!b' + $* <'+a -b +c' + $* <'+a &b' + $* <'+a &!y' + + $* <'+a +( +b )' + $* <'+a +( +x )' + $* <'+a +!( +b )' + $* <'+a +!( +x )' + $* <'+a &( +b )' + $* <'+a &!( +x )' + $* <'+a -( +x )' + $* <'+a -!( +b )' + $* <'+( +b -c +a )' + $* <'+a &( +b -c +a )' + $* <'+a &( +b -c +( +a -b ) +c )' + + $* <'a : +c' + $* <'a : -x' + } + + : empty-class-list + : + { + $* <'+!x' + } +} + +: mismatch +: +{ + : non-empty-class-list + : + { + test.arguments += a b c + + $* <'+!a' == 1 + $* <'+a -b' == 1 + $* <'+a -!x' == 1 + $* <'+a &x' == 1 + $* <'+a &!b' == 1 + + $* <'+a -( +b )' == 1 + $* <'+a -!( +x )' == 1 + $* <'+a &( +x )' == 1 + $* <'+a &!( +b )' == 1 + $* <'+a -c +( +x )' == 1 + $* <'+a -c +!( +b )' == 1 + $* <'+a -( +x +b )' == 1 + $* <'+a &( +b -c +( +a +b ) &x )' == 1 + + $* <'x : +a' == 1 + $* <'a : -c' == 1 + } + + : empty-class-list + : + { + $* <'+a' == 1 + } +} diff --git a/tests/manifest/testscript b/tests/manifest/testscript index 4f9a9a9..b77740f 100644 --- a/tests/manifest/testscript +++ b/tests/manifest/testscript @@ -127,6 +127,7 @@ requires: ? ; libc++ standard library if using Clang on Mac OS X. requires: zlib; Most Linux/UNIX systems already have one; or get it at\ www.zlib.net. + builds: +!windows &( +gcc +clang ) +( +windows &msvc ) build-include: linux* build-include: freebsd* build-exclude: *; Only supports Linux and FreeBSD. @@ -142,6 +143,8 @@ email: libbar-users@example.org build-email: depends: libbaz (1- 2-) | libbaz [3 4-) | libbaz (5 6] | libbaz [7 8] + builds: default legacy; Default and legacy. + builds: -windows; Not on Windows. build-exclude: *-msvc_14*/i?86-*; Linker crash. location: bar/libbar-3.4A.5+6.tbz sha256sum: d4b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 @@ -153,6 +156,7 @@ url: http://www.example.org/projects/libbar/ email: libbaz-users@example.org build-error-email: libbaz-issues@example.org; Email for libbaz issues. + builds: default experimental location: libbaz/libbaz-+2-3.4A.5+3.tar.gz sha256sum: b5b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 EOF @@ -204,6 +208,23 @@ fragment: ca602c2d46b0dca7a9ebc856871767b0ba6b74f3 EOF } + + : builds + : + { + : invalid + : + { + : empty + : + $* -pp <<EOI 2>"stdin:4:9: error: invalid package builds: class expression separator ':' expected" != 0 + : 1 + sha256sum: a2b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + : + builds: default -gcc + EOI + } + } } : repositories |