summaryrefslogtreecommitdiff
path: root/cli-tests/combined
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-04-08 14:51:57 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-04-27 11:38:53 +0300
commit720c5a33b6a49cf328fdd7611f49153cf8f60247 (patch)
tree9725f3d1f42ec90fde84520f49647edea013ce5e /cli-tests/combined
parent3183f3bb927a90783ae0aeaf190a0919377aabe4 (diff)
Separate tests and examples into individual packages
Also make cli module to be explicitly enabled via the config.cli configuration variable.
Diffstat (limited to 'cli-tests/combined')
-rw-r--r--cli-tests/combined/buildfile9
-rw-r--r--cli-tests/combined/driver.cxx39
-rw-r--r--cli-tests/combined/test.cli16
-rw-r--r--cli-tests/combined/testscript108
4 files changed, 172 insertions, 0 deletions
diff --git a/cli-tests/combined/buildfile b/cli-tests/combined/buildfile
new file mode 100644
index 0000000..943ca25
--- /dev/null
+++ b/cli-tests/combined/buildfile
@@ -0,0 +1,9 @@
+# file : combined/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-specifier --generate-file-scanner
diff --git a/cli-tests/combined/driver.cxx b/cli-tests/combined/driver.cxx
new file mode 100644
index 0000000..dcbdd34
--- /dev/null
+++ b/cli-tests/combined/driver.cxx
@@ -0,0 +1,39 @@
+// file : combined/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+// Test combined flags (-xyz vs -x -y -z) and option values (--foo=bar).
+//
+
+#include <iostream>
+
+#include "test.hxx"
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ cli::argv_file_scanner s (argc, argv, "--file");
+ options o (s);
+
+ if (o.foo_specified ())
+ cout << "--foo=" << o.foo () << endl;
+
+ if (o.x () || o.y () || o.z ())
+ cout << '-'
+ << (o.x () ? "x" : "")
+ << (o.y () ? "y" : "")
+ << (o.z () ? "z" : "") << endl;
+
+ if (o.xyz ())
+ cout << "--xyz" << endl;
+ }
+ catch (const cli::exception& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+}
diff --git a/cli-tests/combined/test.cli b/cli-tests/combined/test.cli
new file mode 100644
index 0000000..6377de8
--- /dev/null
+++ b/cli-tests/combined/test.cli
@@ -0,0 +1,16 @@
+// file : combined/test.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+include <string>;
+
+class options
+{
+ std::string --foo|-f;
+
+ bool -x;
+ bool -y;
+ bool -z;
+
+ bool --xyz;
+};
diff --git a/cli-tests/combined/testscript b/cli-tests/combined/testscript
new file mode 100644
index 0000000..d1f9830
--- /dev/null
+++ b/cli-tests/combined/testscript
@@ -0,0 +1,108 @@
+# file : combined/testscript
+# license : MIT; see accompanying LICENSE file
+
+: values
+:
+{
+ : long
+ :
+ $* --foo=123 >'--foo=123'
+
+ : short
+ :
+ $* -f=123 >'--foo=123'
+
+ : empty
+ :
+ $* --foo= >'--foo='
+
+ : unknown-option-long
+ :
+ $* --bar=123 2>>EOE != 0
+ unknown option '--bar'
+ EOE
+
+ : unknown-option-short
+ :
+ $* -b=123 2>>EOE != 0
+ unknown option '-b'
+ EOE
+
+ : unknown-value
+ :
+ $* --xyz=123 2>>EOE != 0
+ invalid value '123' for option '--xyz'
+ EOE
+
+ : options-file
+ :
+ {
+ : basics
+ :
+ cat <<EOI >=options;
+ --foo=123
+ EOI
+ $* --file=options >'--foo=123'
+
+ : equal-in-value
+ :
+ cat <<EOI >=options;
+ --foo bar=123
+ EOI
+ $* --file=options >'--foo=bar=123'
+
+ : space-in-value
+ :
+ cat <<EOI >=options;
+ --foo= 123
+ EOI
+ $* --file=options >'--foo= 123'
+
+ : quoted-value
+ :
+ cat <<EOI >=options;
+ --foo="'bar 123'"
+ EOI
+ $* --file=options >"--foo='bar 123'"
+ }
+}
+
+: flags
+:
+{
+ : basic
+ :
+ $* -zyx >'-xyz'
+
+ : separate
+ :
+ $* -zx -y >'-xyz'
+
+ : long
+ :
+ $* --xyz >'--xyz'
+
+ : unknown-option
+ :
+ $* -xYz 2>>EOE != 0
+ unknown option '-Y'
+ EOE
+
+ : alnum-only
+ :
+ $* -xy+ 2>>EOE != 0
+ unknown option '-xy+'
+ EOE
+
+ : flags-only
+ :
+ $* -xyf 123 2>>EOE != 0
+ missing value for option '-f'
+ EOE
+
+ : flags-only-combined
+ :
+ $* -xyf=123 2>>EOE != 0
+ missing value for option '-f'
+ EOE
+}