From dd973d03bf5f3f439dcdacbb22470105e66e698a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 29 Mar 2017 00:45:30 +0300 Subject: Implement manifests and build_config --- tests/variable/buildfile | 9 +++++++ tests/variable/driver.cxx | 61 +++++++++++++++++++++++++++++++++++++++++++++++ tests/variable/testscript | 55 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 tests/variable/buildfile create mode 100644 tests/variable/driver.cxx create mode 100644 tests/variable/testscript (limited to 'tests/variable') diff --git a/tests/variable/buildfile b/tests/variable/buildfile new file mode 100644 index 0000000..7fb5105 --- /dev/null +++ b/tests/variable/buildfile @@ -0,0 +1,9 @@ +# file : tests/variable/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +import libs += libbutl%lib{butl} + +exe{driver}: cxx{driver} ../../bbot/lib{bbot} $libs test{testscript} + +include ../../bbot/ diff --git a/tests/variable/driver.cxx b/tests/variable/driver.cxx new file mode 100644 index 0000000..88167ad --- /dev/null +++ b/tests/variable/driver.cxx @@ -0,0 +1,61 @@ +// file : tests/variable/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include // ios_base::failbit, ios_base::badbit +#include +#include +#include // size_t +#include + +#include // operator<<(ostream,exception) + +#include + +using namespace std; +using namespace butl; +using namespace bbot; + +// Usage: argv[0] [-u] +// +// Read variables from STDIN (one per line) and serialize them to STDOUT (also +// one per line). +// +// -u output variables being unquoted beforehand +// +int +main (int argc, char* argv[]) +{ + assert (argc <= 2); + bool unquote (false); + + if (argc == 2) + { + assert (argv[1] == string ("-u")); + unquote = true; + } + + cin.exceptions (ios_base::badbit); + cout.exceptions (ios_base::failbit | ios_base::badbit); + + string s; + for (size_t l (1); getline (cin, s); ++l) + { + try + { + variable v (move (s)); + + cout << (unquote + ? v.unquoted () + : static_cast (v)) + << '\n'; + } + catch (const invalid_variable& e) + { + cerr << l << ':' << 1 + e.pos << ": error: " << e << endl; + return 1; + } + } + + return 0; +} diff --git a/tests/variable/testscript b/tests/variable/testscript new file mode 100644 index 0000000..d3d9302 --- /dev/null +++ b/tests/variable/testscript @@ -0,0 +1,55 @@ +# file : tests/variable/testscript +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.options += -u + +: valid +: +{ + $* <> EOO + config.cc.coptions="-O3 -stdlib='libc++'" + ab'c="x y"' + var=xy + var= + EOI + config.cc.coptions=-O3 -stdlib='libc++' + abc="x y" + var=xy + var= + EOO +} + +: invalid +: +{ + : expected-assignment + : + $* <'v"a r=abc"' 2>'1:4: error: expected variable assignment' == 1 + + : unterminated-quoted-string + : + $* <'var="a b' 2>'1:9: error: unterminated quoted string' == 1 + + : no-value + : + $* <'var' 2>'1:4: error: no variable value' == 1 +} + +: unquoting +: +{ + : single + : + $* <"var='a \" b'" >'var=a " b' + + : double + : + $* <'var="a '"'"' b"' >"var=a ' b" + + : mixed + : + $* <'var=a bc e' + var='a b'"c e" + EOI +} -- cgit v1.1