[parted-devel] Rewrite integration tests to use a new framework (git's).

Jim Meyering jim at meyering.net
Mon May 7 15:35:40 UTC 2007


My first cut at adding integration tests didn't communicate well
what was being tested.  I've redone the framework to be more chatty,
a lot like git's.  Here's the output from "make -C tests check":

  ---------------------------------------------
  Making check in tests
  make[1]: Entering directory `/f/mirror/parted/b/tests'
  make  check-TESTS
  make[2]: Entering directory `/f/mirror/parted/b/tests'
  *   ok 1: create the test file
  *   ok 2: run parted -s FILE mklabel msdos
  *   ok 3: expect no output
  *   ok 4: erase the left-over label
  *   ok 5: run parted mklabel (without -s) on a blank disk
  *   ok 6: create expected output file
  *   ok 7: check its "interactive" output
  *   ok 8: create interactive input
  *   ok 9: rerun that same command, but now with a preexisting label
  *   ok 10: normalize the actual output
  *   ok 11: create expected output file
  *   ok 12: check its output -- slightly different here, due to prompts
  * passed all 12 test(s)
  PASS: t0000-basic.sh
  *   ok 1: create a file too small to hold a fat32 file system
  *   ok 2: label the test disk
  *   ok 3: expect no output
  *   ok 4: try/fail to create a file system in too small a space
  *   ok 5: create expected output file
  *   ok 6: check for expected failure diagnostic
  *   ok 7: clean up, preparing for next test
  *   ok 8: create a file large enough to hold a fat32 file system
  *   ok 9: label the test disk
  *   ok 10: expect no output
  *   ok 11: create an msdos file system
  *   ok 12: expect no output
  * passed all 12 test(s)
  PASS: t1000-mkpartfs.sh
  ==================
  All 2 tests passed
  ==================
  ---------------------------------------------

You can get still more output by running the tests
individually with e.g., --verbose or --debug.
That reminds me I need to add a tests/README file.
I'll do that once this goes in.

Here's the patch (looks big, but most of it is removals):

 b/tests/Makefile.am       |    8 -
 b/tests/t0000-basic.sh    |   99 +++++++++++++++++++
 b/tests/t1000-mkpartfs.sh |   69 +++++++++++++
 b/tests/test-lib.sh       |  238 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/label-01            |   61 -----------
 tests/label-02            |   70 -------------
 tests/lang-default        |   10 -
 tests/part-01             |   60 -----------
 tests/part-02             |   62 -----------
 tests/priv-check          |   94 ------------------
 10 files changed, 409 insertions(+), 362 deletions(-)

	Rewrite integration tests to use a new framework (git's).
	* tests/t1000-mkpartfs.sh: New file.
	* tests/t0000-basic.sh: New file.
	* tests/test-lib.sh: New file.  Derived from git's t/test-lib.sh.
	* tests/lang-default, tests/priv-check: Remove files.
	* tests/Makefile.am (EXTRA_DIST): Add test-lib.sh.
	Remove lang-default and priv-check; no longer used.
	* tests/part-01, tests/label-01: Remove files.
	* tests/part-02, tests/label-02: Likewise.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3d443ad..044e126 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,11 +1,9 @@
 TESTS = \
-  label-01 \
-  label-02 \
-  part-01 \
-  part-02
+  t0000-basic.sh \
+  t1000-mkpartfs.sh

 TESTS_ENVIRONMENT = \
   PATH="`pwd`/../parted$(PATH_SEPARATOR)$$PATH"

 EXTRA_DIST = \
-  $(TESTS) lang-default priv-check
+  $(TESTS) test-lib.sh
diff --git a/tests/label-01 b/tests/label-01
deleted file mode 100755
index 596ced3..0000000
--- a/tests/label-01
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/bin/sh
-# Ensure that a simple command using -s succeeds with no prompt
-
-# Copyright (C) 2007 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-if test "$VERBOSE" = yes; then
-  set -x
-  parted --version
-fi
-
-. $srcdir/lang-default
-
-pwd=`pwd`
-t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
-trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
-trap '(exit $?); exit $?' 1 2 13 15
-
-framework_failure=0
-mkdir -p $tmp || framework_failure=1
-cd $tmp || framework_failure=1
-
-# create a file of size N bytes
-N=1M
-dev=loop-file
-dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null || framework_failure=1
-
-# Expect no output for root.
-# Expect the warning for non-root.
-touch exp
-uid=`id -u` || uid=1
-test "$uid" = 0 || cat <<\EOF > exp || fail=1
-WARNING: You are not superuser.  Watch out for permissions.
-EOF
-
-if test $framework_failure = 1; then
-  echo "$0: failure in testing framework" 1>&2
-  (exit 1); exit 1
-fi
-
-fail=0
-parted -s $dev mklabel msdos > out 2>&1 || fail=1
-
-cmp out exp || fail=1
-test $fail = 1 && diff out exp 2> /dev/null
-
-(exit $fail); exit $fail
diff --git a/tests/label-02 b/tests/label-02
deleted file mode 100755
index f26fed5..0000000
--- a/tests/label-02
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/bin/sh
-# Ensure that a simple mklabel command succeeds.
-# Since there's no -s option, there are prompts.
-
-# Copyright (C) 2007 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-if test "$VERBOSE" = yes; then
-  set -x
-  parted --version
-fi
-
-. $srcdir/lang-default
-
-pwd=`pwd`
-t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
-trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
-trap '(exit $?); exit $?' 1 2 13 15
-
-framework_failure=0
-mkdir -p $tmp || framework_failure=1
-cd $tmp || framework_failure=1
-
-# create a file of size N bytes
-N=1M
-dev=loop-file
-dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null || framework_failure=1
-printf 'y\n\n' > in || framework_failure=1
-
-if test $framework_failure = 1; then
-  echo "$0: failure in testing framework" 1>&2
-  (exit 1); exit 1
-fi
-
-fail=0
-# First iteration works with no prompting, since there is no preexisting label.
-parted $dev mklabel msdos > out 2>&1 || fail=1
-
-# Now that there's a label, rerunning the same command is interactive.
-parted ---pretend-input-tty $dev mklabel msdos < in > o2 2>&1 || fail=1
-sed "s,^/.*$dev ,,;s,
 *
,,;s, $,," o2 >> out
-
-cat <<\EOF > exp || fail=1
-WARNING: You are not superuser.  Watch out for permissions.
-WARNING: You are not superuser.  Watch out for permissions.
-Warning: The existing disk label on
-will be destroyed and all
-data on this disk will be lost. Do you want to continue?
-Yes/No? y
-New disk label type?  [msdos]?
-EOF
-
-cmp out exp || fail=1
-test $fail = 1 && diff -u out exp 2> /dev/null
-
-(exit $fail); exit $fail
diff --git a/tests/lang-default b/tests/lang-default
deleted file mode 100644
index 882672f..0000000
--- a/tests/lang-default
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# Set locale-related environment variables so we get consistent
-# message translations, time formats, sort orderings, etc.
-
-LC_ALL=C
-export LC_ALL
-unset LANGUAGE NLSPATH
-
-# These settings shouldn't matter, but unset them anyway just in case.
-unset LANG LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME
diff --git a/tests/part-01 b/tests/part-01
deleted file mode 100755
index 1d6798e..0000000
--- a/tests/part-01
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/bin/sh
-# Ensure that mkpartfs fails when the device is too small.
-
-# Copyright (C) 2007 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-if test "$VERBOSE" = yes; then
-  set -x
-  parted --version
-fi
-
-. $srcdir/lang-default
-
-pwd=`pwd`
-t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
-trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
-trap '(exit $?); exit $?' 1 2 13 15
-
-framework_failure=0
-mkdir -p $tmp || framework_failure=1
-cd $tmp || framework_failure=1
-
-# You need much more than this to create a fat32 file system
-N=1M
-dev=loop-file
-dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null || framework_failure=1
-parted $dev mklabel msdos > /dev/null 2>&1 || framework_failure=1
-
-cat <<\EOF > exp || framework_failure=1
-WARNING: You are not superuser.  Watch out for permissions.
-Error: Partition too big/small for a fat32 file system.
-EOF
-
-if test $framework_failure = 1; then
-  echo "$0: failure in testing framework" 1>&2
-  (exit 1); exit 1
-fi
-
-fail=0
-# Require nonzero exit status.
-parted -s $dev mkpartfs primary fat32 0 1 > out 2>&1 && fail=1
-
-cmp out exp || fail=1
-test $fail = 1 && diff -u out exp 2> /dev/null
-
-(exit $fail); exit $fail
diff --git a/tests/part-02 b/tests/part-02
deleted file mode 100755
index bef517e..0000000
--- a/tests/part-02
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/bin/sh
-# Ensure that mkpartfs works in one small case.
-
-# Copyright (C) 2007 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-if test "$VERBOSE" = yes; then
-  set -x
-  parted --version
-fi
-
-. $srcdir/lang-default
-
-pwd=`pwd`
-t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
-trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
-trap '(exit $?); exit $?' 1 2 13 15
-
-framework_failure=0
-mkdir -p $tmp || framework_failure=1
-cd $tmp || framework_failure=1
-
-# 40MB is just enough space in which to create a fat32 file system
-N=40M
-dev=loop-file
-dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null || framework_failure=1
-parted $dev mklabel msdos > /dev/null 2>&1 || framework_failure=1
-
-# Expect no output for root.
-# Expect the warning for non-root.
-touch exp
-uid=`id -u` || uid=1
-test "$uid" = 0 || cat <<\EOF > exp || fail=1
-WARNING: You are not superuser.  Watch out for permissions.
-EOF
-
-if test $framework_failure = 1; then
-  echo "$0: failure in testing framework" 1>&2
-  (exit 1); exit 1
-fi
-
-fail=0
-parted -s $dev mkpartfs primary fat32 0 40 > out 2>&1 || fail=1
-
-cmp out exp || fail=1
-test $fail = 1 && diff -u out exp 2> /dev/null
-
-(exit $fail); exit $fail
diff --git a/tests/priv-check b/tests/priv-check
deleted file mode 100644
index b0d6c92..0000000
--- a/tests/priv-check
+++ /dev/null
@@ -1,94 +0,0 @@
-# -*- sh -*-
-# Source this file at the beginning of a test that works
-# only when run as root or as non-root.
-
-# Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-case "$PRIV_CHECK_ARG" in
-  require-root) who='as root';;
-  require-non-root) who='by an unprivileged user';;
-  *) echo "Usage: PRIV_CHECK_ARG={require-root|require-non-root} . priv-check"\
-     1>&2; exit 1;;
-esac
-
-# Make sure id -u succeeds.
-my_uid=`id -u`
-test $? = 0 || {
-  echo "$0: cannot run \`id -u'" 1>&2
-  (exit 1); exit 1
-}
-
-# Make sure it gives valid output.
-case $my_uid in
-  *[!0-9]*)
-    echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
-    (exit 1); exit 1
-    ;;
-  *) ;;
-esac
-
-test $my_uid = 0 && \
-{
-  # When running as root, always ensure that we have a valid non-root username.
-  # As non-root, don't do anything, since we won't be running setuidgid.
-  : ${NON_ROOT_USERNAME=nobody}
-
-  # Ensure that the supplied username is valid and with UID != 0.
-  coreutils_non_root_uid=`id -u $NON_ROOT_USERNAME`
-  test $? = 0 || \
-    {
-      echo "$0: This command failed: \`id -u $NON_ROOT_USERNAME'" 1>&2
-      echo "$0: Skipping this test.  To enable it, set the envvar" 1>&2
-      echo "$0: NON_ROOT_USERNAME to a non-root user name." 1>&2
-      (exit 77); exit 77
-    }
-  test "$coreutils_non_root_uid" = 0 && \
-    {
-      echo "$0: The specified NON_ROOT_USERNAME ($NON_ROOT_USERNAME)" 1>&2
-      echo "$0: is invalid because its UID is 0." 1>&2
-      (exit 1); exit 1
-    }
-}
-
-give_msg=no
-case $PRIV_CHECK_ARG:$my_uid in
-  require-root:0) ;;
-  require-root:*) give_msg=yes ;;
-  require-non-root:0)
-    # `.' must be writable by $NON_ROOT_USERNAME
-    setuidgid $NON_ROOT_USERNAME test -w . ||
-      {
-	echo "$0: `pwd`: not writable by user \`$NON_ROOT_USERNAME'" 1>&2
-	echo "$0: skipping this test" 1>&2
-	(exit 77); exit 77
-      }
-    exec setuidgid $NON_ROOT_USERNAME env PATH="$PATH" $0
-    ;;
-  require-non-root:*) ;;
-esac
-
-test $give_msg = yes && {
-  cat <<EOF
-***************************
-NOTICE:
-$0: This test is being skipped, since it works only
-when run $who.
-***************************
-EOF
-  (exit 77); exit 77
-}
diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh
new file mode 100755
index 0000000..6049e15
--- /dev/null
+++ b/tests/t0000-basic.sh
@@ -0,0 +1,99 @@
+#!/bin/sh
+# Ensure that a simple command using -s succeeds with no prompt
+
+# Copyright (C) 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+../parted/parted --version > /dev/null 2>&1
+if test $? != 0; then
+  echo >&2 'You have not built parted yet.'
+  exit 1
+fi
+
+test_description='Test the very basics part #1.'
+
+. $srcdir/test-lib.sh
+
+# FIXME: is id -u portable enough?
+uid=`id -u` || uid=1
+
+# create a file of size N bytes
+N=1M
+dev=loop-file
+
+test_expect_success \
+    'create the test file' \
+    'dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null'
+
+test_expect_success \
+    'run parted -s FILE mklabel msdos' \
+    'parted -s $dev mklabel msdos > out 2>&1'
+test_expect_success 'expect no output' '$compare out /dev/null'
+
+# ----------------------------------------------
+# Now, ensure that a simple mklabel command succeeds.
+# Since there's no -s option, there are prompts -- sometimes.
+
+test_expect_success \
+    'erase the left-over label' \
+    'dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null'
+
+# First iteration works with no prompting, since there is no preexisting label.
+test_expect_success \
+    'run parted mklabel (without -s) on a blank disk' \
+    'parted $dev mklabel msdos > out 2>&1'
+
+warning_msg='WARNING: You are not superuser.  Watch out for permissions.'
+test_expect_success \
+    'create expected output file' \
+    'test "$uid" = 0 && : > exp || echo "$warning_msg" > exp'
+
+test_expect_success \
+    'check its "interactive" output' \
+    '$compare out exp 1>&2'
+
+test_expect_success 'create interactive input' 'printf "y\n\n" > in'
+
+# Now that there's a label, rerunning the same command is interactive.
+test_expect_success \
+    'rerun that same command, but now with a preexisting label' \
+    'parted ---pretend-input-tty $dev mklabel msdos < in > o2 2>&1'
+
+# Transform the actual output, to avoid spurious differences when
+# $PWD contains a symlink-to-dir.  Also, remove the ^M      ...^M bogosity.
+test_expect_success \
+    'normalize the actual output' \
+    'sed "s,on /.*/$dev,on DEVICE,;s,
   *
,,;s, $,," o2 > out'
+
+# Create expected output file.
+fail=0
+{ test "$uid" = 0 && : > exp || echo "$warning_msg" > exp; } || fail=1
+cat <<EOF >> exp || fail=1
+Warning: The existing disk label on DEVICE will be destroyed and all\
+ data on this disk will be lost. Do you want to continue?
+Yes/No? y
+New disk label type?  [msdos]?
+EOF
+test_expect_success \
+    'create expected output file' \
+    'test $fail = 0'
+
+test_expect_success \
+    'check its output -- slightly different here, due to prompts' \
+    '$compare out exp'
+
+test_done
diff --git a/tests/t1000-mkpartfs.sh b/tests/t1000-mkpartfs.sh
new file mode 100755
index 0000000..37dc43a
--- /dev/null
+++ b/tests/t1000-mkpartfs.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+# Copyright (C) 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+test_description='Create some file systems using mkpartfs.'
+
+. $srcdir/test-lib.sh
+
+N=1M
+dev=loop-file
+test_expect_success \
+    'create a file too small to hold a fat32 file system' \
+    'dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null'
+
+test_expect_success \
+    'label the test disk' \
+    'parted -s $dev mklabel msdos > out 2>&1'
+test_expect_success 'expect no output' '$compare out /dev/null'
+
+# Expect parted's mkpartfs command to fail.
+test_expect_failure \
+    'try/fail to create a file system in too small a space' \
+    'parted -s $dev mkpartfs primary fat32 0 1 > out 2>&1'
+
+test_expect_success \
+    'create expected output file' \
+    'echo "Error: Partition too big/small for a fat32 file system." > exp'
+
+test_expect_success \
+    'check for expected failure diagnostic' \
+    '$compare out exp'
+
+test_expect_success 'clean up, preparing for next test' 'rm $dev out'
+
+#====================================================================
+# Similar, but with a file that's large enough, so mkpartfs succeeds.
+N=40M
+
+test_expect_success \
+    'create a file large enough to hold a fat32 file system' \
+    'dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null'
+
+test_expect_success \
+    'label the test disk' \
+    'parted -s $dev mklabel msdos > out 2>&1'
+test_expect_success 'expect no output' '$compare out /dev/null'
+
+test_expect_success \
+    'create an msdos file system' \
+    'parted -s $dev mkpartfs primary fat32 1 40 > out 2>&1'
+
+test_expect_success 'expect no output' '$compare out /dev/null'
+
+test_done
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
new file mode 100644
index 0000000..d6804cf
--- /dev/null
+++ b/tests/test-lib.sh
@@ -0,0 +1,238 @@
+#!/bin/sh
+# Derived from git's t/test-lib.sh.
+# Copyright (c) 2005 Junio C Hamano
+
+# For repeatability, reset the environment to known value.
+LANG=C
+LC_ALL=C
+TZ=UTC
+export LANG LC_ALL TZ
+
+# Protect ourselves from common misconfiguration to export
+# CDPATH into the environment
+unset CDPATH
+
+# Each test should start with something like this, after copyright notices:
+#
+# test_description='Description of this test...
+# This test checks if command xyzzy does the right thing...
+# '
+# . ./test-lib.sh
+
+error () {
+	echo "* error: $*"
+	trap - exit
+	exit 1
+}
+
+say () {
+	echo "* $*"
+}
+
+test "${test_description}" != "" ||
+error "Test script did not set test_description."
+
+# If $srcdir is not set, set it, if it's ".".  Otherwise, fail.
+if test -a "$srcdir"; then
+    if test -f test-lib.sh; then
+	srcdir=.
+    else
+	error '$srcdir is not set; either set it, or run the test' \
+	    'from the source directory'
+    fi
+fi
+
+while test "$#" -ne 0
+do
+	case "$1" in
+	-d|--d|--de|--deb|--debu|--debug)
+		debug=t; shift ;;
+	-i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
+		immediate=t; shift ;;
+	-h|--h|--he|--hel|--help)
+		echo "$test_description"
+		exit 0 ;;
+	-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
+		verbose=t; shift ;;
+	esac
+done
+
+exec 5>&1
+if test "$verbose" = "t"
+then
+	exec 4>&2 3>&1
+else
+	exec 4>/dev/null 3>/dev/null
+fi
+
+test_failure=0
+test_count=0
+
+trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit
+
+# You are not expected to call test_ok_ and test_failure_ directly, use
+# the text_expect_* functions instead.
+
+test_ok_ () {
+	test_count=$(expr "$test_count" + 1)
+	say "  ok $test_count: $@"
+}
+
+test_failure_ () {
+	test_count=$(expr "$test_count" + 1)
+	test_failure=$(expr "$test_failure" + 1);
+	say "FAIL $test_count: $1"
+	shift
+	echo "$@" | sed -e 's/^/	/'
+	test "$immediate" = "" || { trap - exit; exit 1; }
+}
+
+test_debug () {
+	test "$debug" = "" || eval "$1"
+}
+
+test_run_ () {
+	eval >&3 2>&4 "$1"
+	eval_ret="$?"
+	return 0
+}
+
+test_skip () {
+	this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
+	this_test="$this_test.$(expr "$test_count" + 1)"
+	to_skip=
+	for skp in $SKIP_TESTS
+	do
+		case "$this_test" in
+		$skp)
+			to_skip=t
+		esac
+	done
+	case "$to_skip" in
+	t)
+		say >&3 "skipping test: $@"
+		test_count=$(expr "$test_count" + 1)
+		say "skip $test_count: $1"
+		: true
+		;;
+	*)
+		false
+		;;
+	esac
+}
+
+test_expect_failure () {
+	test "$#" = 2 ||
+	error "bug in the test script: not 2 parameters to test-expect-failure"
+	if ! test_skip "$@"
+	then
+		say >&3 "expecting failure: $2"
+		test_run_ "$2"
+		if [ "$?" = 0 -a "$eval_ret" != 0 -a "$eval_ret" -lt 129 ]
+		then
+			test_ok_ "$1"
+		else
+			test_failure_ "$@"
+		fi
+	fi
+	echo >&3 ""
+}
+
+test_expect_success () {
+	test "$#" = 2 ||
+	error "bug in the test script: not 2 parameters to test-expect-success"
+	if ! test_skip "$@"
+	then
+		say >&3 "expecting success: $2"
+		test_run_ "$2"
+		if [ "$?" = 0 -a "$eval_ret" = 0 ]
+		then
+			test_ok_ "$1"
+		else
+			test_failure_ "$@"
+		fi
+	fi
+	echo >&3 ""
+}
+
+test_expect_code () {
+	test "$#" = 3 ||
+	error "bug in the test script: not 3 parameters to test-expect-code"
+	if ! test_skip "$@"
+	then
+		say >&3 "expecting exit code $1: $3"
+		test_run_ "$3"
+		if [ "$?" = 0 -a "$eval_ret" = "$1" ]
+		then
+			test_ok_ "$2"
+		else
+			test_failure_ "$@"
+		fi
+	fi
+	echo >&3 ""
+}
+
+test_done () {
+	case "$test_failure" in
+	0)
+		# We could:
+		# cd .. && rm -fr trash
+		# but that means we forbid any tests that use their own
+		# subdirectory from calling test_done without coming back
+		# to where they started from.
+		# The Makefile provided will clean this test area so
+		# we will leave things as they are.
+
+		say "passed all $test_count test(s)"
+		exit 0 ;;
+
+	*)
+		say "failed $test_failure among $test_count test(s)"
+		exit 1 ;;
+
+	esac
+}
+
+pwd_=`pwd`
+
+# Test the binaries we have just built.  The tests are kept in
+# t/ subdirectory and are run in trash subdirectory.
+PATH=$pwd_/../parted:$PATH
+export PATH
+
+t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp_=$t0/$$
+trap 'st=$?; cd "$pwd_" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $st' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+framework_failure=0
+mkdir -p $tmp_ || framework_failure=1
+cd $tmp_ || framework_failure=1
+test $framework_failure = 0 \
+     || error 'failed to create temporary directory'
+
+this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
+for skp in $SKIP_TESTS
+do
+	to_skip=
+	for skp in $SKIP_TESTS
+	do
+		case "$this_test" in
+		$skp)
+			to_skip=t
+		esac
+	done
+	case "$to_skip" in
+	t)
+		say >&3 "skipping test $this_test altogether"
+		say "skip all tests in $this_test"
+		test_done
+	esac
+done
+
+if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare='diff -u'
+elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare='cmp -s'
+else
+  compare=cmp
+fi



More information about the parted-devel mailing list