From 5007870b52aa549971824959a55ad3bb886f09e0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Sep 2018 16:37:32 +0200 Subject: Rename .test/test{} to .testscript/testscript{} --- tests/test/script/runner/regex.testscript | 312 ++++++++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 tests/test/script/runner/regex.testscript (limited to 'tests/test/script/runner/regex.testscript') diff --git a/tests/test/script/runner/regex.testscript b/tests/test/script/runner/regex.testscript new file mode 100644 index 0000000..46b1872 --- /dev/null +++ b/tests/test/script/runner/regex.testscript @@ -0,0 +1,312 @@ +# file : tests/test/script/runner/regex.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Here we test that regex objects are properly created by the parser/runner +# venture. The unit test approach is not of much use as regex object is not +# serializable back to string. The only way we can test their proper creation +# is via matching. +# +# Note that such a tests are separated from ones that check regex matching +# specifically (in particular matching failures), The latest ones are located +# in redirect.testscript. +# +# Also note that the following tests are grouped by features: basic +# functionality, flags, portable-path modifier. +# + +.include ../common.testscript + +: basic +: +{ + : str + : + { + $c <'cat ~/fo./' && $b : out + $c <'cat &2 2>~/fo./' && $b : err + $c <'cat <:foo >:~/fo./' && $b : no-newline + + : malformed + : + : Note that old versions of libc++ (for example 1.1) do not detect some + : regex errors. For example '*' is parsed successfully. + : + $c <'cat ~/foo[/' && $b 2>>~/EOE/ != 0 + /testscript:1:12: error: invalid stdout regex redirect.*/ + info: regex: '/foo[/' + EOE + + : no-match + : + $c <'cat ~/bar/' && $b 2>>/EOE != 0 + testscript:1:1: error: cat stdout doesn't match regex + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + foo + EOE + } + + : doc + : + { + : out + : + $c <>~/EOO/ + /foo/ + EOO + EOI + + : err + : + $c <&2 2>>~/EOO/ + /fo./ + EOO + EOI + + : no-newline + : + $c <>:~/EOO/ + /fo./ + EOO + EOI + + : line-char + : + $c <>~/EOO/ + foo + bar + baz + baz + Biz + Fox + fox + + + + + EOF + foo + /? + /bar/ + /baz/+ + /biz/i + /fox/i+ + + // + //{2} + EOO + EOI + + : expansion + : + $c <>~"/EOO/" + foo + bar + + baz + EOF + /f$(s) + baz + EOO + EOI + + : invalid-syntax-char + : + $c <>EOE != 0 + cat >~/EOO/ + /x + EOO + EOI + testscript:2:1: error: invalid syntax character 'x' in stdout regex redirect + info: regex line: '/x' + EOE + + : invalid-char-regex + : + $c <>~/EOE/ != 0 + cat >~/EOO/ + /foo[/ + EOO + EOI + /testscript:2:1: error: invalid char-regex in stdout regex redirect.*/ + info: regex line: '/foo[/' + EOE + + : invalid-line-regex + : + $c <>/~%EOE% != 0 + cat >~/EOO/ + a + /{ + EOO + EOI + %testscript:4:1: error: invalid stdout regex redirect.*% + info: stdout regex: test/1/stdout.regex + EOE + + : no-match + : + { + : leading-blank + : + $c <>/EOE != 0 + cat >~/EOO/ + + foo + EOO + EOI + testscript:1:1: error: cat stdout doesn't match regex + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + foo + EOE + } + } +} + +:flags +: +{ + : str + : + { + : i + : + $c <'cat ~/foo/i' && $b + + : d + : + { + : escaped-dot + : + : Escaped dot becomes syntax dot and matches any character ('i' in our + : case). + : + $c <'cat ~/f\\.o/d' && $b + + : syntax-dot + : + : Syntax dot becomes escaped dot and matches only '.' and so we fail. + : + $c <'cat ~/f.o/d' && $b 2>>~/EOE/ != 0 + testscript:1:1: error: cat stdout doesn't match regex + /.+ + EOE + } + } + + : doc + { + : i + : + $c <>~/EOO/ + /foo/i + EOO + EOI + + : d + : + : All the reasonings for the /flags/str/d test group are valid for the + : current one. + : + { + : escaped-dot + : + $c <>~/EOO/ + /f\.o/d + EOO + EOI + + : syntax-dot + : + $c <>~/EOE/ != 0 + cat >~/EOO/ + /f.o/d + EOO + EOI + testscript:1:1: error: cat stdout doesn't match regex + /.+ + EOE + } + + : global + : + { + : i + : + $c <>~/EOO/i + /foo/ + EOO + EOI + + : d + : + { + : escaped-dot + : + $c <>~/EOO/d + /f\.o/ + EOO + EOI + + : syntax-dot + : + $c <>~/EOE/ != 0 + cat >~/EOO/d + /f.o/ + EOO + EOI + testscript:1:1: error: cat stdout doesn't match regex + /.+ + EOE + } + } + } +} + +: portable-path +: +{ + ps = ($cxx.target.class != 'windows' ? '/' : '\') + + : str + : + { + $c <"cat <'foo$ps' >/~%foo/%" && $b : out + $c <"cat <'foo$ps' 1>&2 2>/~%foo/%" && $b : err + } + + : doc + { + : out + : + $c <<"EOI" && $b + cat <'foo$ps' >>/~%EOO% + foo/ + EOO + EOI + + : err + : + $c <<"EOI" && $b + cat <'foo$ps' 1>&2 2>>/~%EOO% + foo/ + EOO + EOI + } +} -- cgit v1.1