From 720c5a33b6a49cf328fdd7611f49153cf8f60247 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 8 Apr 2020 14:51:57 +0300 Subject: Separate tests and examples into individual packages Also make cli module to be explicitly enabled via the config.cli configuration variable. --- cli-tests/merge/buildfile | 9 ++++++++ cli-tests/merge/driver.cxx | 55 ++++++++++++++++++++++++++++++++++++++++++++++ cli-tests/merge/test.cli | 18 +++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 cli-tests/merge/buildfile create mode 100644 cli-tests/merge/driver.cxx create mode 100644 cli-tests/merge/test.cli (limited to 'cli-tests/merge') diff --git a/cli-tests/merge/buildfile b/cli-tests/merge/buildfile new file mode 100644 index 0000000..ed93cda --- /dev/null +++ b/cli-tests/merge/buildfile @@ -0,0 +1,9 @@ +# file : merge/buildfile +# license : MIT; see accompanying LICENSE file + +exe{driver}: {hxx cxx}{* -test} cli.cxx{test} + +cxx.poptions =+ "-I$out_base" + +cli.cxx{test}: cli{test} +cli.options = --generate-merge diff --git a/cli-tests/merge/driver.cxx b/cli-tests/merge/driver.cxx new file mode 100644 index 0000000..43b1c59 --- /dev/null +++ b/cli-tests/merge/driver.cxx @@ -0,0 +1,55 @@ +// file : merge/driver.cxx +// author : Boris Kolpackov +// license : MIT; see accompanying LICENSE file + +// Test parsed options merging. +// + +#include +#include + +#include "test.hxx" + +using namespace std; + +template +static T +merge (const char* (&av1)[N1], const char* (&av2)[N2]) +{ + int ac1 (N1); + int ac2 (N2); + T o1 (ac1, const_cast (av1)); + T o2 (ac2, const_cast (av2)); + o1.merge (o2); + return o1; +} + +int +main () +{ + // Basics. + // + { + const char* a1[] = {"", "-i=123", "-v=1", "-v=2"}; + const char* a2[] = {"", "-b", "-i=456", "-s=xyz", "-v=3", "-v=4"}; + derived r (merge (a1, a2)); + + assert (r.b ()); + assert (r.i_specified () && r.i () == 456); + assert (r.s_specified () && r.s () == "xyz"); + assert (r.v_specified () && r.v ().size () == 4 && + r.v ()[0] == 1 && + r.v ()[1] == 2 && + r.v ()[2] == 3 && + r.v ()[3] == 4); + } + + // Default value does not override. + // + { + const char* a1[] = {"", "-i=456"}; + const char* a2[] = {"" }; + derived r (merge (a1, a2)); + assert (r.i_specified () && r.i () == 456); + } +} diff --git a/cli-tests/merge/test.cli b/cli-tests/merge/test.cli new file mode 100644 index 0000000..67f50c6 --- /dev/null +++ b/cli-tests/merge/test.cli @@ -0,0 +1,18 @@ +// file : merge/test.cli +// author : Boris Kolpackov +// license : MIT; see accompanying LICENSE file + +include ; +include ; + +class base +{ + bool -b; + int -i = -1; + std::string -s; +}; + +class derived: base +{ + std::vector -v; +}; -- cgit v1.1