summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-07-27 17:28:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-07-27 17:28:27 +0200
commit8c1e0035404050376350d5e9b9242f5d39a6b53e (patch)
tree1aa609d156a4e0c131caf40c2d070d20b304bdbf /tests
parentdca38b27afc25d329fd7a7241095b40e2a1ecae2 (diff)
Add support for direct file loading with argv_file_scanner
Diffstat (limited to 'tests')
-rw-r--r--tests/file/driver.cxx19
-rw-r--r--tests/file/testscript103
2 files changed, 84 insertions, 38 deletions
diff --git a/tests/file/driver.cxx b/tests/file/driver.cxx
index e2dc9d5..82f944c 100644
--- a/tests/file/driver.cxx
+++ b/tests/file/driver.cxx
@@ -5,7 +5,8 @@
// Test argv_file_scanner.
//
-
+#include <memory>
+#include <string>
#include <iostream>
#include "test.hxx"
@@ -17,10 +18,20 @@ main (int argc, char* argv[])
{
try
{
- cli::argv_file_scanner s (argc, argv, "--file");
+ 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;
+ while (s->more ())
+ cout << s->next () << endl;
}
catch (const cli::exception& e)
{
diff --git a/tests/file/testscript b/tests/file/testscript
index 3f9d43b..ab0eb12 100644
--- a/tests/file/testscript
+++ b/tests/file/testscript
@@ -8,12 +8,12 @@
#
eol = ""
-+cat <<EOI >=empty.cli
++cat <<EOI >=empty.ops
# Empty options file.
#
EOI
-+cat <<EOI >=base.cli
++cat <<EOI >=base.ops
-a 21
-b 21
EOI
@@ -23,7 +23,7 @@ EOI
: 000
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a 11
-b 11
-a 12
@@ -31,7 +31,7 @@ cat <<EOI >=test.cli;
-b 12
a
EOI
-$* -a 1 --file ../empty.cli -b 1 --file ../base.cli --file test.cli b >>EOO
+$* -a 1 --file ../empty.ops -b 1 --file ../base.ops --file test.ops b >>EOO
-a
1
-b
@@ -54,32 +54,32 @@ EOO
: 001
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
# Empty options file.
#
EOI
-$* -a 1 -- --file test.cli b >>EOO
+$* -a 1 -- --file test.ops b >>EOO
-a
1
--
--file
-test.cli
+test.ops
b
EOO
: 002
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a 11
-b 11
--
---file ../base.cli
+--file ../base.ops
-a 12
-b 12
a
EOI
-$* -a 1 --file test.cli --file ../empty.cli b >>EOO
+$* -a 1 --file test.ops --file ../empty.ops b >>EOO
-a
1
-a
@@ -88,20 +88,20 @@ $* -a 1 --file test.cli --file ../empty.cli b >>EOO
11
--
--file
-../base.cli
+../base.ops
-a
12
-b
12
a
--file
-../empty.cli
+../empty.ops
b
EOO
: 003
:
-$* -a 1 --file ../base.cli --file test.cli b >>EOO 2>>EOE
+$* -a 1 --file ../base.ops --file test.ops b >>EOO 2>>EOE
-a
1
-a
@@ -109,12 +109,12 @@ $* -a 1 --file ../base.cli --file test.cli b >>EOO 2>>EOE
-b
21
EOO
-unable to open file 'test.cli' or read failure
+unable to open file 'test.ops' or read failure
EOE
: 004
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a a"b"c
-a "abc"
-a "a"b"
@@ -133,7 +133,7 @@ cat <<EOI >=test.cli;
-a '''
-a '"'
EOI
-$* --file test.cli >>"EOO"
+$* --file test.ops >>"EOO"
-a
a"b"c
-a
@@ -170,83 +170,118 @@ EOO
: 005
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a "
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument '"'
EOE
: 006
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a "abc
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument '"abc'
EOE
: 007
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a abc"
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument 'abc"'
EOE
: 008
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a '
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument '''
EOE
: 009
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a 'abc
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument ''abc'
EOE
: 010
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a abc'
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument 'abc''
EOE
: 011
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a "abc'
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument '"abc''
EOE
: 012
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
-a 'abc"
EOI
-$* --file test.cli 2>>EOE
+$* --file test.ops 2>>EOE
unmatched quote in argument ''abc"'
EOE
: quoted-argument
:
-cat <<EOI >=test.cli;
+cat <<EOI >=test.ops;
"'foo bar'"
'"foo bar"'
EOI
-$* --file test.cli >>EOO
+$* --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