diff options
author | xroche <xavier.roche@open.eurogiciel.org> | 2014-12-09 09:46:53 +0100 |
---|---|---|
committer | xroche <xavier.roche@open.eurogiciel.org> | 2014-12-09 09:46:53 +0100 |
commit | 05423b7d418fa33f4c812b8262c21f9401ee3a98 (patch) | |
tree | beda5326587188087152da3293fd1327a6d6c299 /tests | |
parent | 9331dfb4907377e5241cfecb67aac4a2a7617ca4 (diff) | |
download | toybox-05423b7d418fa33f4c812b8262c21f9401ee3a98.tar.gz toybox-05423b7d418fa33f4c812b8262c21f9401ee3a98.tar.bz2 toybox-05423b7d418fa33f4c812b8262c21f9401ee3a98.zip |
Imported Upstream version 0.5.1upstream/0.5.1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ls.test | 4 | ||||
-rw-r--r-- | tests/sed.test | 86 |
2 files changed, 90 insertions, 0 deletions
diff --git a/tests/ls.test b/tests/ls.test index d052f13..9866eb7 100644 --- a/tests/ls.test +++ b/tests/ls.test @@ -37,6 +37,10 @@ testing "ls softlink - long listing" "$IN && ls -l slink | awk '{ print \$NF }' "file1.txt\n" "" "" rm -f lstest/slink +ln -s /dev/null/nosuchfile lstest/nosuchfile +testing "ls with -d - broken softlink" "$IN && ls -d nosuchfile; $OUT" "nosuchfile\n" "" "" +rm -f lstest/nosuchfile + rm -rf lstest/* && mkdir -p lstest/dir1 && touch lstest/file1.txt testing "ls nested recursively" "$IN && ls -R; $OUT" \ ".:\ndir1\nfile1.txt\n\n./dir1:\n" "" "" diff --git a/tests/sed.test b/tests/sed.test new file mode 100644 index 0000000..2d019eb --- /dev/null +++ b/tests/sed.test @@ -0,0 +1,86 @@ +#!/bin/echo Run scripts/test.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing 'sed as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree" + +# Exploring the wonders of sed addressing modes +testing '' 'sed -n 1p' "one\n" "" "one\ntwo\nthree" +testing '' 'sed 2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree" +testing '' 'sed -n 2p' "two\n" "" "one\ntwo\nthree" +testing 'sed -n $p' 'sed -n \$p' "three" "" "one\ntwo\nthree" +testing 'sed as cat #2' "sed -n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree" +testing 'no input means no last line' "sed '\$a boing'" "" "" "" +testing 'sed -n $,$p' 'sed -n \$,\$p' 'three' '' 'one\ntwo\nthree' +testing '' 'sed -n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree" +testing '' 'sed -n 2,3p' "two\nthree" "" "one\ntwo\nthree" +testing '' 'sed -n 2,1p' "two\n" "" "one\ntwo\nthree" +testing 'sed $ with 2 inputs' 'sed -n \$p - input' "four\n" "four\n" \ + "one\ntwo\nthree" +testing '' 'sed -n /two/p' "two\n" "" "one\ntwo\nthree" +testing '' 'sed -n 1,/two/p' 'one\ntwo\n' '' 'one\ntwo\nthree' +testing '' 'sed -n /one/,2p' 'one\ntwo\n' '' 'one\ntwo\nthree' +testing '' 'sed -n 1,/one/p' 'one\ntwo\nthree' '' 'one\ntwo\nthree' +testing '' 'sed -n /one/,1p' 'one\n' '' 'one\ntwo\nthree' +testing 'sed -n /two/,$p' 'sed -n /two/,\$p' 'two\nthree' '' 'one\ntwo\nthree' + + +# Fun with newlines! +testing '' 'sed -n 3p' "three" "" "one\ntwo\nthree" +testing 'prodigal newline' "sed -n '1,\$p' - input" "one\ntwo\nthree\nfour\n" \ + "four\n" "one\ntwo\nthree" +testing 'Newline only added if further output' "sed -n 3p - input" "three" \ + "four\n" "one\ntwo\nthree" + +# Fun with match delimiters and escapes +testing 'sed match \t tab' "sed -n '/\t/p'" "\tx\n" "" "\tx\n" +testing 'sed match t delim disables \t tab' "sed -n '\t\txtp'" "" "" "\tx\n" +testing 'sed match t delim makes \t literal t' \ + "sed -n '\t\txtp'" "tx\n" "" "tx\n" +testing 'sed match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n" +testing 'sed match n delim disables \n newline' "sed -n '\n\nxnp'" "" "" "\nx\n" +SKIP_HOST=1 testing 'sed match \n literal n' "sed -n '\n\nxnp'" "nx\n" "" "nx\n" +testing 'end match does not check starting match line' \ + "sed -n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree" +testing 'end match/start match mixing number/letter' \ + "sed -n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree" +testing 'sed num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' +testing 'sed regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' +testing 'sed multiple regex address match' 'sed -n /on/,/off/p' \ + 'bone\nturtle\scoff\ntron\nlurid\noffer\n' "" \ + 'zap\nbone\nturtle\scoff\nfred\ntron\nlurid\noffer\nbecause\n' +testing 'sed regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \ + 'on\nzap\noffon\nping\noff\n' + +testing "sed aci" \ + "sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \ + "one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \ + "one\ntwo\nthree\nfour\n" +testing 'sed prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one' +testing 'sed newline staying away' 'sed s/o/x/' 'xne\ntwx' '' 'one\ntwo' +# Why on _earth_ is this not an error? There's a \ with no continuation! +testing 'sed what, _really_?' 'sed -e a\\ && echo yes really' \ + 'one\nyes really\n' '' 'one\n' + +# all the s/// test + + +testing 'sed \1' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy\nthree" "" \ + "one\ntwo\nthree" +testing 'sed \1 p' "sed 's/t\\(w\\)o/za\\1py/p'" "one\nzawpy\nzawpy\nthree" \ + "" "one\ntwo\nthree" +testing 'sed \1 no newline' "sed 's/t\\(w\\)o/za\\1py/'" "one\nzawpy" "" \ + "one\ntwo" +testing 'sed \1 p no newline' "sed 's/t\\(w\\)o/za\\1py/p'" \ + "one\nzawpy\nzawpy" "" "one\ntwo" +testing 'sed -n s//\1/p' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" "" "one\ntwo" +testing 'sed -n s//\1/p no newline' "sed -n 's/t\\(w\\)o/za\\1py/p'" "zawpy" \ + "" "one\ntwo" +testing 'sed backref error' \ + "sed 's/w/ale \2 ha/' >/dev/null 2>/dev/null || echo no" \ + "no\n" "" "one\ntwo\nthree" +testing 'sed empty match after nonempty match' "sed -e 's/a*/c/g'" 'cbcncgc' \ + '' 'baaang' +testing 'sed empty match' "sed -e 's/[^ac]*/A/g'" 'AaAcA' '' 'abcde' +testing 'sed s///#' "sed -e 's/TWO/four/i#comment'" "one\nfour\nthree" \ + "" "one\ntwo\nthree" |