From 8c1e0035404050376350d5e9b9242f5d39a6b53e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 27 Jul 2019 17:28:27 +0200 Subject: Add support for direct file loading with argv_file_scanner --- tests/file/driver.cxx | 19 ++++++++-- tests/file/testscript | 103 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 84 insertions(+), 38 deletions(-) (limited to 'tests') 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 +#include #include #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. + // + // ---- + // --- + // + unique_ptr 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 <=empty.cli ++cat <=empty.ops # Empty options file. # EOI -+cat <=base.cli ++cat <=base.ops -a 21 -b 21 EOI @@ -23,7 +23,7 @@ EOI : 000 : -cat <=test.cli; +cat <=test.ops; -a 11 -b 11 -a 12 @@ -31,7 +31,7 @@ cat <=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 <=test.cli; +cat <=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 <=test.cli; +cat <=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 <=test.cli; +cat <=test.ops; -a a"b"c -a "abc" -a "a"b" @@ -133,7 +133,7 @@ cat <=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 <=test.cli; +cat <=test.ops; -a " EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument '"' EOE : 006 : -cat <=test.cli; +cat <=test.ops; -a "abc EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument '"abc' EOE : 007 : -cat <=test.cli; +cat <=test.ops; -a abc" EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument 'abc"' EOE : 008 : -cat <=test.cli; +cat <=test.ops; -a ' EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument ''' EOE : 009 : -cat <=test.cli; +cat <=test.ops; -a 'abc EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument ''abc' EOE : 010 : -cat <=test.cli; +cat <=test.ops; -a abc' EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument 'abc'' EOE : 011 : -cat <=test.cli; +cat <=test.ops; -a "abc' EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument '"abc'' EOE : 012 : -cat <=test.cli; +cat <=test.ops; -a 'abc" EOI -$* --file test.cli 2>>EOE +$* --file test.ops 2>>EOE unmatched quote in argument ''abc"' EOE : quoted-argument : -cat <=test.cli; +cat <=test.ops; "'foo bar'" '"foo bar"' EOI -$* --file test.cli >>EOO +$* --file test.ops >>EOO 'foo bar' "foo bar" EOO + +: direct-file-load +: +cat <=test.ops; +-f +-a 123 +EOI +$* --- test.ops >>EOO +-f +-a +123 +EOO + +: direct-file-empty +: +cat <=test.ops; +EOI +$* --- test.ops + +: direct-file-load-nested +: +cat <=test.ops; +-f +--file ../base.ops +-a 123 +EOI +$* ---- test.ops >>EOO +-f +-a +21 +-b +21 +-a +123 +EOO -- cgit v1.1