# file : tests/test/script/runner/regex.test # copyright : Copyright (c) 2014-2017 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.test testscript. # # Also note that the following tests are grouped by features: basic # functionality, flags, portable-path modifier. # .include ../common.test : basic : { : str : { : out : $c <'cat ~/fo./'; $b : err : $c <'cat &2 2>~/fo./'; $b : no-newline : $c <'cat <:foo >:~/fo./'; $b : malformed : : Note that old versions of libc++ (for example 1.1) do not detect some : regex errors. For example '*' is parsed successfully. : $c <'$* -o foo >~/foo[/'; $b 2>>~/EOE/ != 0 /testscript:1:13: error: invalid stdout regex redirect.*/ info: regex: '/foo[/' EOE } : doc : { : out : $c <>~/EOO/ /foo/ EOO EOI $b : err : $c <&2 2>>~/EOO/ /fo./ EOO EOI $b : no-newline : $c <>:~/EOO/ /fo./ EOO EOI $b : line-char : $c <>~/EOO/ foo bar baz baz Biz Fox fox EOF foo /? /bar/ /baz/+ /biz/i /fox/i+ // //{2} EOO EOI $b : expansion : $c <>~"/EOO/" foo bar baz EOF /f$(s) baz EOO EOI $b : invalid-syntax-char : $c <>~/EOO/ /x EOO EOI $b 2>>EOE != 0 testscript:2:3: error: invalid syntax character 'x' in stdout regex redirect info: regex line: '/x' EOE : invalid-char-regex : $c <>~/EOO/ /foo[/ EOO EOI $b 2>>~/EOE/ != 0 /testscript:2:3: error: invalid char-regex in stdout regex redirect.*/ info: regex line: '/foo[/' EOE : invalid-line-regex : $c <>~/EOO/ a /{ EOO EOI $b 2>>/~%EOE% != 0 %testscript:4:3: error: invalid stdout regex redirect.*% info: stdout regex: test/1/stdout.regex 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 the regex /.+ EOE } } : doc { : i : $c <>~/EOO/ /foo/i EOO EOI $b : 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 $b : syntax-dot : $c <>~/EOO/ /f.o/d EOO EOI $b 2>>~/EOE/ != 0 testscript:1:1: error: cat stdout doesn't match the regex /.+ EOE } : global : { : i : $c <>~/EOO/i /foo/ EOO EOI $b : d : { : escaped-dot : $c <>~/EOO/d /f\.o/ EOO EOI $b : syntax-dot : $c <>~/EOO/d /f.o/ EOO EOI $b 2>>~/EOE/ != 0 testscript:1:1: error: cat stdout doesn't match the regex /.+ EOE } } } } : portable-path : { ps = ($cxx.target.class != 'windows' ? '/' : '\') : str : { : out : $c <"cat <'foo$ps' >/~%foo/%"; $b : err : $c <"cat <'foo$ps' >/~%foo/%"; $b } : doc { : out : $c <<"EOI"; cat <'foo$ps' >>/~%EOO% foo/ EOO EOI $b : err : $c <<"EOI"; cat <'foo$ps' >>/~%EOO% foo/ EOO EOI $b } }