The test suite of the ed utility has five tests that fail because they
test for restrictions that aren't actually enforced by the program. The
README says that it's because POSIX requires that only a single address
be specified for the commands 'a', '=', 'i', 'k' and 'r'. However, I've
looked into the standard itself and couldn't find any trace of such a
restriction. This is what the latest version I could find of the
standard says:

       "Commands accept zero, one, or two addresses.
       If more than the required number of
       addresses are provided to a command that
       requires zero addresses, it shall be an
       error. Otherwise, if more than the required
       number of addresses are provided to a
       command, the addresses specified first shall
       be evaluated and then discarded until the
       maximum number of valid addresses remain,
       for the specified command."

I think this means that the current behavior (using the last address
and discarding the others) is what the standard actually requires, and
as such the five aforementioned tests and the notes that have been put
in the README are wrong and need to be fixed. I'm attaching a patch to
that effect. The new tests will verify that when more than a single
address is attached to the five aforementioned commands, only the last
address is used and no error is thrown. The 'ckscripts.sh' script has
also been adjusted. Previously, it exited with non-zero status if no
errors had been found, and with zero if there were errors. I kept the
previous behavior of not failing if there are errors while also fixing
the exit status if there were no errors. The output of a grep in the
makefile has been discarded as it duplicates what was output in the
'ckscripts.sh' script.


diff --git bin/ed/POSIX bin/ed/POSIX
index 1cd2afc352f..403ec15ac27 100644
--- bin/ed/POSIX
+++ bin/ed/POSIX
@@ -9,11 +9,7 @@ OMISSIONS
 ---------
 1) Locale(3) is not supported yet.
 
-2) For backwards compatibility, the POSIX rule that says a range of
-   addresses cannot be used where only a single address is expected has
-   been relaxed.
-
-3) To support the BSD `s' command (see extension [1] below),
+2) To support the BSD `s' command (see extension [1] below),
    substitution patterns cannot be delimited by numbers or the characters
    `r', `g' and `p'.  In contrast, POSIX specifies any character except
    space or newline can be used as a delimiter.
diff --git bin/ed/test/Makefile bin/ed/test/Makefile
index de3e737f7fb..788b74e036f 100644
--- bin/ed/test/Makefile
+++ bin/ed/test/Makefile
@@ -8,7 +8,7 @@ all: check
        @:
 
 check: build test
-       @if grep -h '\*\*\*' errs.o scripts.o; then :; else \
+       @if grep -h '\*\*\*' errs.o scripts.o >/dev/null; then :; else \
                echo "tests completed successfully."; \
        fi
 
diff --git bin/ed/test/README bin/ed/test/README
index 27ad28dd9f5..eb7f923d1c8 100644
--- bin/ed/test/README
+++ bin/ed/test/README
@@ -3,7 +3,7 @@ $NetBSD: README,v 1.8 1995/03/21 09:05:18 cgd Exp $
 
 The files in this directory with suffixes `.t', `.d', `.r' and `.err' are
 used for testing ed.  To run the tests, set the ED variable in the Makefile
-for the path name of the program to be tested (e.g., /bin/ed), and type
+to the path name of the program to be tested (e.g., /bin/ed), and type
 `make'.  The tests do not exhaustively verify POSIX compliance nor do
 they verify correct 8-bit or long line support.
 
@@ -21,13 +21,3 @@ which look like:
        *** The script u.ed exited abnormally ***
 or:
        *** Output u.o of script u.ed is incorrect ***
-
-The POSIX requirement that an address range not be used where at most
-a single address is expected has been relaxed in this version of ed.
-Therefore, the  following scripts  which test for compliance with this
-POSIX rule exit abnormally:
-a1-err.ed
-eq-err.ed
-i1-err.ed
-k1-err.ed
-r1-err.ed
diff --git bin/ed/test/a1.d bin/ed/test/a1.d
new file mode 100644
index 00000000000..92f337e977f
--- /dev/null
+++ bin/ed/test/a1.d
@@ -0,0 +1,5 @@
+line 1
+line 2
+line 3
+line 4
+line5
diff --git bin/ed/test/a1.r bin/ed/test/a1.r
new file mode 100644
index 00000000000..fe99e416286
--- /dev/null
+++ bin/ed/test/a1.r
@@ -0,0 +1,6 @@
+line 1
+line 2
+line 3
+line 4
+line5
+hello world
diff --git bin/ed/test/a1.err bin/ed/test/a1.t
similarity index 100%
rename from bin/ed/test/a1.err
rename to bin/ed/test/a1.t
diff --git bin/ed/test/ckscripts.sh bin/ed/test/ckscripts.sh
index b401a79058e..bdf2cf8b85b 100644
--- bin/ed/test/ckscripts.sh
+++ bin/ed/test/ckscripts.sh
@@ -35,4 +35,4 @@ for i in *.ed; do
        fi
 done >scripts.o 2>&1
 
-grep -h '\*\*\*' errs.o scripts.o
+grep -h '\*\*\*' errs.o scripts.o || exit 0
diff --git bin/ed/test/eq.d bin/ed/test/eq.d
new file mode 100644
index 00000000000..92f337e977f
--- /dev/null
+++ bin/ed/test/eq.d
@@ -0,0 +1,5 @@
+line 1
+line 2
+line 3
+line 4
+line5
diff --git bin/ed/test/eq.r bin/ed/test/eq.r
new file mode 100644
index 00000000000..92f337e977f
--- /dev/null
+++ bin/ed/test/eq.r
@@ -0,0 +1,5 @@
+line 1
+line 2
+line 3
+line 4
+line5
diff --git bin/ed/test/eq.err bin/ed/test/eq.t
similarity index 100%
rename from bin/ed/test/eq.err
rename to bin/ed/test/eq.t
diff --git bin/ed/test/i1.d bin/ed/test/i1.d
new file mode 100644
index 00000000000..92f337e977f
--- /dev/null
+++ bin/ed/test/i1.d
@@ -0,0 +1,5 @@
+line 1
+line 2
+line 3
+line 4
+line5
diff --git bin/ed/test/i1.r bin/ed/test/i1.r
new file mode 100644
index 00000000000..f40ab7d19ae
--- /dev/null
+++ bin/ed/test/i1.r
@@ -0,0 +1,6 @@
+line 1
+line 2
+line 3
+line 4
+hello world
+line5
diff --git bin/ed/test/i1.err bin/ed/test/i1.t
similarity index 100%
rename from bin/ed/test/i1.err
rename to bin/ed/test/i1.t
diff --git bin/ed/test/k1.d bin/ed/test/k1.d
new file mode 100644
index 00000000000..92f337e977f
--- /dev/null
+++ bin/ed/test/k1.d
@@ -0,0 +1,5 @@
+line 1
+line 2
+line 3
+line 4
+line5
diff --git bin/ed/test/k1.err bin/ed/test/k1.err
deleted file mode 100644
index eba1f3d8ff1..00000000000
--- bin/ed/test/k1.err
+++ /dev/null
@@ -1 +0,0 @@
-1,$ka
diff --git bin/ed/test/k1.r bin/ed/test/k1.r
new file mode 100644
index 00000000000..ecc3410a489
--- /dev/null
+++ bin/ed/test/k1.r
@@ -0,0 +1,5 @@
+line 2
+line 3
+hello world
+line 4
+line5
diff --git bin/ed/test/k1.t bin/ed/test/k1.t
new file mode 100644
index 00000000000..9d484f21c93
--- /dev/null
+++ bin/ed/test/k1.t
@@ -0,0 +1,5 @@
+1,3ka
+1d
+'aa
+hello world
+.
diff --git bin/ed/test/r1.err bin/ed/test/r1.err
deleted file mode 100644
index 269aa7cbcb8..00000000000
--- bin/ed/test/r1.err
+++ /dev/null
@@ -1 +0,0 @@
-1,$r r1.err
diff --git bin/ed/test/r4.d bin/ed/test/r4.d
new file mode 100644
index 00000000000..92f337e977f
--- /dev/null
+++ bin/ed/test/r4.d
@@ -0,0 +1,5 @@
+line 1
+line 2
+line 3
+line 4
+line5
diff --git bin/ed/test/r4.r bin/ed/test/r4.r
new file mode 100644
index 00000000000..fe99e416286
--- /dev/null
+++ bin/ed/test/r4.r
@@ -0,0 +1,6 @@
+line 1
+line 2
+line 3
+line 4
+line5
+hello world
diff --git bin/ed/test/r4.t bin/ed/test/r4.t
new file mode 100644
index 00000000000..c067049105a
--- /dev/null
+++ bin/ed/test/r4.t
@@ -0,0 +1,2 @@
+1,$r !echo hello world
+w r4.o

Reply via email to