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/group/buildfile | 9 +++ cli-tests/group/driver.cxx | 58 +++++++++++++++++++ cli-tests/group/test.cli | 7 +++ cli-tests/group/testscript | 140 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 cli-tests/group/buildfile create mode 100644 cli-tests/group/driver.cxx create mode 100644 cli-tests/group/test.cli create mode 100644 cli-tests/group/testscript (limited to 'cli-tests/group') diff --git a/cli-tests/group/buildfile b/cli-tests/group/buildfile new file mode 100644 index 0000000..30327e0 --- /dev/null +++ b/cli-tests/group/buildfile @@ -0,0 +1,9 @@ +# file : group/buildfile +# license : MIT; see accompanying LICENSE file + +exe{driver}: {hxx cxx}{* -test} cli.cxx{test} testscript + +cxx.poptions =+ "-I$out_base" + +cli.cxx{test}: cli{test} +cli.options = --generate-group-scanner diff --git a/cli-tests/group/driver.cxx b/cli-tests/group/driver.cxx new file mode 100644 index 0000000..68f6107 --- /dev/null +++ b/cli-tests/group/driver.cxx @@ -0,0 +1,58 @@ +// file : group/driver.cxx +// author : Boris Kolpackov +// license : MIT; see accompanying LICENSE file + +// Test group_scanner. +// + +#include + +#include "test.hxx" + +using namespace std; + +int +main (int argc, char* argv[]) +{ + try + { + using namespace cli; + + // Mode flags. + // + // 'g' -- don't handle groups. + // 's' -- skip arguments. + // + string m (argv[1]); + + argv_scanner as (--argc, ++argv); + group_scanner s (as); + + while (s.more ()) + { + if (m.find ('s') == string::npos) + { + const char* a (s.next ()); + cout << "'" << a << "'"; + } + else + s.skip (); + + if (m.find ('g') == string::npos) + { + scanner& gs (s.group ()); + while (gs.more ()) + cout << " '" << gs.next () << "'"; + } + + cout << endl; + } + + return 0; + } + catch (const cli::exception& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/cli-tests/group/test.cli b/cli-tests/group/test.cli new file mode 100644 index 0000000..8725791 --- /dev/null +++ b/cli-tests/group/test.cli @@ -0,0 +1,7 @@ +// file : group/test.cli +// author : Boris Kolpackov +// license : MIT; see accompanying LICENSE file + +class options +{ +}; diff --git a/cli-tests/group/testscript b/cli-tests/group/testscript new file mode 100644 index 0000000..6269ca2 --- /dev/null +++ b/cli-tests/group/testscript @@ -0,0 +1,140 @@ +# file : group/testscript +# license : MIT; see accompanying LICENSE file + +: no-args +: +$* '' + +: no-groups +: +$* '' --foo arg >>EOO +'--foo' +'arg' +EOO + +: group-pre +: +$* '' { --foo --bar }+ arg1 arg2 >>EOO +'arg1' '--foo' '--bar' +'arg2' +EOO + +: group-pre-multi +: +$* '' { --foo }+ { --bar }+ arg1 arg2 >>EOO +'arg1' '--foo' '--bar' +'arg2' +EOO + +: group-post +: +$* '' arg1 arg2 +{ foo bar } >>EOO +'arg1' +'arg2' 'foo' 'bar' +EOO + +: group-post-multi +: +$* '' arg1 arg2 +{ foo } +{ bar } >>EOO +'arg1' +'arg2' 'foo' 'bar' +EOO + +: group-both +: +$* '' arg1 { --foo --bar }+ arg2 +{ foo bar } arg3 >>EOO +'arg1' +'arg2' '--foo' '--bar' 'foo' 'bar' +'arg3' +EOO + +: group-both-multi +: +$* '' arg1 { --foo }+ { --bar }+ arg2 +{ foo } +{ bar } arg3 >>EOO +'arg1' +'arg2' '--foo' '--bar' 'foo' 'bar' +'arg3' +EOO + +: multi-group +: +$* '' { --foo }+ arg1 arg2 +{ bar } >>EOO +'arg1' '--foo' +'arg2' 'bar' +EOO + +: empty-group +: +$* '' { }+ arg1 arg2 +{ } >>EOO +'arg1' +'arg2' +EOO + +: escape-arg +: +$* '' '\{' '\}' '\+{' '\}+' '{x' '}x' >>EOO +'{' +'}' +'+{' +'}+' +'{x' +'}x' +EOO + +: escape-group +: +$* '' { '\{' '\}' '\+{' '\}+' '{x' '}x' }+ arg >>EOO +'arg' '{' '}' '+{' '}+' '{x' '}x' +EOO + +: not-group +: +$* '' { --foo } 2>>EOE != 0 +expected group separator '}+' instead of '}', use '\}' to escape +EOE + +: no-arg-pre +: +$* '' { --foo }+ 2>>EOE != 0 +unexpected group separator '{', use '\{' to escape +EOE + +: no-arg-pre-empty +: +$* '' { }+ 2>>EOE != 0 +unexpected group separator '{', use '\{' to escape +EOE + +: no-arg-post +: +$* '' +{ --foo } 2>>EOE != 0 +unexpected group separator '+{', use '\+{' to escape +EOE + +: no-arg-post-empty +: +$* '' +{ } 2>>EOE != 0 +unexpected group separator '+{', use '\+{' to escape +EOE + +: unhandled-group-pre +: +$* 'g' { --foo }+ arg >>EOO 2>>EOE != 0 +'arg' +EOO +unexpected grouped argument '--foo' for argument 'arg' +EOE + +: unhandled-group-post +: +$* 'g' arg +{ bar } >>EOO 2>>EOE != 0 +'arg' +EOO +unexpected grouped argument 'bar' for argument 'arg' +EOE + +: unhandled-group-skip +: +$* 'sg' { --foo }+ arg +{ bar } >>EOO + +EOO -- cgit v1.1