From 45218bf14ea1e8041b303bea313c939e1ec77a91 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 16 Apr 2019 22:47:22 +0300 Subject: Add package_manifest::override() overriding build* values --- tests/overrides/buildfile | 8 +++ tests/overrides/driver.cxx | 95 +++++++++++++++++++++++++++++++++++ tests/overrides/testscript | 122 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 tests/overrides/buildfile create mode 100644 tests/overrides/driver.cxx create mode 100644 tests/overrides/testscript (limited to 'tests') diff --git a/tests/overrides/buildfile b/tests/overrides/buildfile new file mode 100644 index 0000000..bcc0224 --- /dev/null +++ b/tests/overrides/buildfile @@ -0,0 +1,8 @@ +# file : tests/overrides/buildfile +# copyright : Copyright (c) 2014-2019 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/overrides/driver.cxx b/tests/overrides/driver.cxx new file mode 100644 index 0000000..fea4294 --- /dev/null +++ b/tests/overrides/driver.cxx @@ -0,0 +1,95 @@ +// file : tests/overrides/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include // ios_base::failbit, ios_base::badbit +#include +#include +#include // size_t +#include // uint64_t +#include +#include + +#include // trim() +#include +#include + +#include + +using namespace std; +using namespace butl; +using namespace bpkg; + +// Usages: argv[0] [-n] (:)* +// +// Parse the package manifest from stdin, apply overrides passed as arguments, +// and serialize the resulting manifest to stdout. +// +// -n pass the stream name to manifest_parser::override() +// +int +main (int argc, char* argv[]) +{ + vector overrides; + + bool name (false); + + uint64_t l (1); + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-n") + { + name = true; + } + else + { + size_t p (a.find (':')); + + assert (p != string::npos); + + // Fill the values with the location information for the exception + // description testing. + // + manifest_name_value nv {string (a, 0, p), string (a, p + 1), + l /* name_line */, 1 /* name_column */, + l /* value_line */, p + 2 /* value_column */, + 0, 0, 0}; + + ++l; + + trim (nv.name); + trim (nv.value); + + assert (!nv.name.empty ()); + + overrides.push_back (move (nv)); + } + } + + cin.exceptions (ios_base::failbit | ios_base::badbit); + cout.exceptions (ios_base::failbit | ios_base::badbit); + + manifest_parser p (cin, "stdin"); + manifest_serializer s (cout, "stdout"); + + try + { + package_manifest m (p); + m.override (overrides, name ? "args" : string ()); + m.serialize (s); + } + catch (const manifest_parsing& e) + { + cerr << e << endl; + return 1; + } + catch (const manifest_serialization& e) + { + cerr << e << endl; + return 1; + } + + return 0; +} diff --git a/tests/overrides/testscript b/tests/overrides/testscript new file mode 100644 index 0000000..9a7472f --- /dev/null +++ b/tests/overrides/testscript @@ -0,0 +1,122 @@ +# file : tests/overrides/testscript +# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: valid +: +{ + : build-email + : + $* 'build-email: bar@example.com' <>EOO + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + build-email: foo@example.com + build-error-email: error@example.com + build-warning-email: warning@example.com + EOI + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + build-email: bar@example.com + EOO + + : builds + : + $* 'builds: gcc' <>EOO + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + builds: default + build-include: linux* + build-exclude: *; Only supports Linux. + EOI + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + builds: gcc + EOO + + : build-include-exclude + : + $* 'build-include: linux*' 'build-exclude: *; Only supports Linux.' <>EOO + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + builds: default + EOI + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + build-include: linux* + build-exclude: *; Only supports Linux. + EOO + + : none + : + $* <>EOO + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + build-email: foo@example.com + EOI + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + build-email: foo@example.com + EOO +} + +: invalid +: +{ + : forbidden + : + $* 'name: libbar' <"cannot override 'name' value" != 0 + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + EOI + + : bad-value + : + $* 'builds: all' 'builds: default : -windows' <>EOE != 0 + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + EOI + invalid package builds in 'default : -windows': unexpected underlying class set + EOE + + : stream-name-specified + : + $* -n 'builds: all' 'builds: default : -windows' <>EOE != 0 + : 1 + name: libfoo + version: 2.0.0 + summary: Modern C++ parser + license: LGPLv2 + EOI + args:2:8: error: invalid package builds: unexpected underlying class set + EOE +} -- cgit v1.1