diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 10 | ||||
-rw-r--r-- | tests/README | 16 | ||||
-rw-r--r-- | tests/commands.sh.in | 8 | ||||
-rw-r--r-- | tests/expected/ts-mount-paths | 7 | ||||
-rw-r--r-- | tests/functions.sh | 42 | ||||
-rwxr-xr-x | tests/run.sh | 25 | ||||
-rwxr-xr-x | tests/ts-mount-paths | 14 |
9 files changed, 126 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 5f69f448..b5293e2f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,8 @@ SUBDIRS = lib \ po \ schedutils \ sys-utils \ - text-utils + text-utils \ + tests ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 5a0d44ea..b4cbf2ef 100644 --- a/configure.ac +++ b/configure.ac @@ -408,6 +408,8 @@ po/Makefile.in schedutils/Makefile sys-utils/Makefile text-utils/Makefile +tests/Makefile +tests/commands.sh ]) AC_OUTPUT diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 00000000..65cd57a5 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/config/include-Makefile.am + +EXTRA_DIST = commands.sh.in \ + functions.sh \ + ts-mount-paths \ + expected/ts-mount-paths + +distclean-local: + rm -rf output diff + diff --git a/tests/README b/tests/README new file mode 100644 index 00000000..bcade3d7 --- /dev/null +++ b/tests/README @@ -0,0 +1,16 @@ + + util-linux regression tests + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + It's expected that for each invasive change or important bugfix you will + include a test to your patch. + + + Run all tests: + + ./run.sh + + Run one tests: + + ./ts-<component_name>-<test_name>.sh + diff --git a/tests/commands.sh.in b/tests/commands.sh.in new file mode 100644 index 00000000..ecdb9b94 --- /dev/null +++ b/tests/commands.sh.in @@ -0,0 +1,8 @@ +TOPDIR=@top_srcdir@ +TS_TOPDIR=$TOPDIR/tests + +# paths to commands +TS_CMD_MOUNT=${TS_CMD_MOUNT:-"$TOPDIR/mount/mount"} +TS_CMD_UMOUNT=${TS_CMD_MOUNT:-"$TOPDIR/mount/umount"} +TS_CMD_SWAPON=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapon"} +TS_CMD_SWAPOFF=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapoff"} diff --git a/tests/expected/ts-mount-paths b/tests/expected/ts-mount-paths new file mode 100644 index 00000000..d6f798ae --- /dev/null +++ b/tests/expected/ts-mount-paths @@ -0,0 +1,7 @@ +DEBUG: fstab path: "/etc/fstab" +DEBUG: lock path: "/etc/mtab~" +DEBUG: temp path: "/etc/mtab.tmp" +DEBUG: spec: "/dev/dummy" +DEBUG: node: "/mnt" +DEBUG: types: "(null)" +DEBUG: opts: "(null)" diff --git a/tests/functions.sh b/tests/functions.sh new file mode 100644 index 00000000..64392e4d --- /dev/null +++ b/tests/functions.sh @@ -0,0 +1,42 @@ + +TS_OUTDIR="$TS_TOPDIR/output" +TS_DIFFDIR="$TS_TOPDIR/diff" +TS_EXPECTEDDIR="$TS_TOPDIR/expected" + +function ts_init { + TS_NAME=$(basename $0) + if [ ! -d $TS_OUTDIR ]; then + mkdir -p $TS_OUTDIR + fi + if [ ! -d $TS_DIFFDIR ]; then + mkdir -p $TS_DIFFDIR + fi + TS_OUTPUT="$TS_OUTDIR/$TS_NAME" + TS_DIFF="$TS_DIFFDIR/$TS_NAME" + TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME" + + printf "%15s: %-25s ..." "$TS_COMPONENT" "$TS_DESC" +} + +function ts_finalize { + local res=0 + + if [ -s $TS_EXPECTED ]; then + if [ -s $TS_OUTPUT ]; then + diff -u $TS_EXPECTED $TS_OUTPUT > $TS_DIFF + if [ -s $TS_DIFF ]; then + res=1 + fi + else + res=0 + fi + fi + if [ $res -eq 0 ]; then + echo " OK" + exit 0 + else + echo " FAILED ($TS_NAME)" + exit 1 + fi +} + diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 00000000..b4ca51b5 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +. commands.sh + +echo +echo "------------------ Utils-linux-ng regression tests ------------------" +echo + +res=0 +count=0 +for ts in `ls ts-*`; do + $TS_TOPDIR/$ts + res=$(( $res + $? )) + count=$(( $count + 1 )) +done + +echo +echo "---------------------------------------------------------------------" +if [ $res -eq 0 ]; then + echo " All $count tests PASSED" +else + echo " $res tests of $count FAILED" +fi +echo "---------------------------------------------------------------------" + diff --git a/tests/ts-mount-paths b/tests/ts-mount-paths new file mode 100755 index 00000000..137aade3 --- /dev/null +++ b/tests/ts-mount-paths @@ -0,0 +1,14 @@ +#!/bin/bash + +. commands.sh +. functions.sh + +TS_COMPONENT="mount" +TS_DESC="basic paths" + +ts_init + +$TS_CMD_MOUNT -n -f --debug=2 /dev/dummy /mnt &> $TS_OUTPUT + +ts_finalize + |