Skip to content

Commit 0850639

Browse files
committed
Add ability to exclude tests from the run
(because I dont always want to run emailing tests), but I want to be able to run them re ADWolf:#1354
1 parent 154135e commit 0850639

File tree

1 file changed

+53
-21
lines changed

1 file changed

+53
-21
lines changed

lisp-unit.lisp

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,32 +123,50 @@
123123
(warn 'missing-test :test-name id)))
124124

125125
(defun get-tests (&key tests tags package reintern-package
126+
exclude-tests exclude-tags
126127
&aux (db *test-db*))
127128
"finds tests by names, tags, and package
128129
129130
if reintern-package is provided, reintern all symbols provided for tests
130131
and tags into the reintern-package. Mostly provided for easing conversion
131132
of lisp-unit1 test suites
132133
"
133-
(%log-around (#?"get-tests:${tests} tags:${tags} package:${package} reintern-package:${reintern-package}"
134+
(%log-around (#?"get-tests:${tests} tags:${tags} package:${package} reintern-package:${reintern-package} exclude-tags:${exclude-tags} exclude-tests:${ exclude-tests }"
134135
:start-level 0)
136+
135137
(when reintern-package
136-
(setf tests (%in-package tests reintern-package))
137-
(setf tags (%in-package tags reintern-package)))
138+
(setf tests (alexandria:ensure-list
139+
(%in-package tests reintern-package)))
140+
(setf tags (alexandria:ensure-list
141+
(%in-package tags reintern-package)))
142+
(setf exclude-tests (alexandria:ensure-list
143+
(%in-package exclude-tests reintern-package)))
144+
(setf exclude-tags (alexandria:ensure-list
145+
(%in-package exclude-tags reintern-package))))
138146
;; defaults to pulling up all tests in the current package
139147
(when (and (null tests) (null tags) (null package))
140148
(setf package (package-name *package*)))
141-
(remove-duplicates
142-
(append
143-
(iter (for p in (alexandria:ensure-list package))
144-
(appending (head (gethash (find-package p) (package-index db)))))
145-
(iter (for tag in (alexandria:ensure-list tags))
146-
(appending (head (gethash tag (tag-index db)))))
147-
(iter (for name in (alexandria:ensure-list tests))
148-
(for test = (%to-test name))
149-
(when test
150-
(collect test))))
151-
:key #'name)))
149+
(collectors:with-collector-output (out)
150+
(collectors:with-appender (gathered)
151+
(iter (for p in (alexandria:ensure-list package))
152+
(gathered (head (gethash (find-package p) (package-index db)))))
153+
(iter (for tag in (alexandria:ensure-list tags))
154+
(gathered (head (gethash tag (tag-index db)))))
155+
(iter (for name in (alexandria:ensure-list tests))
156+
(for test = (%to-test name))
157+
(gathered test))
158+
(flet ((excluded? (test)
159+
(or (and (find (name test) exclude-tests)
160+
(not (find (name test) tests)))
161+
(iter (for tag in (tags test))
162+
(thereis (and (find tag exclude-tags)
163+
(not (find tag tags))))))))
164+
(iter (for test in (gathered))
165+
(unless (or (null test)
166+
(excluded? test)
167+
(find test (out)))
168+
(out test))))
169+
))))
152170

153171

154172

@@ -468,7 +486,7 @@
468486

469487

470488
(defgeneric run-tests (&key
471-
tests tags package name
489+
tests tags package name exclude-tests exclude-tags
472490
test-contexts
473491
run-contexts
474492
reintern-package)
@@ -492,24 +510,38 @@
492510
493511
run-contexts is a list of contexts that will be applied around the entire
494512
suite (around signals)
513+
514+
exclude-tests, exclude-tags: tests / tags to remove from the
515+
run. explicit inclusion overrides, explicit exclusion, overrides
516+
implicit inclusion
517+
EG: (define-test test-takes-forever (manual stuff) ...)
518+
(find-test :tags 'stuff :exclude-tags 'manual)
519+
will not find test-takes-forever
520+
(find-test :tags '(stuff manual) :exclude-tags 'manual)
521+
(find-test :tests 'test-takes-forever :exclude-tags 'manual)
522+
both will find test-takes-forever
495523
")
496-
(:method :around (&key tests tags package name
524+
(:method :around (&key tests tags package name exclude-tests exclude-tags
497525
test-contexts run-contexts
498526
reintern-package)
499527
(declare (ignorable tests tags package test-contexts run-contexts
528+
exclude-tests exclude-tags
500529
reintern-package name))
501530
(%log-around (#?"Running tests${name}:${tests} tags:${tags} package:${package} context:${test-contexts},${run-contexts}")
502531
(call-next-method)))
503532
(:method (&rest args
504533
&key
505-
tests tags package reintern-package name
534+
tests tags package reintern-package name exclude-tests exclude-tags
506535
test-contexts
507536
run-contexts
508537
&aux
509-
(all-tests (get-tests :tests tests
510-
:tags tags
511-
:package package
512-
:reintern-package reintern-package))
538+
(all-tests
539+
(get-tests :tests tests
540+
:tags tags
541+
:package package
542+
:reintern-package reintern-package
543+
:exclude-tests exclude-tests
544+
:exclude-tags exclude-tags))
513545
(results (make-instance 'test-results-db :tests all-tests :name name :args args))
514546
(*results* results))
515547
(%log #?"Running tests:${all-tests}" :level 0)

0 commit comments

Comments
 (0)