X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-posix%2Fposix-tests.lisp;h=c95359ef3d64463aba17b5faeb4c39fe2be3967a;hb=126e0a851c7e170b13c206c530083fc48572ea60;hp=f8e92b6f54c0f69717f1cf00f81b3907f366eeef;hpb=e855e0537e05f315d26cf8778353a3be02ee760b;p=sbcl.git diff --git a/contrib/sb-posix/posix-tests.lisp b/contrib/sb-posix/posix-tests.lisp index f8e92b6..c95359e 100644 --- a/contrib/sb-posix/posix-tests.lisp +++ b/contrib/sb-posix/posix-tests.lisp @@ -12,7 +12,7 @@ (defvar *current-directory* *default-pathname-defaults*) (defvar *this-file* *load-truename*) - + (deftest chdir.1 (sb-posix:chdir *test-directory*) 0) @@ -47,7 +47,7 @@ (sb-posix:syscall-error (c) (sb-posix:syscall-errno c))) #.sb-posix::enotdir) - + (deftest mkdir.1 (let ((dne (make-pathname :directory '(:relative "mkdir.does-not-exist.1")))) (unwind-protect @@ -84,7 +84,7 @@ (sb-posix:syscall-error (c) (sb-posix:syscall-errno c))) #.sb-posix::eacces) - + (deftest rmdir.1 (let ((dne (make-pathname :directory '(:relative "rmdir.does-not-exist.1")))) (ensure-directories-exist (merge-pathnames dne *test-directory*)) @@ -153,7 +153,7 @@ (sb-posix:rmdir dir) (sb-posix:syscall-errno c)))) #.sb-posix::eacces) - + (deftest stat.1 (let* ((stat (sb-posix:stat *test-directory*)) (mode (sb-posix::stat-mode stat))) @@ -205,20 +205,81 @@ (sb-posix:rmdir dir) (sb-posix:syscall-errno c)))) #.sb-posix::eacces) + +;;; stat-mode tests +(defmacro with-stat-mode ((mode pathname) &body body) + (let ((stat (gensym))) + `(let* ((,stat (sb-posix:stat ,pathname)) + (,mode (sb-posix::stat-mode ,stat))) + ,@body))) + +(defmacro with-lstat-mode ((mode pathname) &body body) + (let ((stat (gensym))) + `(let* ((,stat (sb-posix:lstat ,pathname)) + (,mode (sb-posix::stat-mode ,stat))) + ,@body))) + +(deftest stat-mode.1 + (with-stat-mode (mode *test-directory*) + (sb-posix:s-isreg mode)) + 0) + +(deftest stat-mode.2 + (with-stat-mode (mode *test-directory*) + (zerop (sb-posix:s-isdir mode))) + nil) + +(deftest stat-mode.3 + (with-stat-mode (mode *test-directory*) + (sb-posix:s-ischr mode)) + 0) +(deftest stat-mode.4 + (with-stat-mode (mode *test-directory*) + (sb-posix:s-isblk mode)) + 0) + +(deftest stat-mode.5 + (with-stat-mode (mode *test-directory*) + (sb-posix:s-isfifo mode)) + 0) + +(deftest stat-mode.6 + (with-stat-mode (mode *test-directory*) + (sb-posix:s-issock mode)) + 0) + +(deftest stat-mode.7 + (let ((link-pathname (make-pathname :name "stat-mode.7" + :defaults *test-directory*))) + (unwind-protect + (progn + (sb-posix:symlink *test-directory* link-pathname) + (with-lstat-mode (mode link-pathname) + (zerop (sb-posix:s-islnk mode)))) + (ignore-errors (sb-posix:unlink link-pathname)))) + nil) + +(deftest stat-mode.8 + (let ((pathname (make-pathname :name "stat-mode.8" + :defaults *test-directory*))) + (unwind-protect + (progn + (with-open-file (out pathname :direction :output) + (write-line "test" out)) + (with-stat-mode (mode pathname) + (zerop (sb-posix:s-isreg mode)))) + (ignore-errors (delete-file pathname)))) + nil) + ;;; see comment in filename's designator definition, in macros.lisp (deftest filename-designator.1 - (progn - ;; we use run-program to bypass the wildcard quoting in the - ;; highlevel CL functions like OPEN - (sb-ext:run-program "touch" - (list - (format nil "~A/[foo].txt" - (namestring *test-directory*))) - :search t :wait t ) - ;; if this test fails, it will probably be with - ;; "System call error 2 (No such file or directory)" - (let ((*default-pathname-defaults* *test-directory*)) - (sb-posix:unlink (car (directory "*.txt"))))) + (let ((file (format nil "~A/[foo].txt" (namestring *test-directory*)))) + ;; creat() with a string as argument + (sb-posix:creat file 0) + ;; if this test fails, it will probably be with + ;; "System call error 2 (No such file or directory)" + (let ((*default-pathname-defaults* *test-directory*)) + (sb-posix:unlink (car (directory "*.txt"))))) 0)