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/builtin/sed.testscript | 333 +++++++++++++++++++++++++++++++ 1 file changed, 333 insertions(+) create mode 100644 tests/test/script/builtin/sed.testscript (limited to 'tests/test/script/builtin/sed.testscript') diff --git a/tests/test/script/builtin/sed.testscript b/tests/test/script/builtin/sed.testscript new file mode 100644 index 0000000..9db7cb4 --- /dev/null +++ b/tests/test/script/builtin/sed.testscript @@ -0,0 +1,333 @@ +# file : tests/test/script/builtin/sed.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +: arg +: +{ + : auto-prn + : + { + $c <"sed -n -e 's/fox/bar/' <'foo' " && $b : on + $c <"sed -e 's/fox/bar/' <'foo' >'foo'" && $b : off + } + + : script + : + { + : missed + : + $c <'sed' && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: missing script + EOE + + : missed-val + : + $c <'sed -e' && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: missing script + EOE + + : empty + : + $c <"sed -e ''" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: empty script + EOE + + : multiple + : + $c <"sed -e 's/a//' -e 's/a//'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: multiple scripts + EOE + + : invalid + : + $c <"sed -e 'z'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: only 's' command supported + EOE + } + + : file + : + { + : exist + : + $c <=f; + sed -e 's/foo/bar/' f >'bar' + EOI + + : none + : + $c <'bar' + EOI + + : dash + : + $c <'bar' + EOI + + : not-exist + : + $c <"sed -e 's/foo/bar/' f" && $b 2>>/~%EOE% != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + %sed: unable to edit '.+/1/f': .+% + EOE + + : empty + : + $c <"sed -e 's/foo/bar/' ''" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: invalid path '' + EOE + } + + : unexpected + : + $c <"sed -e 's/a//' a b" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: unexpected argument + EOE +} + +: command +: +{ + : subst + : + { + : parsing + : + { + : delim + : + { + : none + : + $c <"sed -e 's'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: no delimiter for 's' command + EOE + + : invalid + : + $c <"sed -e 's\\'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: invalid delimiter for 's' command + EOE + } + + : regex + : + { + : unterminated + : + $c <"sed -e 's/foo'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: unterminated 's' command regex + EOE + + : empty + : + $c <"sed -e 's///'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: empty regex in 's' command + EOE + + : invalid + : + : Note that old versions of libc++ (for example 1.1) do not detect some + : regex errors. For example '*' is parsed successfully. + : + $c <"sed -e 's/foo[/bar/'" && $b 2>>/~%EOE% != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + %sed: invalid regex.*% + EOE + } + + : unterminated-replacement + : + $c <"sed -e 's/foo/bar'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: unterminated 's' command replacement + EOE + + : invalid-flags + : + $c <"sed -e 's/foo/bar/a'" && $b 2>>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: invalid 's' command flag 'a' + EOE + } + + : exec + : + { + : flags + : + { + : global + : + { + $c <"sed -e 's/o/a/g' <'foo' >'faa'" && $b : on + $c <"sed -e 's/o/a/' <'foo' >'fao'" && $b : off + } + + : icase + : + { + $c <"sed -e 's/O/a/i' <'foo' >'fao'" && $b : on + $c <"sed -e 's/O/a/' <'foo' >'foo'" && $b : off + } + + : print + : + { + $c <"sed -n -e 's/o/a/p' <'foo' >'fao'" && $b : on-match + $c <"sed -n -e 's/o/a/' <'foo' " && $b : off-match + $c <"sed -n -e 's/u/a/p' <'foo' " && $b : on-no-match + } + } + + : search + { + : anchor + : + { + $c <"sed -n -e 's/^o/a/gp' <'oof' >'aof'" && $b : begin + $c <"sed -n -e 's/o\$/a/gp' <'foo' >'foa'" && $b : end + } + + : match + : Match corner cases + : + { + $c <"sed -n -e 's/a/b/p' <'a' >'b' " && $b : full + $c <"sed -n -e 's/a/b/p' <'ac' >'bc' " && $b : left + $c <"sed -n -e 's/a/b/p' <'ca' >'cb' " && $b : right + $c <"sed -n -e 's/a/b/pg' <'xaax' >'xbbx'" && $b : adjacent + } + } + + : replacement + : + { + : ecma-escape + : + { + $c <"sed <'xay' -e 's/a/\$b/' >'x\$by'" && $b : none + $c <"sed <'xay' -e 's/a/\$/' >'x\$y' " && $b : none-term + $c <"sed <'xay' -e 's/a/\$\$/' >'x\$y' " && $b : self + $c <"sed <'xay' -e 's/a/b\$&c/' >'xbacy'" && $b : match + $c <"sed <'xay' -e 's/a/b\$`c/' >'xbxcy'" && $b : match-precede + $c <"sed <'xay' -e \"s/a/b\\\$'c/\" >'xbycy'" && $b : match-follow + + : capture + : + $c <'aj' + EOI + } + + : perl-escape + : + { + $c <"sed <'xay' -e 's/a/\\b/' >'xby' " && $b : none + $c <"sed <'xay' -e 's/a/\\/' >'xy' " && $b : none-term + $c <"sed <'xay' -e 's/a/\\\\/' >'x\\y'" && $b : self + + : capture + : + $c <'aa0' + EOI + + : upper + : + { + $c <"sed <'xay' -e 's/a/\\U/' >'xy' " && $b : none + $c <"sed <'xay' -e 's/a/\\Uvz/' >'xVZy'" && $b : repl + $c <"sed <'xay' -e 's/a/\\Uv\\Ez/' >'xVzy'" && $b : end + $c <"sed <'aa' -e 's/a/v\\Uz/g' >'vZvZ'" && $b : locality + $c <"sed <'xay' -e 's/\(a\)/\\U\\1/' >'xAy' " && $b : capt + $c <"sed <'x-y' -e 's/\(a?\)-/\\U\\1z/' >'xZy' " && $b : capt-empty + $c <"sed <'xay' -e 's/a/\\uvz/' >'xVzy'" && $b : once + } + + : lower + : + { + $c <"sed <'xay' -e 's/a/\\lVZ/' >'xvZy'" && $b : once + } + } + } + + $c <"sed -e 's/a//' <:'b' >'b'" && $b : no-newline + $c <"sed -e 's/a//' <:'' " && $b : empty-stdin + + : empty-file + : + $c <>/EOE != 0 + testscript:1:1: error: sed exit code 1 != 0 + info: stderr: test/1/stderr + sed: -i option specified while reading from stdin + EOE + + : edit + : + $c <=f; + sed -i -e 's/foo/bar/' f; + cat f >'bar' + EOI +} + +: big +: +: Sed a big file (about 100K) to test that the builtin is asynchronous. +: +{ + $c <"$s" + EOI +} -- cgit v1.1