1 (defpackage sb-cover-test
(:use
:cl
:asdf
:uiop
))
3 (in-package sb-cover-test
)
5 (defparameter *source-directory
*
6 (system-source-directory :sb-cover
))
7 (defparameter *output-directory
*
8 (apply-output-translations *source-directory
*))
10 (setf *default-pathname-defaults
* (translate-logical-pathname *default-pathname-defaults
*))
12 (defun compile-load (x)
13 (flet ((in-dir (dir type
)
14 (translate-logical-pathname (subpathname dir x
:type type
))))
15 (load (compile-file (in-dir *source-directory
* "lisp")
16 :output-file
(in-dir *output-directory
* "fasl")))))
20 (sb-cover:report
*output-directory
*)
22 (error "Unexpected warning"))))
24 (defun report-expect-failure ()
27 (sb-cover:report
*output-directory
*)
28 (error "Should've raised a warning"))
32 ;;; No instrumentation
33 (compile-load "test-data-1")
34 (report-expect-failure)
36 ;;; Instrument the file, try again -- first with a non-directory pathname
38 (proclaim '(optimize sb-cover
:store-coverage-data
))
39 (compile-load "test-data-1")
43 (sb-cover:report
#p
"/tmp/foo")
46 (error "REPORT with a non-pathname directory did not signal an error."))
50 (assert (probe-file (subpathname *output-directory
* "cover-index.html")))
52 ;;; None of the code was executed
53 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
54 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
55 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
56 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
58 ;;; Call the function again
62 ;;; And now we should have complete expression coverage
63 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
64 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
65 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
66 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))
67 (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
69 ;;; Reset-coverage clears the instrumentation
70 (sb-cover:reset-coverage
)
74 ;;; So none of the code should be marked as executed
75 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
76 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
77 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
78 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
80 ;;; Forget all about that file
81 (sb-cover:clear-coverage
)
82 (report-expect-failure)
84 ;;; Another file, with some branches
85 (compile-load "test-data-2")
90 ;; Complete expression coverage
91 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
92 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))
93 (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
94 ;; Partial branch coverage
95 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
96 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
97 (assert (/= (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))
98 (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
103 ;; Complete branch coverage
104 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))
105 (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
107 ;; Check for presence of constant coalescing bugs
108 (compile-load "test-data-3")
111 ;; Clean up after the tests
112 (map nil
#'delete-file
113 (directory (merge-pathnames #p
"*.html" *output-directory
*)))