1 (defpackage sb-cover-test
4 (in-package sb-cover-test
)
6 (defparameter *path
* #.
(truename *compile-file-pathname
*))
7 (defparameter *output-directory
*
8 (merge-pathnames (make-pathname :name nil
11 :directory
'(:relative
"test-output"))
12 (make-pathname :directory
(pathname-directory *path
*))))
16 (sb-cover:report
*output-directory
*)
18 (error "Unexpected warning"))))
20 (defun report-expect-failure ()
23 (sb-cover:report
*output-directory
*)
24 (error "Should've raised a warning"))
27 ;;; No instrumentation
28 (load (compile-file (merge-pathnames #p
"test-data-1.lisp" *path
*)))
29 (report-expect-failure)
31 ;;; Instrument the file, try again -- first with a non-directory pathname
33 (proclaim '(optimize sb-cover
:store-coverage-data
))
34 (load (compile-file (merge-pathnames #p
"test-data-1.lisp" *path
*)))
38 (sb-cover:report
#p
"/tmp/foo")
41 (error "REPORT with a non-pathname directory did not signal an error."))
45 (assert (probe-file (make-pathname :name
"cover-index" :type
"html"
46 :defaults
*output-directory
*)))
48 ;;; None of the code was executed
49 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
50 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
51 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
52 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
54 ;;; Call the function again
58 ;;; And now we should have complete expression coverage
59 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
60 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
61 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
62 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))
63 (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
65 ;;; Reset-coverage clears the instrumentation
66 (sb-cover:reset-coverage
)
70 ;;; So none of the code should be marked as executed
71 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
72 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
73 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
74 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
76 ;;; Forget all about that file
77 (sb-cover:clear-coverage
)
78 (report-expect-failure)
80 ;;; Another file, with some branches
81 (load (compile-file (merge-pathnames #p
"test-data-2.lisp" *path
*)))
86 ;; Complete expression coverage
87 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
88 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))
89 (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
90 ;; Partial branch coverage
91 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
92 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
93 (assert (/= (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))
94 (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
99 ;; Complete branch coverage
100 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))
101 (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
103 ;; Check for presence of constant coalescing bugs
105 (load (compile-file (merge-pathnames #p
"test-data-3.lisp" *path
*)))
108 ;; Clean up after the tests
110 (map nil
#'delete-file
111 (directory (merge-pathnames #p
"*.html" *output-directory
*)))