Apply "search for cp" patch by Hraban Luyat
[sbcl.git] / tests / side-effectful-pathnames.test.sh
blobfa4b659935c58e272ce166ac82cc6d2b8717f5ea
1 #!/bin/sh
3 # This software is part of the SBCL system. See the README file for
4 # more information.
6 # While most of SBCL is derived from the CMU CL system, the test
7 # files (like this one) were written from scratch after the fork
8 # from CMU CL.
10 # This software is in the public domain and is provided with
11 # absolutely no warranty. See the COPYING and CREDITS files for
12 # more information.
14 . ./subr.sh
16 use_test_subdirectory
17 testdir="`pwd -P`" # resolve symbolic links in the directory.
19 # LOADing and COMPILEing files with logical pathnames
20 testfilestem="load-test"
21 StudlyCapsStem="Load-Test"
22 testfilename="$testfilestem.lisp"
23 cat >$testfilename <<EOF
24 (in-package :cl-user)
25 (defparameter *loaded* :yes)
26 EOF
27 run_sbcl <<EOF
28 (in-package :cl-user)
29 (setf (logical-pathname-translations "TEST")
30 (list (list "**;*.*.*" "$testdir/**/*.*")))
31 (format t "/translations=~S~%" (logical-pathname-translations "TEST"))
32 (let* ((untranslated "test:$StudlyCapsStem.lisp")
33 (ignore-me (format t "untranslated=~S~%" untranslated))
34 (translation (namestring (translate-logical-pathname untranslated)))
35 (expected-translation "$testdir/$testfilestem.lisp"))
36 (declare (ignore ignore-me))
37 (format t "translation=~S~%" translation)
38 (format t "expected-translation=~S~%" expected-translation)
39 (assert (string= translation expected-translation)))
40 (format t "about to LOAD ~S~%" "TEST:$StudlyCapsStem")
41 (load "TEST:$StudlyCapsStem")
42 (assert (eq *loaded* :yes))
43 ;; COMPILE-FILE returns truenames unless SB-C::*MERGE-PATHNAMES* is set it NIL
44 ;; so that you don't see pathnames returned that are immediately useless
45 ;; on another machine, in which case we should just explicitly call TRUENAME
46 ;; to get the expected result for this test, which is of course meaningless,
47 ;; because my 'pwd' is here:
48 ;; /google/src/cloud/..somewhere...EA0643B31763702B4088D15FEA8C1700_1/google3/third_party/lisp/sbcl
49 ;; but it "wants" to see:
50 ;; /build/work/bb4efcf5cc6f5221b1a246e4fe09dd16eed5/google3/tmp/side-effectful-pathnames-test-4187/load-test.fasl"
51 ;; even though a different execution's might as well be here (or anywhere):
52 ;; /build/work/698d0e844a200a4c30cf75e6233b55b215ea/google3/runfiles/google3/third_party/lisp/sbcl/src/tests
53 ;; So is it better to have a kludged passing test, or a failing test?
54 ;; And is it better to change the test's expectation, or "force" a valid result?
55 ;; I don't know the answer to those questions, and I don't care.
56 (let ((compiled-file-name (namestring (truename (compile-file "TEST:$StudlyCapsStem"))))
57 (expected-file-name "$testdir/$testfilestem.fasl"))
58 (format t "compiled-file-name=~S~%" compiled-file-name)
59 (format t "expected-file-name=~S~%" expected-file-name)
60 (assert (string= compiled-file-name expected-file-name)))
61 (sb-ext:quit :unix-status $EXIT_LISP_WIN)
62 EOF
63 check_status_maybe_lose "LOAD/COMPILE" $?
65 # In the flaky1 branch, Dan Barlow pointed out that
66 # ENSURE-DIRECTORIES-EXIST failed for these relative pathname
67 # operations when the mysterious special case handling of "" pathnames
68 # was removed from UNIX-STAT. Let's make sure that it works now.
70 # Set up an empty directory to work with.
71 testdir="${TMPDIR:-/tmp}/sbcl-mkdir-test-$$"
72 if ! rm -rf "$testdir" ; then
73 echo "$testdir already exists and could not be deleted"
74 exit 1;
76 mkdir "$testdir"
77 cd "$testdir"
79 # Provoke failure.
80 run_sbcl <<EOF
81 (let ((rel-name #p"foo/bar/")
82 (abs-name (merge-pathnames #p"baz/quux/" (truename "."))))
83 (and
84 (equalp (ensure-directories-exist abs-name) abs-name)
85 (equalp (ensure-directories-exist rel-name) rel-name)
86 (sb-ext:exit :code 52)))
87 EOF
88 check_status_maybe_lose "ENSURE-DIRECTORIES-EXIST" $?
89 if [ ! -d "$testdir/foo/bar" ] ; then
90 echo test failed: "$testdir/foo/bar" is not a directory
91 find "$testdir" -print
92 exit 1
93 fi;
94 if [ ! -d "$testdir/baz/quux" ] ; then
95 echo test failed: "$testdir/baz/quux" is not a directory
96 find "$testdir" -print
97 exit 1
98 fi;
100 # We succeeded, life is good. Now we don't need the test directory
101 # any more; and come back home.
102 cd "$SBCL_PWD"
103 rm -r "$testdir"
105 exit $EXIT_TEST_WIN