1.0.45.31: make COPY-PPRINT-DISPATCH have access to a pristine table
[sbcl.git] / tests / filesys.test.sh
index f892fee..6840181 100644 (file)
 # absolutely no warranty. See the COPYING and CREDITS files for
 # more information.
 
+. ./subr.sh
+
+use_test_subdirectory
+testdir="`pwd -P`" # resolve symbolic links in the directory.
+
+set -f # disable filename expansion in the shell.
+
 # Test DIRECTORY and TRUENAME.
-testdir=`/bin/pwd`"/filesys-test-$$"
-mkdir $testdir
-echo this is a test > $testdir/test-1.tmp
-echo this is a test > $testdir/test-2.tmp
-echo this is a test > $testdir/wild\?test.tmp
-cd $testdir
-ln -s $testdir dirlinktest
+echo this is a test > test-1.tmp
+echo this is a test > test-2.tmp
+echo this is a test > wild?test.tmp
+
+ln -s "$testdir" dirlinktest
 ln -s test-1.tmp link-1
-ln -s `pwd`/test-2.tmp link-2
+ln -s "$testdir/test-2.tmp" link-2
 ln -s i-do-not-exist link-3
 ln -s link-4 link-4
 ln -s link-5 link-6
-ln -s `pwd`/link-6 link-5
-expected_truenames=\
-"'(#p\"$testdir/\"\
-   #p\"$testdir/link-3\"\
-   #p\"$testdir/link-4\"\
-   #p\"$testdir/link-5\"\
-   #p\"$testdir/link-6\"\
-   #p\"$testdir/test-1.tmp\"\
-   #p\"$testdir/test-2.tmp\"\
-   #p\"$testdir/wild\\\\?test.tmp\")"
-$SBCL <<EOF
+ln -s "$testdir/link-6" link-5
+expected_truenames=`cat<<EOF
+(list #p"$testdir/"
+      #p"$testdir/link-3"
+      #p"$testdir/link-4"
+      #p"$testdir/link-5"
+      #p"$testdir/link-6"
+      #p"$testdir/test-1.tmp"
+      #p"$testdir/test-2.tmp"
+      #p"$testdir/wild\\\\\?test.tmp")
+EOF
+`
+# FIXME: the following tests probably can't succeed at all if the
+# testdir name contains wildcard characters or quotes.
+run_sbcl <<EOF
   (in-package :cl-user)
   (let* ((directory (directory "./*.*"))
          (truenames (sort directory #'string< :key #'pathname-name)))
@@ -50,14 +59,12 @@ $SBCL <<EOF
   (assert (equal (truename "link-4")     #p"$testdir/link-4"))
   (assert (equal (truename "link-5")     #p"$testdir/link-5"))
   (assert (equal (truename "link-6")     #p"$testdir/link-6"))
-  (sb-ext:quit :unix-status 52)
+  (sb-ext:quit :unix-status $EXIT_LISP_WIN)
 EOF
-if [ $? != 52 ]; then
-    echo DIRECTORY/TRUENAME test part 1 failed, unexpected SBCL return code=$?
-    exit 1
-fi
-cd ..
-$SBCL <<EOF
+check_status_maybe_lose "DIRECTORY/TRUENAME part 1" $?
+
+cd "$SBCL_PWD"
+run_sbcl <<EOF
   (in-package :cl-user)
   (let* ((directory (directory "$testdir/*.*"))
          (truenames (sort directory #'string< :key #'pathname-name)))
@@ -71,17 +78,14 @@ $SBCL <<EOF
   (assert (equal (truename "$testdir/link-4")     #p"$testdir/link-4"))
   (assert (equal (truename "$testdir/link-5")     #p"$testdir/link-5"))
   (assert (equal (truename "$testdir/link-6")     #p"$testdir/link-6"))
-  (sb-ext:quit :unix-status 52)
+  (sb-ext:quit :unix-status $EXIT_LISP_WIN)
 EOF
-if [ $? != 52 ]; then
-    echo DIRECTORY/TRUENAME test part 2 failed, unexpected SBCL return code=$?
-    exit 1
-fi
-rm -r $testdir
+check_status_maybe_lose "DIRECTORY/TRUENAME part 2" $?
+cleanup_test_subdirectory
 
 # Test DIRECTORY on a tree structure of directories.
-mkdir $testdir
-cd $testdir
+use_test_subdirectory
+
 touch water dirt
 mkdir animal plant
 mkdir animal/vertebrate animal/invertebrate
@@ -104,7 +108,7 @@ touch animal/vertebrate/mammal/rodent/rat
 touch animal/vertebrate/mammal/ruminant/cow
 touch animal/vertebrate/snake/python
 touch plant/kingsfoil plant/pipeweed
-$SBCL <<EOF
+run_sbcl <<EOF
 (in-package :cl-user)
 (defun absolutify (pathname)
   "Convert a possibly-relative pathname to absolute."
@@ -190,14 +194,109 @@ Lisp filename syntax idiosyncrasies)."
   #+nil
   (need-match "animal/vertebrate/mammal/robot/../**/../**/*.*" nil))
 (need-matches)
-(sb-ext:quit :unix-status 52)
+(sb-ext:quit :unix-status $EXIT_LISP_WIN)
+EOF
+check_status_maybe_lose "DIRECTORY/TRUENAME part 3" $?
+cleanup_test_subdirectory
+
+# DIRECTORY pattern matching
+use_test_subdirectory
+
+mkdir foo
+touch foo/aa.txt
+touch foo/aa.tmp
+mkdir foo/x
+mkdir far
+touch far/ab.txt
+touch far/ab.tmp
+mkdir far/x
+mkdir far/y
+mkdir far/y/x
+mkdir far/x/x
+mkdir qar
+touch qar/ac.txt
+touch qar/ac.tmp
+mkdir foo.moose
+touch foo.bar
+run_sbcl <<EOF
+(defun test (pattern &rest expected)
+  (let ((wanted (sort (mapcar #'truename expected) #'string< :key #'namestring))
+        (got (sort (directory pattern) #'string< :key #'namestring)))
+    (unless (equal wanted got)
+      (format t "wanted:~%  ~Sgot:~%  ~S" wanted got)
+      (error "wanted:~%  ~Sgot:~%  ~S" wanted got))))                 
+(test "*/a*.txt" "foo/aa.txt" "far/ab.txt" "qar/ac.txt")
+(test "fo*/a*.t*" "foo/aa.txt" "foo/aa.tmp")
+(test "*/*b.*" "far/ab.txt" "far/ab.tmp")
+(test "*a*/*.txt" "far/ab.txt" "qar/ac.txt")
+(test "*ar/*.txt" "far/ab.txt" "qar/ac.txt")
+(test "f*.*" "far/" "foo/" "foo.moose/" "foo.bar")
+(test "f*" "far/" "foo/")
+(test "*r" "far/" "qar/")
+(test "*r.*" "far/" "qar/")
+(test "f*.[mb]*" "foo.moose/" "foo.bar")
+(test "f*.m*.*")
+(test "f*.b*.*")
+(test "*/x" "foo/x/" "far/x/")
+(test "far/*/x" "far/y/x/" "far/x/x/")
+(test "**/x/" "foo/x/" "far/x/" "far/x/x" "far/y/x/")
+(quit :unix-status $EXIT_LISP_WIN)
 EOF
-if [ $? != 52 ]; then
-    echo DIRECTORY/TRUENAME test part 1 failed, unexpected SBCL return code=$?
-    exit 1
-fi
-cd ..
-rm -r $testdir
+check_status_maybe_lose "DIRECTORY/PATTERNS" $?
+
+# Test whether ENSURE-DIRECTORIES-EXIST can create a directory whose
+# name contains a wildcard character (it used to get itself confused
+# internally).
+run_sbcl --eval '(ensure-directories-exist "foo\\*bar/baz.txt")' --eval '(sb-ext:quit)'
+test -d foo*bar
+check_status_maybe_lose "ENSURE-DIRECTORIES-EXIST part 1" $? \
+    0 "(directory exists)"
+
+run_sbcl --eval '(ensure-directories-exist "foo\\?bar/baz.txt")' --eval '(sb-ext:quit)'
+test -d foo?bar
+check_status_maybe_lose "ENSURE-DIRECTORIES-EXIST part 2" $? \
+    0 "(directory exists)"
+
+# DELETE-DIRECTORY
+use_test_subdirectory
+mkdir    dont_delete_me
+touch    me_neither
+mkdir    simple_test_subdir1
+mkdir    simple_test_subdir2
+mkdir -p deep/1/2/
+touch    deep/a
+touch    deep/b
+touch    deep/1/c
+touch    deep/1/d
+touch    deep/1/2/e
+touch    deep/1/2/f
+ln -s    `pwd`/dont_delete_me deep/linky
+ln -s    `pwd`/me_neither deep/1/another_linky
+
+run_sbcl --eval '(sb-ext:delete-directory "simple_test_subdir1")' \
+         --eval '(sb-ext:delete-directory "simple_test_subdir2/")' \
+         --eval '(sb-ext:delete-directory "deep" :recursive t)' \
+         --eval '(sb-ext:quit)'
+
+test -e simple_test_subdir1
+check_status_maybe_lose "delete-directory 1" $? \
+  1 "deleted"
+
+test -e simple_test_subdir2
+check_status_maybe_lose "delete-directory 2" $? \
+  1 "deleted"
+
+test -e deep
+check_status_maybe_lose "delete-directory 3" $? \
+  1 "deleted"
+
+test -e dont_delete_me
+check_status_maybe_lose "delete-directory 4" $? \
+  0 "didn't follow link"
+
+test -e me_neither
+check_status_maybe_lose "delete-directory 5" $? \
+  0 "didn't follow link"
 
 # success convention for script
-exit 104
+exit $EXIT_TEST_WIN