Add test coverage check
[wolf] / src / test / main.lisp
1 ; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3.  See distributed LICENSE.txt.
2 (in-package #:wolf-test)
3
4 (defparameter *tests* nil)
5
6 (defmacro deftest (filename success &optional msg line-no col-no copyright-notice)
7  `(push
8    (lambda ()
9     (let
10      ((green (format nil "~c[1;32m" #\Esc))
11       (red (format nil "~c[1;31m" #\Esc))
12       (result (wolf:check-file ,filename :copyright-notice ,copyright-notice)))
13      (cond
14       ((not (eql ,success (car result)))
15        (format t "~A- ~A failed, expected ~A and got ~A~c[0m~%"
16         red ,filename ,success (car result) #\Esc))
17       ((and (eql :failure ,success) (string/= ,msg (third result)))
18        (format t "~A- ~A failed, expected msg ~A and got msg ~A~c[0m~%"
19         red ,filename ,msg (third result) #\Esc))
20       ((and (eql :failure ,success) (/= ,line-no (fourth result)))
21        (format t "~A- ~A failed, expected line ~A and got line ~A~c[0m~%"
22         red ,filename ,line-no (fourth result) #\Esc))
23       ((and (eql :failure ,success) (/= ,col-no (fifth result)))
24        (format t "~A- ~A failed, expected column ~A and got column ~A~c[0m~%"
25         red ,filename ,col-no (fifth result) #\Esc))
26       (t (format t "~A- ~A passed ~c[0m~%" green ,filename #\Esc) t))))
27    *tests*))
28
29 ; This really is just here to check against regressions
30 (defun run-all-tests ()
31  (let
32   ((results (mapcar #'funcall *tests*)))
33   (every #'identity results)))
34
35 (deftest #P"resources/commentneedsspace.lisp" :failure "Multiline top level forms must be separated by a space" 6 0)
36 (deftest #P"resources/emptylineatend.lisp" :failure "Must not end with empty line" 8 0)
37 (deftest #P"resources/good.lisp" :success)
38 (deftest #P"resources/goodcomment.lisp" :success)
39 (deftest #P"resources/hangingcloseparens1.lisp" :failure "No hanging close parens" 11 0)
40 (deftest #P"resources/hangingcloseparens2.lisp" :failure "No hanging close parens" 12 1)
41 (deftest #P"resources/internalsymbols.lisp" :failure "No internal symbols from other packages" 6 22)
42 (deftest #P"resources/invalidindent1.lisp" :failure "All form elements must be indented equally" 9 5)
43 (deftest #P"resources/invalidindent2.lisp" :failure "All form elements must be indented equally" 11 6)
44 (deftest #P"resources/longform.lisp" :failure "Forms can't be over 50 lines long" 117 60)
45 (deftest #P"resources/longline.lisp" :failure "Line longer than 120 characters" 2 0)
46 (deftest #P"resources/newlineafteropenparens.lisp" :failure "No new line after opening form" 11 5)
47 (deftest #P"resources/nopackage.lisp" :failure "Must begin with in-package form" 0 0)
48 (deftest #P"resources/package.lisp" :success)
49 (deftest #P"resources/spaceafteropenparens.lisp" :failure "No space after opening parens" 11 5)
50 (deftest #P"resources/tabs.lisp" :failure "Must not use tabs" 4 0)
51 (deftest #P"resources/toplevelindented.lisp" :failure "Top level forms must begin on first column" 3 1)
52 (deftest #P"resources/twoemptylines.lisp" :failure "Must not have two empty lines in a row" 2 0)
53 (deftest #P"resources/twoemptylineswithcomment.lisp" :failure "Must not have two empty lines in a row" 8 0)
54 (deftest #P"resources/twoinpackage.lisp" :failure "Only one in-package per file" 9 0)
55 (deftest #P"resources/twospaces.lisp" :failure "Only one space between items of a form" 8 6)
56 (deftest #P"resources/unspacedforms.lisp" :failure "Multiline top level forms must be separated by a space" 4 0)
57 (deftest #P"resources/whitespaceendline.lisp" :failure "No whitespace at end of line" 4 106)
58 (deftest #P"resources/whitespacelines.lisp" :failure "No whitespace only lines" 1 1)
59 (deftest #P"resources/copyrightnotice.lisp" :success nil nil nil "; Copyright XXXX AGPL")
60 (deftest #P"resources/copyrightnotice.lisp" :failure "Must begin with in-package form" 0 0)
61 (deftest #P"resources/package.lisp" :failure "Must begin with specified copyright notice" 0 0 "; Copyright XXXX AGPL")
62 (deftest #P"resources/unmatchedending.lisp" :failure "Unmatched ending paren" 2 12)
63
64 ; This is not a check for actually validity, but rather that the check directory code
65 ; checks the directory.
66 (push
67  (lambda ()
68   (let
69    ((*standard-output* (make-broadcast-stream))
70     (*error-output* (make-broadcast-stream)))
71    (wolf:pretty-print-check-directory #P"resources/dircheck"
72     :copyright-notice "; Copyright XXXX AGPL")
73    (wolf:pretty-print-check-directory #P"resources/dircheck"))
74   t)
75  *tests*)