summaryrefslogtreecommitdiff
path: root/cli-tests/file
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/file
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/file')
-rw-r--r--cli-tests/file/buildfile9
-rw-r--r--cli-tests/file/driver.cxx39
-rw-r--r--cli-tests/file/test.cli7
-rw-r--r--cli-tests/file/testscript286
4 files changed, 341 insertions, 0 deletions
diff --git a/cli-tests/file/buildfile b/cli-tests/file/buildfile
new file mode 100644
index 0000000..793d2a9
--- /dev/null
+++ b/cli-tests/file/buildfile
@@ -0,0 +1,9 @@
+# file : file/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-file-scanner
diff --git a/cli-tests/file/driver.cxx b/cli-tests/file/driver.cxx
new file mode 100644
index 0000000..eef7ef1
--- /dev/null
+++ b/cli-tests/file/driver.cxx
@@ -0,0 +1,39 @@
+// file : file/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+// Test argv_file_scanner.
+//
+#include <memory>
+#include <string>
+#include <iostream>
+
+#include "test.hxx"
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ string a (argc > 1 ? argv[1] : "");
+
+ // Special modes.
+ //
+ // ---- <file>
+ // --- <file>
+ //
+ unique_ptr<cli::scanner> s (
+ a == "----" ? new cli::argv_file_scanner (argv[2], "--file") :
+ a == "---" ? new cli::argv_file_scanner (argv[2]) :
+ new cli::argv_file_scanner (argc, argv, "--file"));
+
+ while (s->more ())
+ cout << s->next () << endl;
+ }
+ catch (const cli::exception& e)
+ {
+ cerr << e << endl;
+ }
+}
diff --git a/cli-tests/file/test.cli b/cli-tests/file/test.cli
new file mode 100644
index 0000000..c72a495
--- /dev/null
+++ b/cli-tests/file/test.cli
@@ -0,0 +1,7 @@
+// file : file/test.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+class options
+{
+};
diff --git a/cli-tests/file/testscript b/cli-tests/file/testscript
new file mode 100644
index 0000000..d86ec1d
--- /dev/null
+++ b/cli-tests/file/testscript
@@ -0,0 +1,286 @@
+# file : file/testscript
+# license : MIT; see accompanying LICENSE file
+
+# End-of-line marker. Place its expansion in here-documents after the trailing
+# spaces to prevent them from being stripped by editors and to improve
+# readability.
+#
+eol = ""
+
++cat <<EOI >=empty.ops
+# Empty options file.
+#
+
+EOI
++cat <<EOI >=base.ops
+-a 21
+-b 21
+EOI
+
+# @@ Give tests some meaningfull descriptions.
+#
+
+: 000
+:
+cat <<EOI >=test.ops;
+-a 11
+-b 11
+ -a 12
+
+ -b 12
+a
+EOI
+$* -a 1 --file ../empty.ops -b 1 --file ../base.ops --file test.ops b >>EOO
+-a
+1
+-b
+1
+-a
+21
+-b
+21
+-a
+11
+-b
+11
+-a
+12
+-b
+12
+a
+b
+EOO
+
+: 001
+:
+cat <<EOI >=test.ops;
+# Empty options file.
+#
+
+EOI
+$* -a 1 -- --file test.ops b >>EOO
+-a
+1
+--
+--file
+test.ops
+b
+EOO
+
+: 002
+:
+cat <<EOI >=test.ops;
+-a 11
+-b 11
+--
+--file ../base.ops
+-a 12
+-b 12
+a
+EOI
+$* -a 1 --file test.ops --file ../empty.ops b >>EOO
+-a
+1
+-a
+11
+-b
+11
+--
+--file
+../base.ops
+-a
+12
+-b
+12
+a
+--file
+../empty.ops
+b
+EOO
+
+: 003
+:
+$* -a 1 --file ../base.ops --file test.ops b >>EOO 2>>EOE
+-a
+1
+-a
+21
+-b
+21
+EOO
+unable to open file 'test.ops' or read failure
+EOE
+
+: 004
+:
+cat <<EOI >=test.ops;
+-a a"b"c
+-a "abc"
+-a "a"b"
+-a ""
+-a " abc "
+-a " "
+-a """
+-a "'"
+
+-a a'b'c
+-a 'abc'
+-a 'a'b'
+-a ''
+-a ' abc '
+-a ' '
+-a '''
+-a '"'
+EOI
+$* --file test.ops >>"EOO"
+-a
+a"b"c
+-a
+abc
+-a
+a"b
+-a
+
+-a
+ abc $eol
+-a
+ $eol
+-a
+"
+-a
+'
+-a
+a'b'c
+-a
+abc
+-a
+a'b
+-a
+
+-a
+ abc $eol
+-a
+ $eol
+-a
+'
+-a
+"
+EOO
+
+: 005
+:
+cat <<EOI >=test.ops;
+-a "
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument '"'
+EOE
+
+: 006
+:
+cat <<EOI >=test.ops;
+-a "abc
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument '"abc'
+EOE
+
+: 007
+:
+cat <<EOI >=test.ops;
+-a abc"
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument 'abc"'
+EOE
+
+: 008
+:
+cat <<EOI >=test.ops;
+-a '
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument '''
+EOE
+
+: 009
+:
+cat <<EOI >=test.ops;
+-a 'abc
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument ''abc'
+EOE
+
+: 010
+:
+cat <<EOI >=test.ops;
+-a abc'
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument 'abc''
+EOE
+
+: 011
+:
+cat <<EOI >=test.ops;
+-a "abc'
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument '"abc''
+EOE
+
+: 012
+:
+cat <<EOI >=test.ops;
+-a 'abc"
+EOI
+$* --file test.ops 2>>EOE
+unmatched quote in argument ''abc"'
+EOE
+
+: quoted-argument
+:
+cat <<EOI >=test.ops;
+"'foo bar'"
+'"foo bar"'
+EOI
+$* --file test.ops >>EOO
+'foo bar'
+"foo bar"
+EOO
+
+: direct-file-load
+:
+cat <<EOI >=test.ops;
+-f
+-a 123
+EOI
+$* --- test.ops >>EOO
+-f
+-a
+123
+EOO
+
+: direct-file-empty
+:
+cat <<EOI >=test.ops;
+EOI
+$* --- test.ops
+
+: direct-file-load-nested
+:
+cat <<EOI >=test.ops;
+-f
+--file ../base.ops
+-a 123
+EOI
+$* ---- test.ops >>EOO
+-f
+-a
+21
+-b
+21
+-a
+123
+EOO