summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/combined/buildfile10
-rw-r--r--tests/combined/driver.cxx40
-rw-r--r--tests/combined/test.cli17
-rw-r--r--tests/combined/testscript84
-rw-r--r--tests/erase/buildfile1
5 files changed, 152 insertions, 0 deletions
diff --git a/tests/combined/buildfile b/tests/combined/buildfile
new file mode 100644
index 0000000..a94bbb0
--- /dev/null
+++ b/tests/combined/buildfile
@@ -0,0 +1,10 @@
+# file : tests/combined/buildfile
+# copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+exe{driver}: {hxx cxx}{* -test} cli.cxx{test} test{testscript}
+
+cxx.poptions =+ "-I$out_base"
+
+cli.cxx{test}: cli{test}
+cli.options = --generate-specifier --generate-file-scanner
diff --git a/tests/combined/driver.cxx b/tests/combined/driver.cxx
new file mode 100644
index 0000000..e6f27e4
--- /dev/null
+++ b/tests/combined/driver.cxx
@@ -0,0 +1,40 @@
+// file : tests/combined/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+// 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/tests/combined/test.cli b/tests/combined/test.cli
new file mode 100644
index 0000000..16f73d9
--- /dev/null
+++ b/tests/combined/test.cli
@@ -0,0 +1,17 @@
+// file : tests/combined/test.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+// 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/tests/combined/testscript b/tests/combined/testscript
new file mode 100644
index 0000000..a6f827b
--- /dev/null
+++ b/tests/combined/testscript
@@ -0,0 +1,84 @@
+# file : tests/combined/testscript
+# copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+# 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
+ :
+ cat <<EOI >=options;
+ --foo=123
+ EOI
+ $* --file=options >'--foo=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
+}
diff --git a/tests/erase/buildfile b/tests/erase/buildfile
index ec1cff6..d73cb2d 100644
--- a/tests/erase/buildfile
+++ b/tests/erase/buildfile
@@ -8,3 +8,4 @@ exe{driver}: test.arguments = foo -a bar -b 123 --arg -- -b 234
cxx.poptions =+ "-I$out_base"
cli.cxx{test}: cli{test}
+cli.options = --no-combined-flags # Can't be used with the skip unknown mode.