Rename FIND-SYMBOL*, and INTERN* to FIND-SYMBOL-FROM-SUBSTRING, and INTERN-FROM-SUBST...
[sbcl/tcr.git] / contrib / sb-cover / tests.lisp
blobea54b7537680fe9e354673714441afd61ef9e5aa
1 (defpackage sb-cover-test
2 (:use "CL"))
4 (in-package sb-cover-test)
6 (defparameter *path* #.(truename *compile-file-pathname*))
7 (defparameter *output-directory*
8 (merge-pathnames (make-pathname :name nil
9 :type nil
10 :version nil
11 :directory '(:relative "test-output"))
12 (make-pathname :directory (pathname-directory *path*))))
14 (defun report ()
15 (handler-case
16 (sb-cover:report *output-directory*)
17 (warning ()
18 (error "Unexpected warning"))))
20 (defun report-expect-failure ()
21 (handler-case
22 (progn
23 (sb-cover:report *output-directory*)
24 (error "Should've raised a warning"))
25 (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*)))
36 (catch 'ok
37 (handler-case
38 (sb-cover:report #p"/tmp/foo")
39 (error ()
40 (throw 'ok nil)))
41 (error "REPORT with a non-pathname directory did not signal an error."))
43 (report)
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
55 (test1)
56 (report)
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)
68 (report)
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*)))
83 (test2 1)
84 (report)
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))))
96 (test2 0)
97 (report)
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*)))
106 (test-2)
108 ;; Clean up after the tests
110 (map nil #'delete-file
111 (directory (merge-pathnames #p"*.html" *output-directory*)))