[parted-devel] [PATCH] Move a test/utility function into test-lib.sh.
Jim Meyering
jim at meyering.net
Tue May 29 18:30:54 UTC 2007
Avoiding more duplication...
* tests/t3000-constraints.sh (emit_superuser_warning): Move this
function to...
* tests/test-lib.sh (emit_superuser_warning): ...here.
* tests/t0000-basic.sh: Use the function instead of open-coding it.
Signed-off-by: Jim Meyering <jim at meyering.net>
---
tests/t0000-basic.sh | 5 ++---
tests/t3000-constraints.sh | 8 --------
tests/test-lib.sh | 7 +++++++
3 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh
index 35bf6e6..180b1da 100755
--- a/tests/t0000-basic.sh
+++ b/tests/t0000-basic.sh
@@ -57,10 +57,9 @@ 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'
+ 'emit_superuser_warning > exp'
test_expect_success \
'check its "interactive" output' \
@@ -81,7 +80,7 @@ test_expect_success \
# Create expected output file.
fail=0
-{ test "$uid" = 0 && : > exp || echo "$warning_msg" > exp; } || fail=1
+{ emit_superuser_warning > 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?
diff --git a/tests/t3000-constraints.sh b/tests/t3000-constraints.sh
index 07fe1b3..179a33c 100755
--- a/tests/t3000-constraints.sh
+++ b/tests/t3000-constraints.sh
@@ -21,14 +21,6 @@ test_description="exercise Parted's constraint-management code"
. ./init.sh
-# FIXME: move this to test-lib.sh, and use it in t0000*.sh
-emit_superuser_warning()
-{
- uid=`id -u` || uid=1
- test "$uid" != 0 &&
- echo 'WARNING: You are not superuser. Watch out for permissions.'
-}
-
dev=loop-file
N=2
t=ext2
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index 050b967..29a2be1 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -201,6 +201,13 @@ if test "$privileges_required_" != ''; then
fi
fi
+emit_superuser_warning()
+{
+ uid=`id -u` || uid=1
+ test "$uid" != 0 &&
+ echo 'WARNING: You are not superuser. Watch out for permissions.'
+}
+
# Test the binaries we have just built.
pwd_=`pwd`
parted_="$pwd_/../parted/parted"
More information about the parted-devel
mailing list