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
33 (proclaim '(optimize sb-cover
:store-coverage-data
))
34 (load (compile-file (merge-pathnames #p
"test-data-1.lisp" *path
*)))
38 (assert (probe-file (make-pathname :name
"cover-index" :type
"html"
39 :defaults
*output-directory
*)))
41 ;;; None of the code was executed
42 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
43 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
44 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
45 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
47 ;;; Call the function again
51 ;;; And now we should have complete expression coverage
52 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
53 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
54 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
55 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))
56 (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
58 ;;; Reset-coverage clears the instrumentation
59 (sb-cover:reset-coverage
)
63 ;;; So none of the code should be marked as executed
64 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
65 (assert (zerop (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
66 (assert (zerop (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
67 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
69 ;;; Forget all about that file
70 (sb-cover:clear-coverage
)
71 (report-expect-failure)
73 ;;; Another file, with some branches
74 (load (compile-file (merge-pathnames #p
"test-data-2.lisp" *path
*)))
79 ;; Complete expression coverage
80 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))))
81 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :expression
))
82 (sb-cover::all-of
(getf sb-cover
::*counts
* :expression
))))
83 ;; Partial branch coverage
84 (assert (plusp (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))))
85 (assert (plusp (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
86 (assert (/= (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))
87 (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))
92 ;; Complete branch coverage
93 (assert (= (sb-cover::ok-of
(getf sb-cover
::*counts
* :branch
))
94 (sb-cover::all-of
(getf sb-cover
::*counts
* :branch
))))