M Makefile => Makefile +4 -0
@@ 249,4 249,8 @@ clean:
rm -f proto
rm -rf build
+tests: $(BIN)
+ sh t/run
+
.PHONY: all install uninstall dist sbase-box-install sbase-box-uninstall clean
+.PHONY: tests
A t/README => t/README +15 -0
@@ 0,0 1,15 @@
+sbase test suite
+================
+
+Test suite for sbase.
+
+Tests for each tool live in a directory in t/ named after the tool. Tests for
+ed live in t/ed.
+
+t/run runs all tests.
+
+t/run_t runs all tests for one tool. E.g. t/run_t t/ed runs all tests for ed.
+
+Tests names must match [0-9][0-9][0-9][0-9] and have the executable bit set.
+
+Tests return 1 if the test failed and return 2 in case of any other error.
A t/die => t/die +5 -0
@@ 0,0 1,5 @@
+die()
+{
+ printf "%s\n" "$1" >&2
+ exit 2
+}
A t/ed/0001 => t/ed/0001 +35 -0
@@ 0,0 1,35 @@
+#!/bin/sh
+
+# Test splitting lines with substitute command
+
+# The Open Group Base Specifications Issue 7, 2018 edition:
+# | Substitute Command
+# |
+# | Synopsis:
+# |
+# | (.,.)s/RE/replacement/flags
+# | [...]
+# | A line can be split by substituting a <newline> into it. The
+# | application shall ensure it escapes the <newline> in the
+# | replacement by preceding it by <backslash>.
+
+d=/tmp/$$
+mkdir $d || exit 2
+
+cat > "$d"/exp << 'EOF'
+foo
+bar
+EOF
+
+f="$d"/f
+echo foobar > "$f"
+
+./ed -s $f << 'EOF'
+s/bar/\
+&/
+w
+q
+EOF
+
+diff -u "$d"/exp $f || exit 1
+rm -r $d
A t/ed/0002 => t/ed/0002 +22 -0
@@ 0,0 1,22 @@
+#!/bin/sh
+
+# Test substitute with back-reference
+
+d=/tmp/$$
+mkdir $d || exit 2
+
+cat > "$d"/exp << 'EOF'
+barfoo
+EOF
+
+f="$d"/f
+echo foobar > "$f"
+
+./ed -s $f << 'EOF'
+s/\(foo\)\(bar\)/\2\1/
+w
+q
+EOF
+
+diff -u "$d"/exp $f || exit 1
+rm -r $d
A t/ed/0003 => t/ed/0003 +22 -0
@@ 0,0 1,22 @@
+#!/bin/sh
+
+# Test substitute with ampersand
+
+d=/tmp/$$
+mkdir $d || exit 2
+
+cat > "$d"/exp << 'EOF'
+foo&bar
+EOF
+
+f="$d"/f
+echo foobar > "$f"
+
+./ed -s $f << 'EOF'
+s/foo/&\&/
+w
+q
+EOF
+
+diff -u "$d"/exp $f || exit 1
+rm -r $d
A t/ed/0004 => t/ed/0004 +22 -0
@@ 0,0 1,22 @@
+#!/bin/sh
+
+# Test substitute with delimiter
+
+d=/tmp/$$
+mkdir $d || exit 2
+
+cat > "$d"/exp << 'EOF'
+foo/bar
+EOF
+
+f="$d"/f
+echo foobar > "$f"
+
+./ed -s $f << 'EOF'
+s/ob/o\/b/
+w
+q
+EOF
+
+diff -u "$d"/exp $f || exit 1
+rm -r $d
A t/run => t/run +18 -0
@@ 0,0 1,18 @@
+#!/bin/sh
+
+test x"$(basename "$PWD")" = xt && { cd .. || exit 2; }
+if test x"${PWD##*/}" != xsbase
+then
+ printf "%s\n" "Run from repo root" >&2
+ exit 2
+fi
+
+rv=0
+for d in t/*
+do
+ test -d "$d" || continue
+ test "$d" != t || continue
+ t/run_t "$d" || rv=1
+done
+
+exit $rv
A t/run_t => t/run_t +23 -0
@@ 0,0 1,23 @@
+#!/bin/sh
+
+test x"$(basename "$PWD")" = xt && { cd .. || exit 2; }
+if test x"${PWD##*/}" != xsbase
+then
+ printf "%s\n" "Run from repo root" >&2
+ exit 2
+fi
+
+. t/die
+test "$1" || die "Which test?"
+
+rv=0
+for f in "$1"/[0-9][0-9][0-9][0-9]*
+do
+ case $f in *.orig | *.rej) continue ;; esac
+ ./"$f"
+ r=$?
+ test $r -eq 2 && die "Failure in setup: $f"
+ test $r -eq 0 || rv=1
+done
+
+exit $rv