1.0.9.27: Fix large file support for MIPS.
[sbcl/tcr.git] / contrib / sb-cover / tests.lisp
blob6fb3d9a4006c6a8cadd48fc88e178b1f0f9b269e
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
33 (proclaim '(optimize sb-cover:store-coverage-data))
34 (load (compile-file (merge-pathnames #p"test-data-1.lisp" *path*)))
36 (report)
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
48 (test1)
49 (report)
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)
61 (report)
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*)))
76 (test2 1)
77 (report)
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))))
89 (test2 0)
90 (report)
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))))