automake-patches
[Top][All Lists]
Advanced

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

[PATCH] Testsuite: fix spurious failure of instspc.test w.r.t. AT&T Ksh.


From: Stefano Lattarini
Subject: [PATCH] Testsuite: fix spurious failure of instspc.test w.r.t. AT&T Ksh.
Date: Thu, 17 Dec 2009 14:02:18 +0100
User-agent: KMail/1.12.1 (Linux/2.6.30-2-686; KDE/4.3.2; i686; ; )

Hello automakers.

I found out that the AT&T version of Ksh on Debian has a weird bug
regarding the `pwd' builtin, which causes a spurious failure of the
`instspc.test' test script.

The bug is somewhat subtle and lengthy to describe, but the fix is easy,
so bear with me.

-*-*-

First, system information:

 $ uname -a
 Linux bigio 2.6.30-2-686 #1 SMP Sat Sep 26 01:16:22 UTC 2009 i686 GNU/Linux
 
 $ cat /etc/debian_version
 squeeze/sid
 
 $ dpkg -l ksh
 ||/ Name    Version       Description
 +++--------------------------------------------------------------------
 ii  ksh        93t+-2        The real, AT&T version of the Korn shell
 
 $ ksh -c 'echo "$KSH_VERSION"; echo "${.sh.version}"'
 Version JM 93t+ 2009-05-01
 Version JM 93t+ 2009-05-01

 $ /bin/pwd --version
 pwd (GNU coreutils) 7.4
 Copyright (C) 2009 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
 Written by Jim Meyering.

-*-*-

The bug of Ksh is related to the use of the `pwd' builtin (or the $PWD
special variable) when a directory named `...' (exactly three dots) is
involved.  It can be reproduced as follows:

 $ cat foo.ksh
 : SETUP
 set -x
 type pwd
 mkdir /tmp/ksh-bug && cd /tmp/ksh-bug || exit 1
 mkdir '...' '....' || exit 1
 : BUG TRIGGERED
 (cd ... && pwd && cd .. && pwd) || exit 1
 : BUG TRIGGERED
 (cd ... && echo $PWD && cd .. && echo $PWD) || exit 1
 : BUG NOT TRIGGERED
 (cd ... && /bin/pwd && cd .. && /bin/pwd) || exit 1
 : BUG NOT TRIGGERED
 (cd .... && pwd && cd .. && pwd) || exit 1
 : CLEANUP
 rmdir '...' '....' && cd /tmp && rmdir /tmp/ksh-bug
 
 $ ksh foo.ksh                                                                 
 + whence -v pwd                         
 pwd is a shell builtin
 + mkdir /tmp/ksh-bug
 + cd /tmp/ksh-bug
 + mkdir ... ....
 + : BUG TRIGGERED
 + cd ...
 + pwd
 /tmp/ksh-bug/...
 + cd ..
 + pwd
 /tmp/ksh-bug/.../..
 + : BUG TRIGGERED
 + cd ...
 + echo /tmp/ksh-bug/...
 /tmp/ksh-bug/...
 + cd ..
 + echo /tmp/ksh-bug/.../..
 /tmp/ksh-bug/.../..
 + : BUG NOT TRIGGERED
 + cd ...
 + /bin/pwd
 /tmp/ksh-bug/...
 + cd ..
 + /bin/pwd
 /tmp/ksh-bug
 + : BUG NOT TRIGGERED
 + cd ....
 + pwd
 /tmp/ksh-bug/....
 + cd ..
 + pwd
 /tmp/ksh-bug
 + : CLEANUP
 + rmdir ... ....
 + cd /tmp
 + rmdir /tmp/ksh-bug

-*-*-

This bug caused an error in the instspc.test script, mostly because
ksh (as many other shells do) probably treats the `pwd' builtin as
roughly equivalent to `echo $PWD':
 # sh can be bash (4.0 or 3.2), dash, AT&T ksh or even zsh (4.3.10 or 3.0.8)
 $ sh -c 'mkdir /tmp/none; cd /tmp/none; rmdir /tmp/none; /bin/pwd; pwd'
 /bin/pwd: couldn't find directory entry in `..' with matching i-node
 /tmp/none
 # Public Domain Korn Shell and Heirloom Sh have a saner behaviour
 $ pdksh -c 'mkdir /tmp/none; cd /tmp/none; rmdir /tmp/none; /bin/pwd; pwd'
 /bin/pwd: couldn't find directory entry in `..' with matching i-node
 pdksh: pwd: can't get current directory - No such file or directory
 $ heirloom sh -c 'mkdir /tmp/none; cd /tmp/none; rmdir /tmp/none; /bin/pwd; 
pwd'
 /bin/pwd: couldn't find directory entry in `..' with matching i-node
 sh: cannot determine current directory

-*-*-

The following example finally show how the AT&T ksh bug and the `pwd'
builtin's behaviour just described combine to cause a spurious failure
in the test script `instspc.test':

 $ cat bar.ksh
 set -x -e
 mkdir /tmp/ksh-bug
 cd /tmp/ksh-bug
 # `$file' is `...', `$test' is `build'
 mkdir sub1 ./...
 cd ./...
 cd ..
 rm -rf sub1 ./...
 pwd; /bin/pwd
 # `$file' is `...', `$test' is `install'
 mkdir sub1 ./...
 cd sub1
 cd ..
 rm -rf sub1 ./...
 pwd; /bin/pwd
 # `$file' is `a:', `$test' is `build'
 mkdir sub1 ./a:
 pwd; /bin/pwd
 cd `pwd`/a: || echo KO
 # apparently, this is equiavalent to "cd `pwd`/a:", which for AT&T Ksh
 # happens to be `/tmp/ksh-bug/.../../a:' -- and this doesn't exists!
 cd ./a: || echo KO

 $ ksh bar.ksh
 + mkdir /tmp/ksh-bug
 + cd /tmp/ksh-bug
 + mkdir sub1 ./...
 + cd ./...
 + cd ..
 + rm -rf sub1 ./...
 + pwd
 /tmp/ksh-bug/.../..
 + /bin/pwd
 /tmp/ksh-bug
 + mkdir sub1 ./...
 + cd sub1
 + cd ..
 + rm -rf sub1 ./...
 + pwd
 /tmp/ksh-bug/.../..
 + /bin/pwd
 /tmp/ksh-bug
 + mkdir sub1 ./a:
 + pwd
 /tmp/ksh-bug/.../..
 + /bin/pwd
 /tmp/ksh-bug
 + pwd
 + cd /tmp/ksh-bug/.../../a:
 bar.ksh[19]: cd: /tmp/ksh-bug/.../../a:: [No such file or directory]
 + echo KO
 KO
 + cd ./a
 bar.ksh[22]: cd: ./a:: [No such file or directory]
 + echo KO
 KO

-*-*-

Well, the description of the bug was convoluted, but at least the patch
to fix it is very simple, and is attached.

Regards,
    Stefano
From 53c9c8d387e4f7f8cbac749bc0e30cbd7e8ba636 Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Wed, 16 Dec 2009 22:51:43 +0100
Subject: [PATCH] Testsuite: fix a spurious failure w.r.t. AT&T Ksh.

* tests/instspc.test ($ocwd): New variable, holding the full path
of the current directory.
(Loop on $file): Use `cd $ocwd' instead of `cd ..' to chdir back
to the previous directory; this is required to work around a bug
of AT&T Korn shell w.r.t. directories named `...'.
---
 ChangeLog          |    9 +++++++++
 tests/instspc.test |   12 +++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3e0f5b4..ae79c4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-12-16  Stefano Lattarini  <address@hidden>
+
+       Testsuite: fix a spurious failure w.r.t. AT&T Ksh.
+       * tests/instspc.test ($ocwd): New variable, holding the full path
+       of the current directory.
+       (Loop on $file): Use `cd $ocwd' instead of `cd ..' to chdir back
+       to the previous directory; this is required to work around a bug
+       of AT&T Korn shell w.r.t. directories named `...'.
+
 2009-12-05  Antonio Diaz Diaz  <address@hidden>
 
        Replace unlzma, gunzip, bunzip2 with pack tool -d invocation.
diff --git a/tests/instspc.test b/tests/instspc.test
index 414b3e5..9b8e6c6 100755
--- a/tests/instspc.test
+++ b/tests/instspc.test
@@ -121,13 +121,16 @@ for file in \
   "a${sp}b" "a${sp}${sp}b" "a${lf}b" ... a:
 do
   for test in build install; do
+
+    ocwd=`pwd`
+
     case $test in
     build)
       build=$file
-      dest=`pwd`/sub1;;
+      dest=$ocwd/sub1;;
     install)
       build=sub1
-      dest=`pwd`/$file;;
+      dest=$ocwd/$file;;
     esac
 
     # Make sure this system supports this character in file names.
@@ -140,9 +143,12 @@ do
     DESTDIR=$dest file=$file $MAKE -e test-install-sep ||
       eval "${test}_failures=\"\$${test}_failures$lf\$file\""
 
-    cd ..
+    # Don't use `cd ..', or a nasty bug of AT&T Ksh will be triggered
+    # when `$file' is `...'
+    cd "$ocwd"
 
     rm -fr sub1 "./$file"
+
   done
 done
 
-- 
1.6.5


reply via email to

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