Add printf(1) regression tests.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sun, 13 Feb 2011 10:46:49 +0000 (00:46 -1000)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 13 Feb 2011 10:46:49 +0000 (00:46 -1000)
Obtained-from: FreeBSD

13 files changed:
tools/regression/usr.bin/printf/Makefile [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.b.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.d.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.f.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.m1.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.m2.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.m3.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.m4.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.m5.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.s.out [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.sh [new file with mode: 0644]
tools/regression/usr.bin/printf/regress.t [new file with mode: 0644]
tools/regression/usr.bin/regress.m4 [new file with mode: 0644]

diff --git a/tools/regression/usr.bin/printf/Makefile b/tools/regression/usr.bin/printf/Makefile
new file mode 100644 (file)
index 0000000..e2def90
--- /dev/null
@@ -0,0 +1,4 @@
+# $FreeBSD: src/tools/regression/usr.bin/printf/Makefile,v 1.1 2005/04/13 20:08:17 stefanf Exp $
+
+all:
+       @m4 ${.CURDIR}/../regress.m4 ${.CURDIR}/regress.sh | sh /dev/stdin ${.CURDIR}
diff --git a/tools/regression/usr.bin/printf/regress.b.out b/tools/regression/usr.bin/printf/regress.b.out
new file mode 100644 (file)
index 0000000..0373d93
--- /dev/null
@@ -0,0 +1 @@
+abcdef
diff --git a/tools/regression/usr.bin/printf/regress.d.out b/tools/regression/usr.bin/printf/regress.d.out
new file mode 100644 (file)
index 0000000..da83c08
--- /dev/null
@@ -0,0 +1 @@
+123,  123,00123,00123,00123
diff --git a/tools/regression/usr.bin/printf/regress.f.out b/tools/regression/usr.bin/printf/regress.f.out
new file mode 100644 (file)
index 0000000..127cb8a
--- /dev/null
@@ -0,0 +1 @@
+42.250000,-42.250 ,inf,nan
diff --git a/tools/regression/usr.bin/printf/regress.m1.out b/tools/regression/usr.bin/printf/regress.m1.out
new file mode 100644 (file)
index 0000000..a9e063e
Binary files /dev/null and b/tools/regression/usr.bin/printf/regress.m1.out differ
diff --git a/tools/regression/usr.bin/printf/regress.m2.out b/tools/regression/usr.bin/printf/regress.m2.out
new file mode 100644 (file)
index 0000000..8baef1b
--- /dev/null
@@ -0,0 +1 @@
+abc
diff --git a/tools/regression/usr.bin/printf/regress.m3.out b/tools/regression/usr.bin/printf/regress.m3.out
new file mode 100644 (file)
index 0000000..bbe4e70
--- /dev/null
@@ -0,0 +1,4 @@
+%abc
+%def
+%ghi
+%jkl
diff --git a/tools/regression/usr.bin/printf/regress.m4.out b/tools/regression/usr.bin/printf/regress.m4.out
new file mode 100644 (file)
index 0000000..5e0b5d4
--- /dev/null
@@ -0,0 +1 @@
+0,0.000000,,
diff --git a/tools/regression/usr.bin/printf/regress.m5.out b/tools/regression/usr.bin/printf/regress.m5.out
new file mode 100644 (file)
index 0000000..2838468
--- /dev/null
@@ -0,0 +1 @@
+-d
diff --git a/tools/regression/usr.bin/printf/regress.s.out b/tools/regression/usr.bin/printf/regress.s.out
new file mode 100644 (file)
index 0000000..3d572b9
--- /dev/null
@@ -0,0 +1 @@
+abc,abc  
diff --git a/tools/regression/usr.bin/printf/regress.sh b/tools/regression/usr.bin/printf/regress.sh
new file mode 100644 (file)
index 0000000..94fce9d
--- /dev/null
@@ -0,0 +1,17 @@
+# $FreeBSD: src/tools/regression/usr.bin/printf/regress.sh,v 1.3 2010/12/08 22:54:18 jilles Exp $
+
+REGRESSION_START($1)
+
+echo '1..9'
+
+REGRESSION_TEST(`b', `printf "abc%b%b" "def\n" "\cghi"')
+REGRESSION_TEST(`d', `printf "%d,%5d,%.5d,%0*d,%.*d\n" 123 123 123 5 123 5 123')
+REGRESSION_TEST(`f', `printf "%f,%-8.3f,%f,%f\n" +42.25 -42.25 inf nan')
+REGRESSION_TEST(`m1', `printf "%c%%%d\0\045\n" abc \"abc')
+REGRESSION_TEST(`m2', `printf "abc\n\cdef"')
+REGRESSION_TEST(`m3', `printf "%%%s\n" abc def ghi jkl')
+REGRESSION_TEST(`m4', `printf "%d,%f,%c,%s\n"')
+REGRESSION_TEST(`m5', `printf -- "-d\n"')
+REGRESSION_TEST(`s', `printf "%.3s,%-5s\n" abcd abc')
+
+REGRESSION_END()
diff --git a/tools/regression/usr.bin/printf/regress.t b/tools/regression/usr.bin/printf/regress.t
new file mode 100644 (file)
index 0000000..a0b9a29
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+# $FreeBSD: src/tools/regression/usr.bin/printf/regress.t,v 1.1 2005/04/13 20:08:17 stefanf Exp $
+
+cd `dirname $0`
+
+m4 ../regress.m4 regress.sh | sh
diff --git a/tools/regression/usr.bin/regress.m4 b/tools/regression/usr.bin/regress.m4
new file mode 100644 (file)
index 0000000..f71a76a
--- /dev/null
@@ -0,0 +1,59 @@
+# $FreeBSD: src/tools/regression/usr.bin/regress.m4,v 1.5 2004/11/11 19:47:54 nik Exp $
+
+dnl A library of routines for doing regression tests for userland utilities.
+
+dnl Start up.  We initialise the exit status to 0 (no failure) and change
+dnl into the directory specified by our first argument, which is the
+dnl directory to run the tests inside.
+define(`REGRESSION_START',
+TESTDIR=$1
+if [ -z "$TESTDIR" ]; then
+  TESTDIR=.
+fi
+cd $TESTDIR
+
+STATUS=0)
+
+dnl Check $? to see if we passed or failed.  The first parameter is the test
+dnl which passed or failed.  It may be nil.
+define(`REGRESSION_PASSFAIL',
+if [ $? -eq 0 ]; then
+  echo "ok - $1 # Test detected no regression. (in $TESTDIR)"
+else
+  STATUS=$?
+  echo "not ok - $1 # Test failed: regression detected.  See above. (in $TESTDIR)"
+fi)
+
+dnl An actual test.  The first parameter is the test name.  The second is the
+dnl command/commands to execute for the actual test.  Their exit status is
+dnl checked.  It is assumed that the test will output to stdout, and that the
+dnl output to be used to check for regression will be in regress.TESTNAME.out.
+define(`REGRESSION_TEST',
+$2 | diff -u regress.$1.out -
+REGRESSION_PASSFAIL($1))
+
+dnl A freeform regression test.  Only exit status is checked.
+define(`REGRESSION_TEST_FREEFORM',
+$2
+REGRESSION_PASSFAIL($1))
+
+dnl A regression test like REGRESSION_TEST, except only regress.out is used
+dnl for checking output differences.  The first argument is the command, the
+dnl second argument (which may be empty) is the test name.
+define(`REGRESSION_TEST_ONE',
+$1 | diff -u regress.out -
+REGRESSION_PASSFAIL($2))
+
+dnl A fatal error.  This will exit with the given status (first argument) and
+dnl print the message (second argument) prefixed with the string "FATAL :" to
+dnl the error stream.
+define(`REGRESSION_FATAL',
+echo "Bail out! $2 (in $TESTDIR)" > /dev/stderr
+exit $1)
+
+dnl Cleanup.  Exit with the status code of the last failure.  Should probably
+dnl be the number of failed tests, but hey presto, this is what it does.  This
+dnl could also clean up potential droppings, if some forms of regression tests
+dnl end up using mktemp(1) or such.
+define(`REGRESSION_END',
+exit $STATUS)