delete-file.lsp 2.49 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jan 13 18:42:29 2004
;;;; Contains: Tests for DELETE-FILE

6

7 8 9 10 11

(deftest delete-file.1
  (let ((pn "scratchfile.txt"))
    (unless (probe-file pn)
      (with-open-file (s pn :direction :output)
sds's avatar
sds committed
12
                      (format s "Contents~%")))
13 14 15 16 17 18 19 20 21 22
    (values
     (notnot (probe-file pn))
     (multiple-value-list (delete-file pn))
     (probe-file pn)))
  t (t) nil)

(deftest delete-file.2
  (let ((pn #p"scratchfile.txt"))
    (unless (probe-file pn)
      (with-open-file (s pn :direction :output)
sds's avatar
sds committed
23
                      (format s "Contents~%")))
24 25 26 27 28 29 30 31
    (values
     (notnot (probe-file pn))
     (multiple-value-list (delete-file pn))
     (probe-file pn)))
  t (t) nil)

(deftest delete-file.3
  (let ((pn "CLTEST:scratchfile.txt"))
32
    (assert (typep (pathname pn) 'logical-pathname))
33 34
    (unless (probe-file pn)
      (with-open-file (s pn :direction :output)
sds's avatar
sds committed
35
                      (format s "Contents~%")))
36 37 38 39 40 41 42 43
    (values
     (notnot (probe-file pn))
     (multiple-value-list (delete-file pn))
     (probe-file pn)))
  t (t) nil)

(deftest delete-file.4
  (let ((pn "CLTEST:scratchfile.txt"))
44
    (assert (typep (pathname pn) 'logical-pathname))
45 46
    (unless (probe-file pn)
      (with-open-file (s pn :direction :output)
sds's avatar
sds committed
47
                      (format s "Contents~%")))
48 49 50 51 52 53 54 55
    (let ((s (open pn :direction :input)))
      (close s)
      (values
       (notnot (probe-file pn))
       (multiple-value-list (delete-file s))
       (probe-file pn))))
  t (t) nil)

56 57 58 59 60 61 62
;;; Specialized string tests

(deftest delete-file.5
  (do-special-strings
   (pn "scratchfile.txt" nil)
   (unless (probe-file pn)
     (with-open-file (s pn :direction :output)
sds's avatar
sds committed
63
                     (format s "Contents~%")))
64 65 66 67 68 69
   (assert (probe-file pn))
   (assert (equal (multiple-value-list (delete-file pn)) '(t)))
   (assert (not (probe-file pn))))
  nil)

;;; Error tests
70 71

(deftest delete-file.error.1
72 73
  (signals-error (delete-file) program-error)
  t)
74 75 76 77 78

(deftest delete-file.error.2
  (let ((pn "scratch.txt"))
    (unless (probe-file pn)
      (with-open-file (s pn :direction :output)
sds's avatar
sds committed
79
                      (format s "Contents~%")))
80 81
    (values
     (notnot (probe-file pn))
82
     (signals-error (delete-file "scratch.txt" nil) program-error)
83 84 85
     (notnot (probe-file pn))
     (delete-file pn)
     (probe-file pn)))
86
  t t t t nil)
87

pfdietz's avatar
pfdietz committed
88
#|
89 90 91
(deftest delete-file.error.3
  (let ((pn "nonexistent.txt"))
    (when (probe-file pn) (delete-file pn))
92
    (signals-error (delete-file "nonexistent.txt") file-error))
93
  t)
pfdietz's avatar
pfdietz committed
94
|#
95