diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-01-11 01:43:09 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-01-19 17:56:07 +0300 |
commit | a83f3866667bca073c4d4c5d80b4deb5ac05906c (patch) | |
tree | 479464203f6be4535c8f165a20d21322a88a2751 /unit-tests/test | |
parent | ba99b60aeb8ccdeffc777589b99728395cd28f95 (diff) |
Add support for portable path modifer and dot character escaping inversion
Diffstat (limited to 'unit-tests/test')
-rw-r--r-- | unit-tests/test/script/parser/driver.cxx | 7 | ||||
-rw-r--r-- | unit-tests/test/script/parser/redirect.test | 76 | ||||
-rw-r--r-- | unit-tests/test/script/parser/regex.test | 115 | ||||
-rw-r--r-- | unit-tests/test/script/regex/driver.cxx | 63 |
4 files changed, 198 insertions, 63 deletions
diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx index 271fd2c..f641dc4 100644 --- a/unit-tests/test/script/parser/driver.cxx +++ b/unit-tests/test/script/parser/driver.cxx @@ -189,6 +189,13 @@ namespace build2 string (), trace)); + value& v ( + tt.assign ( + var_pool.insert<target_triplet> ( + "test.target", variable_visibility::project))); + + v = cast<target_triplet> ((*global_scope)["build.host"]); + testscript& st ( targets.insert<testscript> (work, dir_path (), diff --git a/unit-tests/test/script/parser/redirect.test b/unit-tests/test/script/parser/redirect.test index 5a91354..3db684a 100644 --- a/unit-tests/test/script/parser/redirect.test +++ b/unit-tests/test/script/parser/redirect.test @@ -6,6 +6,82 @@ # @@ Does it make sense to split into separate files - one per redirect type? # +: str +: +{ + : literal + : + { + : portable-path + : + $* <<EOI >>EOO + cmd </foo >/bar 2>/baz + EOI + cmd </foo >/bar 2>/baz + EOO + } + + : regex + : + { + : portable-path + : + $* <<EOI >>EOO + cmd >/~%foo% 2>/~%bar% + EOI + cmd >/~%foo% 2>/~%bar% + EOO + } +} + +: doc +: +{ + : literal + : + { + : portable-path + : + $* <<EOI >>EOO + cmd <</EOI_ >/EOO_ 2>/EOE_ + foo + EOI_ + bar + EOO_ + baz + EOE_ + EOI + cmd <</EOI_ >/EOO_ 2>/EOE_ + foo + EOI_ + bar + EOO_ + baz + EOE_ + EOO + } + + : regex + : + { + : portable-path + : + $* <<EOI >>EOO + cmd >/~%EOF% 2>/~%EOE% + foo + EOF + bar + EOE + EOI + cmd >/~%EOF% 2>/~%EOE% + foo + EOF + bar + EOE + EOO + } +} + : file : { diff --git a/unit-tests/test/script/parser/regex.test b/unit-tests/test/script/parser/regex.test index f9101c9..058a5bc 100644 --- a/unit-tests/test/script/parser/regex.test +++ b/unit-tests/test/script/parser/regex.test @@ -26,12 +26,30 @@ testscript:1:7: error: no closing introducer character in stdout regex redirect EOE + : portable-path-introducer + : + $* <'cmd >/~/foo/' 2>>EOE != 0 + testscript:1:8: error: portable path modifier and '/' introducer in stdout regex redirect + EOE + : empty : $* <'cmd >~//' 2>>EOE != 0 testscript:1:7: error: stdout regex redirect is empty EOE + : no-flags + : + $* <'cmd >~/fo*/' >'cmd >~/fo*/' + + : idot + : + $* <'cmd >~/fo*/d' >'cmd >~/fo*/d' + + : icase + : + $* <'cmd >~/fo*/i' >'cmd >~/fo*/i' + : invalid-flags1 : $* <'cmd >~/foo/z' 2>>EOE != 0 @@ -44,24 +62,6 @@ testscript:1:7: error: junk at the end of stdout regex redirect EOE - : malformed - : - : Note that old versions of libc++ (for example 1.1) do not detect some - : regex errors. For example '*' is parsed successfully. - : - $* <'cmd >~/foo[/' 2>>~/EOE/ != 0 - /testscript:1:7: error: invalid stdout regex redirect.*/ - info: regex: /foo[/ - EOE - - : without-flags - : - $* <'cmd >~/fo*/' >'cmd >~/fo*/' - - : with-flags - : - $* <'cmd >~/fo*/i' >'cmd >~/fo*/i' - : no-newline : $* <'cmd >:~/fo*/' >'cmd >:~/fo*/' @@ -106,46 +106,24 @@ testscript:1:8: error: expected here-document regex end marker EOE - : unterminated-line-char + : portable-path-introducer : $* <<EOI 2>>EOE != 0 - cmd >>~/EOO/ - / + cmd >>/~/EOO/ + foo EOO EOI - testscript:2:1: error: regex introducer without regex - info: consider changing regex introducer '/' in here-document end marker + testscript:1:5: error: portable path modifier and '/' introducer in here-document regex end marker EOE - : invalid-syntax-char + : unterminated-line-char : $* <<EOI 2>>EOE != 0 cmd >>~/EOO/ - /x - EOO - EOI - testscript:2:1: error: invalid line-regex syntax character 'x' - EOE - - : invalid-char-regex - : - $* <<EOI 2>>~/EOE/ != 0 - cmd >>~/EOO/ - /foo[/ - EOO - EOI - /testscript:2:1: error: invalid regex.*/ - EOE - - : invalid-line-regex - : - $* <<EOI 2>>~/EOE/ != 0 - cmd >>~/EOO/ - a - /{ + / EOO EOI - /testscript:4:1: error: invalid here-document regex.*/ + testscript:2:1: error: no syntax line characters EOE : empty @@ -157,7 +135,7 @@ testscript:2:1: error: empty here-document regex EOE - : valid + : no-flags : $* <<EOI >>EOO cmd 2>>~/EOE/ @@ -184,6 +162,47 @@ //* EOE EOO + + : no-newline + : + $* <'cmd >:~/fo*/' >'cmd >:~/fo*/' + $* <<EOI >>EOO + cmd 2>>:~/EOE/ + foo + EOE + EOI + cmd 2>>:~/EOE/ + foo + EOE + EOO + + : end-marker-restore + : + { + : idot + : + $* <<EOI >>EOO + cmd 2>>~/EOE/d + foo + EOE + EOI + cmd 2>>~/EOE/d + foo + EOE + EOO + + : icase + : + $* <<EOI >>EOO + cmd 2>>~/EOE/i + foo + EOE + EOI + cmd 2>>~/EOE/i + foo + EOE + EOO + } } : stderr diff --git a/unit-tests/test/script/regex/driver.cxx b/unit-tests/test/script/regex/driver.cxx index 6ff4d75..2680672 100644 --- a/unit-tests/test/script/regex/driver.cxx +++ b/unit-tests/test/script/regex/driver.cxx @@ -16,6 +16,8 @@ main () using lc = line_char; using ls = line_string; using lr = line_regex; + using cf = char_flags; + using cr = char_regex; // Test line_char. // @@ -54,7 +56,7 @@ main () assert (lc ('0') != '1'); assert (lc ('n') != mp); assert (lc ('0') != lc ("0", p)); - assert (lc ('0') != lc (regex ("0"), p)); + assert (lc ('0') != lc (cr ("0"), p)); assert (lc ('0') < lc ('1')); assert (lc ('0') < '1'); @@ -77,24 +79,54 @@ main () assert (char (lc ("a", p)) == '\a'); assert (lc ("a", p) != lc ("b", p)); - assert (!(lc ("a", p) != lc (regex ("a"), p))); // Matches. - assert (lc ("a", p) != lc (regex ("b"), p)); + assert (!(lc ("a", p) != lc (cr ("a"), p))); + assert (lc ("a", p) != lc (cr ("b"), p)); assert (lc ("a", p) < lc ("b", p)); - assert (!(lc ("a", p) < lc (regex ("a"), p))); // Matches. + assert (!(lc ("a", p) < lc (cr ("a"), p))); assert (lc ("a", p) <= lc ("b", p)); - assert (lc ("a", p) <= lc (regex ("a"), p)); - assert (lc ("a", p) < lc (regex ("c"), p)); + assert (lc ("a", p) <= lc (cr ("a"), p)); + assert (lc ("a", p) < lc (cr ("c"), p)); // Regex roundtrip. // - assert (regex_match ("abc", *lc (regex ("abc"), p).regex ())); + assert (regex_match ("abc", *lc (cr ("abc"), p).regex ())); + + // Regex flags. + // + // icase + // + assert (regex_match ("ABC", cr ("abc", cf::icase))); + + // idot + // + assert (!regex_match ("a", cr ("[.]", cf::idot))); + assert (!regex_match ("a", cr ("[\\.]", cf::idot))); + + assert (regex_match ("a", cr ("."))); + assert (!regex_match ("a", cr (".", cf::idot))); + assert (regex_match ("a", cr ("\\.", cf::idot))); + assert (!regex_match ("a", cr ("\\."))); + + // regex::transform() + // + // The function is static and we can't test it directly. So we will test + // it indirectly via regex matches. + // + // @@ Would be nice to somehow address the inability to test internals (not + // exposed via headers). As a part of utility library support? + // + assert (regex_match (".a[.", cr (".\\.\\[[.]", cf::idot))); + assert (regex_match (".a[.", cr (".\\.\\[[\\.]", cf::idot))); + assert (!regex_match ("ba[.", cr (".\\.\\[[.]", cf::idot))); + assert (!regex_match (".a[b", cr (".\\.\\[[.]", cf::idot))); + assert (!regex_match (".a[b", cr (".\\.\\[[\\.]", cf::idot))); // Regex comparison. // - assert (lc ("a", p) == lc (regex ("a|b"), p)); - assert (lc (regex ("a|b"), p) == lc ("a", p)); + assert (lc ("a", p) == lc (cr ("a|b"), p)); + assert (lc (cr ("a|b"), p) == lc ("a", p)); } // Test char_traits<line_char>. @@ -159,7 +191,7 @@ main () const ct& t (use_facet<ct> (l)); line_pool p; - assert (t.is (ct::digit, '0')); + assert (t.is (ct::digit, '0')); assert (!t.is (ct::digit, '?')); assert (!t.is (ct::digit, lc ("0", p))); @@ -216,7 +248,7 @@ main () // { line_pool p; - lr r1 ({lc ("foo", p), lc (regex ("ba(r|z)"), p)}, move (p)); + lr r1 ({lc ("foo", p), lc (cr ("ba(r|z)"), p)}, move (p)); lr r2 (move (r1)); assert (regex_match (ls ({lc ("foo", r2.pool), lc ("bar", r2.pool)}), r2)); @@ -239,11 +271,12 @@ main () assert (regex_match (ls ({bar, foo}), lr ({'(', foo, '|', bar, ')', '+'}))); - assert (regex_match (ls ({foo, foo}), lr ({'(', foo, ')', '\\', '1'}))); + assert (regex_match (ls ({foo, foo, bar}), + lr ({'(', foo, ')', '\\', '1', bar}))); - assert (regex_match (ls ({foo}), lr ({lc (regex ("fo+"), p)}))); - assert (regex_match (ls ({foo}), lr ({lc (regex (".*"), p)}))); - assert (regex_match (ls ({blank}), lr ({lc (regex (".*"), p)}))); + assert (regex_match (ls ({foo}), lr ({lc (cr ("fo+"), p)}))); + assert (regex_match (ls ({foo}), lr ({lc (cr (".*"), p)}))); + assert (regex_match (ls ({blank}), lr ({lc (cr (".*"), p)}))); assert (regex_match (ls ({blank, blank, foo}), lr ({blank, '*', foo, blank, '*'}))); |