summaryrefslogtreecommitdiff
path: root/tests/test-lib.sh
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-09-12 14:52:26 +0200
committerJim Meyering <jim@meyering.net>2007-09-15 08:40:39 +0200
commita669dfdabb3fa1be2e1367d53a797d495e7bd5c9 (patch)
treec88d6414649f7f4f5571138e193c72da44a03876 /tests/test-lib.sh
parent0539705768992ebcc290bc859f64e27898c7f958 (diff)
downloadcoreutils-a669dfdabb3fa1be2e1367d53a797d495e7bd5c9.tar.xz
More misc, test-related changes. (some to allow running tests as root)
Diffstat (limited to 'tests/test-lib.sh')
-rw-r--r--tests/test-lib.sh39
1 files changed, 34 insertions, 5 deletions
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index 10571a1e6..9d47242e4 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -8,12 +8,41 @@ if test $? != 11; then
(exit 77); exit 77
fi
-framework_failure()
+skip_test_()
{
- echo "$0: failure in testing framework" 1>&2
- (exit 1); exit 1
+ echo "$0: skipping test: $@" 1>&2
+ (exit 77); exit 77
+}
+
+uid_is_privileged_()
+{
+ # Make sure id -u succeeds.
+ my_uid=$(id -u) \
+ || { echo "$0: cannot run \`id -u'" 1>&2; return 1; }
+
+ # Make sure it gives valid output.
+ case $my_uid in
+ 0) ;;
+ *[!0-9]*)
+ echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
+ return 1 ;;
+ *) return 1 ;;
+ esac
}
+skip_if_()
+{
+ case $1 in
+ root) skip_test_ must be run as root ;;
+ non-root) skip_test_ must be run as non-root ;;
+ *) ;; # FIXME?
+ esac
+}
+
+skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; }
+error_() { echo "$0: $@" 1>&2; (exit 1); exit 1; }
+framework_failure() { error_ 'failure in testing framework'; }
+
test_dir_=$(pwd)
this_test_() { echo "./$0" | sed 's,.*/,,'; }
@@ -27,7 +56,7 @@ this_test=$(this_test_)
cleanup_() { :; }
t_=$($abs_top_srcdir/tests/mkdtemp $test_dir_ cu-$this_test.XXXXXXXXXX) \
- || error "failed to create temporary directory in $test_dir_"
+ || error_ "failed to create temporary directory in $test_dir_"
# Run each test from within a temporary sub-directory named after the
# test itself, and arrange to remove it upon exception or normal exit.
@@ -35,7 +64,7 @@ trap 'st=$?; cleanup_; d='"$t_"';
cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0
trap '(exit $?); exit $?' 1 2 13 15
-cd $t_ || error "failed to cd to $t_"
+cd $t_ || error_ "failed to cd to $t_"
if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
compare() { diff -u "$@"; }