file-error.lsp 2.63 KB
Newer Older
1
2
3
4
5
6
7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jan 13 19:10:02 2004
;;;; Contains: Tests of the FILE-ERROR condition, and associated accessor function

(deftest file-error.1
  (let ((pn (make-pathname :name :wild
sds's avatar
sds committed
8
9
10
                           :type "txt"
                           :version :newest
                           :defaults *default-pathname-defaults*)))
11
12
13
    (handler-case
     (probe-file pn)
     (error (c)
sds's avatar
sds committed
14
15
16
17
18
            (values
             (notnot (typep c 'file-error))
             (if (equalp (file-error-pathname c) pn)
                 t
               (list (file-error-pathname c) pn))))))
19
20
21
  t t)

(deftest file-error-pathname.1
22
  (let ((c (make-condition 'file-error :pathname "foo.txt")))
23
24
25
26
    (values
     (notnot (typep c 'file-error))
     (eqlt (class-of c) (find-class 'file-error))
     (file-error-pathname c)))
27
  t t "foo.txt")
28
29

(deftest file-error-pathname.2
30
  (let ((c (make-condition 'file-error :pathname #p"foo.txt")))
31
32
33
    (values
     (notnot (typep c 'file-error))
     (eqlt (class-of c) (find-class 'file-error))
34
     (equalt #p"foo.txt" (file-error-pathname c))))
35
36
37
  t t t)

(deftest file-error-pathname.3
38
  (let ((c (make-condition 'file-error :pathname "CLTEST:foo.txt")))
39
40
41
    (values
     (notnot (typep c 'file-error))
     (eqlt (class-of c) (find-class 'file-error))
42
     (equalpt "CLTEST:foo.txt"
sds's avatar
sds committed
43
              (file-error-pathname c))))
44
45
46
  t t t)

(deftest file-error-pathname.4
47
  (let ((c (make-condition
48
            'file-error :pathname (logical-pathname "CLTEST:foo.txt"))))
49
50
51
    (values
     (notnot (typep c 'file-error))
     (eqlt (class-of c) (find-class 'file-error))
52
     (equalpt (logical-pathname "CLTEST:foo.txt")
sds's avatar
sds committed
53
              (file-error-pathname c))))
54
55
56
  t t t)

(deftest file-error-pathname.5
57
  (with-open-file (s "file-error.txt" :direction :input)
sds's avatar
sds committed
58
59
60
61
62
                  (let ((c (make-condition 'file-error :pathname s)))
                    (values
                     (notnot (typep c 'file-error))
                     (eqlt (class-of c) (find-class 'file-error))
                     (equalpt s (file-error-pathname c)))))
63
64
65
  t t t)

(deftest file-error-pathname.6
66
  (let ((s (open "file-error.txt" :direction :input)))
67
68
69
70
71
72
73
74
75
    (close s)
    (let ((c (make-condition 'file-error :pathname s)))
      (values
       (notnot (typep c 'file-error))
       (eqlt (class-of c) (find-class 'file-error))
       (equalpt s (file-error-pathname c)))))
  t t t)

(deftest file-error-pathname.error.1
76
77
  (signals-error (file-error-pathname) program-error)
  t)
78
79

(deftest file-error-pathname.error.2
80
  (signals-error
81
   (file-error-pathname
82
    (make-condition 'file-error :pathname "foo.txt")
83
84
    nil)
   program-error) t)