bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] test-framework-sh: minor cleanups


From: Paul Eggert
Subject: [PATCH 2/2] test-framework-sh: minor cleanups
Date: Fri, 25 Mar 2016 12:46:30 -0700

* tests/init.sh (testdir_prefix_): Output a trailing newline,
since strictly speaking POSIX requires this.
(setup_): Do not use the variable 'fail', as that makes the
trace output harder to read ('fail' is typically used by
tests to mean the test failed).  Treat // portably.
Check that new directory is not merely a sibling of the tmp dir.
Avoid unnecessary invocation of tr.
---
 ChangeLog     |  9 +++++++++
 tests/init.sh | 19 ++++++++-----------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 545e7a9..ca6c36b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2016-03-25  Paul Eggert  <address@hidden>
 
+       test-framework-sh: minor cleanups
+       * tests/init.sh (testdir_prefix_): Output a trailing newline,
+       since strictly speaking POSIX requires this.
+       (setup_): Do not use the variable 'fail', as that makes the
+       trace output harder to read ('fail' is typically used by
+       tests to mean the test failed).  Treat // portably.
+       Check that new directory is not merely a sibling of the tmp dir.
+       Avoid unnecessary invocation of tr.
+
        test-framework-sh: revert port to NetBSD 7.0
        It was a false alarm; I misinterpreted Assaf Gordon's report.
        * tests/init.sh (testdir_prefix_, pfx_, template_length_):
diff --git a/tests/init.sh b/tests/init.sh
index 71c4526..97e4e4b 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -472,7 +472,6 @@ setup_ ()
   fi
 
   initial_cwd_=$PWD
-  fail=0
 
   pfx_=`testdir_prefix_`
   test_dir_=`mktempd_ "$initial_cwd_" "$pfx_-$ME_.XXXX"` \
@@ -556,8 +555,9 @@ mktempd_ ()
   # Disallow any trailing slash on specified destdir:
   # it would subvert the post-mktemp "case"-based destdir test.
   case $destdir_ in
-  /) ;;
+  / | //) destdir_slash_=$destdir;;
   */) fail_ "invalid destination dir: remove trailing slash(es)";;
+  *) destdir_slash_=$destdir_/;;
   esac
 
   case $template_ in
@@ -567,20 +567,17 @@ mktempd_ ()
   esac
 
   # First, try to use mktemp.
-  d=`unset TMPDIR; { mktemp -d -t -p "$destdir_" "$template_"; } 2>/dev/null` \
-    || fail=1
+  d=`unset TMPDIR; { mktemp -d -t -p "$destdir_" "$template_"; } 2>/dev/null` 
&&
 
   # The resulting name must be in the specified directory.
-  case $d in "$destdir_"*);; *) fail=1;; esac
+  case $d in "$destdir_slash_"*) :;; *) false;; esac &&
 
   # It must have created the directory.
-  test -d "$d" || fail=1
+  test -d "$d" &&
 
   # It must have 0700 permissions.  Handle sticky "S" bits.
-  perms=`ls -dgo "$d" 2>/dev/null|tr S -` || fail=1
-  case $perms in drwx------*) ;; *) fail=1;; esac
-
-  test $fail = 0 && {
+  perms=`ls -dgo "$d" 2>/dev/null` &&
+  case $perms in drwx--[-S]---*) :;; *) false;; esac && {
     echo "$d"
     return
   }
@@ -599,7 +596,7 @@ mktempd_ ()
   i_=1
   while :; do
     X_=`rand_bytes_ $nx_`
-    candidate_dir_="$destdir_/$base_template_$X_"
+    candidate_dir_="$destdir_slash_$base_template_$X_"
     err_=`mkdir -m 0700 "$candidate_dir_" 2>&1` \
       && { echo "$candidate_dir_"; return; }
     test $MAX_TRIES_ -le $i_ && break;
-- 
2.5.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]