Skip to content

Commit ca312e4

Browse files
authored
Print better message when exercise package cannot be found. (#510)
What often happens is that the test slug (the directory name) does not match the solution or test package names. When this happens the CI runner prints a message saying it could not find package NIL which is not very useful. Creating a specific error here for missing exercise packages which has a much more useful report.
1 parent 7aa2030 commit ca312e4

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/test-exercises/exercises.lisp

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
(handler-bind ((style-warning #'muffle-warning))
1919
(load file))))
2020

21+
(defun missing-exercise-package-error-report (condition stream)
22+
(format stream
23+
"Could not find package ~S (perhaps exercise slug and code do not match?)"
24+
(package-error-package condition)))
25+
26+
(define-condition missing-exercise-package-error (package-error) ()
27+
(:documentation "Error to signal if exercise package (or exercise test package) cannot be found")
28+
(:report missing-exercise-package-error-report))
29+
2130
(defun find-exercise-package (exercise &key (test nil))
22-
(let ((slug (symbol-name (aget :slug exercise))))
23-
(find-package (string-upcase (format nil "~A~@[-TEST~]" slug test)))))
31+
(let* ((slug (symbol-name (aget :slug exercise)))
32+
(package-name (string-upcase (format nil "~A~@[-TEST~]" slug test)))
33+
(package (find-package package-name)))
34+
(if (not package)
35+
(error 'missing-exercise-package-error :package package-name)
36+
package)))

src/test-exercises/run.lisp

+13-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
(defun %test-exercise (data)
88
(let ((test-files (aget :test (aget :files data)))
99
(exemplar-files (example-files data)))
10-
(unwind-protect
11-
(progn
12-
(dolist (f (append test-files exemplar-files))
13-
(load-exercise-file data f))
14-
(let ((fiveam:*print-names* nil))
15-
(fiveam:run (find-symbol
16-
(format nil "~A-SUITE" (symbol-name (aget :slug data)))
17-
(find-exercise-package data :test t)))))
18-
(delete-package (find-exercise-package data :test t))
19-
(delete-package (find-exercise-package data)))))
10+
(handler-case
11+
(unwind-protect
12+
(progn
13+
(dolist (f (append test-files exemplar-files))
14+
(load-exercise-file data f))
15+
(let ((fiveam:*print-names* nil))
16+
(fiveam:run (find-symbol
17+
(format nil "~A-SUITE" (symbol-name (aget :slug data)))
18+
(find-exercise-package data :test t)))))
19+
(delete-package (find-exercise-package data :test t))
20+
(delete-package (find-exercise-package data)))
21+
(package-error (c)
22+
(error (format nil "PACKAGE-ERROR with package ~S" (package-error-package c)))))))
2023

2124
(defun test-exercise (dir)
2225
(sb-ext:gc :full t)

0 commit comments

Comments
 (0)