[PATCH] source test-lib.sh from each test, not init.sh
Jim Meyering
meyering at redhat.com
Fri Jun 6 07:16:38 UTC 2008
* tests/test-lib.sh: Source init.sh early.
Use $test_dir_rand_, as done in LVM test framework.
Source lvm-utils.sh _after_ defining test_dir_rand_.
* tests/Makefile.am (init.sh): Don't emit code to source test-lib.sh,
since each test now sources that file directly.
* tests/t0000-basic.sh: Source test-lib.sh, not init.sh.
* tests/t0100-print.sh: Likewise.
* tests/t1000-mkpartfs.sh: Likewise.
* tests/t1100-busy-label.sh: Likewise.
* tests/t1500-small-ext2.sh: Likewise.
* tests/t2000-mkfs.sh: Likewise.
* tests/t2100-mkswap.sh: Likewise.
* tests/t2200-dos-label-recog.sh: Likewise.
* tests/t3000-constraints.sh: Likewise.
* tests/t3100-resize-ext2-partion.sh: Likewise.
* tests/t4100-dvh-partition-limits.sh: Likewise.
* tests/t4100-msdos-partition-limits.sh: Likewise.
* tests/t5000-tags.sh: Likewise.
* tests/t6000-dm.sh: Likewise.
---
tests/Makefile.am | 1 -
tests/t0000-basic.sh | 2 +-
tests/t0100-print.sh | 2 +-
tests/t1000-mkpartfs.sh | 2 +-
tests/t1100-busy-label.sh | 2 +-
tests/t1500-small-ext2.sh | 2 +-
tests/t2000-mkfs.sh | 2 +-
tests/t2100-mkswap.sh | 2 +-
tests/t2200-dos-label-recog.sh | 2 +-
tests/t3000-constraints.sh | 2 +-
tests/t3100-resize-ext2-partion.sh | 2 +-
tests/t4100-dvh-partition-limits.sh | 2 +-
tests/t4100-msdos-partition-limits.sh | 2 +-
tests/t5000-tags.sh | 2 +-
tests/t6000-dm.sh | 2 +-
tests/test-lib.sh | 16 +++++++++-------
16 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2e72bbd..95a129e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,7 +23,6 @@ init.sh: Makefile.in
rm -f $@-t $@
echo 'PARTED_USABLE_TEST_DIR=3D$(PARTED_USABLE_TEST_DIR)' > $@-t
echo 'abs_top_srcdir=3D$(abs_top_srcdir)' >> $@-t
- echo '. $(abs_top_srcdir)/tests/test-lib.sh' >> $@-t
echo 'PATH=3D$(abs_top_builddir)/parted$(PATH_SEPARATOR)$$PATH' >> $@-t
echo 'export PATH' >> $@-t
chmod a-w $@-t
diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh
index cefadf5..93d6fe6 100755
--- a/tests/t0000-basic.sh
+++ b/tests/t0000-basic.sh
@@ -24,7 +24,7 @@ fi
test_description=3D'Test the very basics part #1.'
-. ./init.sh
+. ./test-lib.sh
# FIXME: is id -u portable enough?
uid=3D`id -u` || uid=3D1
diff --git a/tests/t0100-print.sh b/tests/t0100-print.sh
index edaa282..3ec0db8 100755
--- a/tests/t0100-print.sh
+++ b/tests/t0100-print.sh
@@ -17,7 +17,7 @@
test_description=3D"the most basic 'print' test"
-. ./init.sh
+. ./test-lib.sh
dev=3Dloop-file
diff --git a/tests/t1000-mkpartfs.sh b/tests/t1000-mkpartfs.sh
index c15073d..9b63b10 100755
--- a/tests/t1000-mkpartfs.sh
+++ b/tests/t1000-mkpartfs.sh
@@ -17,7 +17,7 @@
test_description=3D'Create some file systems using mkpartfs.'
-. ./init.sh
+. ./test-lib.sh
N=3D1M
dev=3Dloop-file
diff --git a/tests/t1100-busy-label.sh b/tests/t1100-busy-label.sh
index 670f708..f48fa4e 100755
--- a/tests/t1100-busy-label.sh
+++ b/tests/t1100-busy-label.sh
@@ -20,7 +20,7 @@ test_description=3D'partitioning (parted -s DEV mklabel) =
a busy disk must fail.'
privileges_required_=3D1
erasable_device_required_=3D1
-. ./init.sh
+. ./test-lib.sh
dev=3D$DEVICE_TO_ERASE
test_expect_success \
diff --git a/tests/t1500-small-ext2.sh b/tests/t1500-small-ext2.sh
index 7740e02..dd9e398 100755
--- a/tests/t1500-small-ext2.sh
+++ b/tests/t1500-small-ext2.sh
@@ -17,7 +17,7 @@
test_description=3D'Create very small ext2 file systems.'
-. ./init.sh
+. ./test-lib.sh
dev=3Dloop-file
test_expect_success \
diff --git a/tests/t2000-mkfs.sh b/tests/t2000-mkfs.sh
index 8922ddd..b03ebe5 100755
--- a/tests/t2000-mkfs.sh
+++ b/tests/t2000-mkfs.sh
@@ -17,7 +17,7 @@
test_description=3D'Create some file systems using mkfs.'
-. ./init.sh
+. ./test-lib.sh
N=3D40M
dev=3Dloop-file
diff --git a/tests/t2100-mkswap.sh b/tests/t2100-mkswap.sh
index 2bc1e99..5b63dbc 100755
--- a/tests/t2100-mkswap.sh
+++ b/tests/t2100-mkswap.sh
@@ -17,7 +17,7 @@
test_description=3D'create linux-swap partitions'
-. ./init.sh
+. ./test-lib.sh
######################################################################
# When creating a partition of type linux-swap(new) in a DOS partition
diff --git a/tests/t2200-dos-label-recog.sh b/tests/t2200-dos-label-recog.sh
index d5d2670..8b6459b 100755
--- a/tests/t2200-dos-label-recog.sh
+++ b/tests/t2200-dos-label-recog.sh
@@ -17,7 +17,7 @@
test_description=3D'improved MSDOS partition-table recognition'
-. ./init.sh
+. ./test-lib.sh
######################################################################
# With vestiges of a preceding FAT file system boot sector in the MBR,
diff --git a/tests/t3000-constraints.sh b/tests/t3000-constraints.sh
index 3e1f575..54a7197 100755
--- a/tests/t3000-constraints.sh
+++ b/tests/t3000-constraints.sh
@@ -17,7 +17,7 @@
test_description=3D"exercise Parted's constraint-management code"
-. ./init.sh
+. ./test-lib.sh
dev=3Dloop-file
N=3D2
diff --git a/tests/t3100-resize-ext2-partion.sh b/tests/t3100-resize-ext2-p=
artion.sh
index 9ab7fc6..2549c67 100755
--- a/tests/t3100-resize-ext2-partion.sh
+++ b/tests/t3100-resize-ext2-partion.sh
@@ -18,7 +18,7 @@
test_description=3D'Exercise an EXT2-resize bug in at least 1.8.7'
-. ./init.sh
+. ./test-lib.sh
dev=3Dloop-file
# The "device size", $N, must be larger than $NEW_SIZE.
diff --git a/tests/t4100-dvh-partition-limits.sh b/tests/t4100-dvh-partitio=
n-limits.sh
index 6e0a3ee..3c1a18a 100755
--- a/tests/t4100-dvh-partition-limits.sh
+++ b/tests/t4100-dvh-partition-limits.sh
@@ -20,7 +20,7 @@ test_description=3D'enforce limits on partition start sec=
tor and length'
# Need root privileges to use mount.
privileges_required_=3D1
-. ./init.sh
+. ./test-lib.sh
####################################################
# Create and mount a file system capable of dealing with >=3D2TB files.
diff --git a/tests/t4100-msdos-partition-limits.sh b/tests/t4100-msdos-part=
ition-limits.sh
index cedbf83..737f430 100755
--- a/tests/t4100-msdos-partition-limits.sh
+++ b/tests/t4100-msdos-partition-limits.sh
@@ -20,7 +20,7 @@ test_description=3D'enforce limits on partition start sec=
tor and length'
# Need root privileges to use mount.
privileges_required_=3D1
-. ./init.sh
+. ./test-lib.sh
####################################################
# Create and mount a file system capable of dealing with >=3D2TB files.
diff --git a/tests/t5000-tags.sh b/tests/t5000-tags.sh
index dab48ae..3902729 100755
--- a/tests/t5000-tags.sh
+++ b/tests/t5000-tags.sh
@@ -17,7 +17,7 @@
test_description=3D"test bios_grub flag in gpt labels"
-. ./init.sh
+. ./test-lib.sh
dev=3Dloop-file
diff --git a/tests/t6000-dm.sh b/tests/t6000-dm.sh
index bf7df6d..48f579b 100755
--- a/tests/t6000-dm.sh
+++ b/tests/t6000-dm.sh
@@ -20,7 +20,7 @@ test_description=3D'determine type of devicemaps.'
privileges_required_=3D1
device_mapper_required_=3D1
-. ./init.sh
+. ./test-lib.sh
# Device maps names - should be random to not conflict with existing ones =
on
# the system
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index 21d3e51..e967545 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -8,6 +8,8 @@ LC_ALL=3DC
TZ=3DUTC
export LANG LC_ALL TZ
+. ./init.sh || { echo >&2 you must run make first; exit 1; }
+
# Protect ourselves from common misconfiguration to export
# CDPATH into the environment
unset CDPATH
@@ -258,10 +260,6 @@ if test $skip_ =3D 0 && test "$erasable_device_require=
d_" !=3D ''; then
fi
fi
-if test $skip_ =3D 0 && test "$device_mapper_required_" !=3D ''; then
- . $abs_top_srcdir/tests/dm-utils.sh || exit 1
-fi
-
# This is a stub function that is run upon trap (upon regular exit and
# interrupt). Override it with a per-test function, e.g., to unmount
# a partition, or to undo any other global state changes.
@@ -286,16 +284,20 @@ do
esac
done
-t0=3D$($abs_top_srcdir/build-aux/mktempd $test_dir_ parted-$this_test.XXXX=
XXXXXX) \
+test_dir_rand_=3D$($abs_top_srcdir/build-aux/mktempd $test_dir_ parted-$th=
is_test.XXXXXXXXXX) \
|| error "failed to create temporary directory in $test_dir_"
+if test $skip_ =3D 0 && test "$device_mapper_required_" !=3D ''; then
+ . $abs_top_srcdir/tests/dm-utils.sh || exit 1
+fi
+
# Run each test from within a temporary sub-directory named after the
# test itself, and arrange to remove it upon exception or normal exit.
-trap 'st=3D$?; cleanup_; d=3D'"$t0"';
+trap 'st=3D$?; cleanup_; d=3D'"$test_dir_rand_"';
cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0
trap '(exit $?); exit $?' 1 2 13 15
-cd $t0 || error "failed to cd to $t0"
+cd "$test_dir_rand_" || error "failed to cd to $test_dir_rand_"
if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
compare=3D'diff -u'
--=20
1.5.6.rc0.30.g7c3f3
More information about the parted-devel
mailing list