aboutsummaryrefslogtreecommitdiff
path: root/testsuite/sed.tests
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-11-10 06:26:40 +0000
committerRob Landley <rob@landley.net>2005-11-10 06:26:40 +0000
commit990025a7d971bbbdd982d2d070d3e47628d0fac0 (patch)
tree21e56ca95118f3874f7a889c285921377df47552 /testsuite/sed.tests
parentecfd1f6a350c91bd2b562cd3d04c160a54debc61 (diff)
downloadbusybox-w32-990025a7d971bbbdd982d2d070d3e47628d0fac0.tar.gz
busybox-w32-990025a7d971bbbdd982d2d070d3e47628d0fac0.tar.bz2
busybox-w32-990025a7d971bbbdd982d2d070d3e47628d0fac0.zip
Ok, I've converted the contents of the "testing/sed" directory into a
sed.tests file. My brain hurts now. (Lots of boggling at sed minutiae and corner cases and going "why is gnu giving that output". The behavior of N and n with regard to EOF are only understandable if you read the Open Group spec, not if you read the sed info page, by the way...) Some of the existing sed tests are just nuts. For example, sed-next-line is testing for our behavior (which is wrong), and would fail if run against gnu sed (which was getting it right. Again, this was a spec-boggling moment, with much head scratching. I've got to add a debug mode where the stuff output by the p command is a different color from the stuff output by normal end of script printing (when not suppressed by -n).) As for sed-handles-unsatisifed-backrefs: what is this test trying to _do_? I ran it against gnu sed and got an error message, and this behavior sounds perfectly reasonable. (It _is_ an unsatisfied backref.) The fact we currently ignore this case (and treat \1 as an empty string) isn't really behavior we should have a test depend on for success. The remaining one is sed-aic-commands, which is long and complicated. I'm trying to figure out if I should chop this into a number of smaller tests, or if having one big "does-many-things" test is a good idea. In any case, the _next_ step is to go through the Open Group standard and make tests for every case not yet covered. (And there are plenty. There are few comments in the file already.) Plus I have notes about corner cases from development that I need to collate and put into here. This file is maybe the first 1/3 of a truly comprehensive sed test. Rob
Diffstat (limited to 'testsuite/sed.tests')
-rwxr-xr-xtestsuite/sed.tests109
1 files changed, 109 insertions, 0 deletions
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
new file mode 100755
index 000000000..479dd9ae7
--- /dev/null
+++ b/testsuite/sed.tests
@@ -0,0 +1,109 @@
1#!/bin/sh
2
3# SUSv3 compliant sed tests.
4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details.
6
7[ -z "$COMMAND" ] && COMMAND=sed
8. testing.sh
9
10# testing "description" "arguments" "result" "infile" "stdin"
11
12# Corner cases
13testing "sed as cat" '"" -' "hello\n" "" "hello\n"
14testing "sed handles empty lines" "-e 's/\$/@/'" "@\n" "" "\n"
15
16# no files (stdin)
17# explicit stdin
18# mix files and stdin (various orders)
19# list stdin twice
20# Trailing EOF.
21# Multiple files: first no EOF, second length 0.
22# Match $, at end of each file or all files?
23# First no EOF, second no matches at all.
24# -e corner cases
25# without -e
26# multiple -e
27# interact with a
28# -eee arg1 arg2 arg3
29# -f corner cases
30# -e -f -e
31# -n corner cases
32# no newline at EOF?
33# -r corner cases
34# Just make sure it works.
35# -i corner cases:
36# sed -i -
37# permissions
38# -i on a symlink
39# on a directory
40
41# command list
42testing "sed accepts blanks before command" "-e '1 d'" "" "" ""
43testing "sed accepts newlines in -e" "-e 'i\
441
45a\
463'" "1\n2\n3\n" "" "2\n"
47testing "sed accepts multiple -e" "-e 'i\' -e '1' -e 'a\' -e '3'" \
48 "1\n2\n3\n" "" "2\n"
49
50# substitutions
51testing "sed -n" "-n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n"
52testing "sed s//p" "-e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \
53 "" "foo\n"
54testing "sed -n s//p" "-ne s/abc/def/p" "def\n" "" "abc\n"
55testing "sed s//g (exhaustive)" "-e 's/[[:space:]]*/,/g'" ",1,2,3,4,5,\n" \
56 "" "12345\n"
57testing "sed s arbitrary delimiter" "-e 's woo boing '" "boing\n" "" "woo\n"
58testing "sed s chains" "-e s/foo/bar/ -e s/bar/baz/" "baz\n" "" "foo\n"
59testing "sed s chains2" "-e s/foo/bar/ -e s/baz/nee/" "bar\n" "" "foo\n"
60testing "sed s [delimiter]" "-e 's@[@]@@'" "onetwo" "" "one@two"
61
62# branch
63testing "sed b (branch)" "-e 'b one;p;: one'" "foo\n" "" "foo\n"
64testing "sed b (branch with no label jumps to end)" "-e 'b;p'" \
65 "foo\n" "" "foo\n"
66
67# test and branch
68testing "sed t (test/branch)" "-e 's/a/1/;t one;p;: one;p'" \
69 "1\n1\nb\nb\nb\nc\nc\nc\n" "" "a\nb\nc\n"
70testing "sed t (test/branch clears test bit)" "-e 's/a/b/;:loop;t loop'" \
71 "b\nb\nc\n" "" "a\nb\nc\n"
72testing "sed T (!test/branch)" "-e 's/a/1/;T notone;p;: notone;p'" \
73 "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
74
75# Normal sed end-of-script doesn't print "c" because n flushed the pattern
76# space. If n hits EOF, pattern space is empty when script ends.
77# Query: how does this interact with no newline at EOF?
78testing "sed n (flushes pattern space, terminates early)" "-e 'n;p'" \
79 "a\nb\nb\nc\n" "" "a\nb\nc\n"
80# N does _not_ flush pattern space, therefore c is still in there @ script end.
81testing "sed N (doesn't flush pattern space when terminating)" "-e 'N;p'" \
82 "a\nb\na\nb\nc\n" "" "a\nb\nc\n"
83testing "sed address match newline" '"/b/N;/b\\nc/i woo"' "a\nwoo\nb\nc\nd\n" \
84 "" "a\nb\nc\nd\n"
85
86# Multiple lines in pattern space
87testing "sed N (stops at end of input) and P (prints to first newline only)" \
88 "-n 'N;P;p'" "a\na\nb\n" "" "a\nb\nc\n"
89
90# Hold space
91testing "sed G (append hold space to pattern space)" 'G' "a\n\nb\n\nc\n\n" \
92 "" "a\nb\nc\n"
93#testing "sed g/G (swap/append hold and patter space)"
94#testing "sed g (swap hold/pattern space)"
95
96testing "sed d ends script iteration" \
97 "-e '/ook/d;s/ook/ping/p;i woot'" "" "" "ook\n"
98testing "sed d ends script iteration (2)" \
99 "-e '/ook/d;a\' -e 'bang'" "woot\nbang\n" "" "ook\nwoot\n"
100
101# Ponder this a bit more, why "woo not found" from gnu version?
102#testing "sed doesn't substitute in deleted line" \
103# "-e '/ook/d;s/ook//;t woo;a bang;'" "bang" "" "ook\n"
104
105# This makes both seds very unhappy. Why?
106#testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \
107# "" "12345"
108
109exit $FAILCOUNT