Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using eval inside def-test #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions src/test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,35 @@ If PROFILE is T profiling information will be collected as well."
(destructuring-bind (name &rest args)
(ensure-list fixture)
`((with-fixture ,name ,args ,@body-forms)))
body-forms)))
body-forms))
(lambda-name (format-symbol t "%~A-~A" '#:test name))
(inner-lambda-name (format-symbol t "%~A-~A" '#:inner-test name)))
`(progn
(register-test ',name ,description ',effective-body ,suite-form ',depends-on ,compile-at ,profile)
(register-test ',name ,description
(named-lambda ,lambda-name ()
,@(ecase compile-at
(:run-time `((funcall
(let ((*package* (find-package ',(package-name *package*))))
(compile ',inner-lambda-name
'(lambda () ,@effective-body))))))
(:definition-time effective-body)))
,suite-form ',depends-on ,compile-at ,profile)
(when *run-test-when-defined*
(run! ',name))
',name))))

(defun register-test (name description body suite depends-on compile-at profile)
(let ((lambda-name
(format-symbol t "%~A-~A" '#:test name))
(inner-lambda-name
(format-symbol t "%~A-~A" '#:inner-test name)))
(setf (get-test name)
(make-instance 'test-case
:name name
:runtime-package (find-package (package-name *package*))
:test-lambda
(eval
`(named-lambda ,lambda-name ()
,@(ecase compile-at
(:run-time `((funcall
(let ((*package* (find-package ',(package-name *package*))))
(compile ',inner-lambda-name
'(lambda () ,@body))))))
(:definition-time body))))
:description description
:depends-on depends-on
:collect-profiling-info profile
:test-suite suite))
(setf (gethash name (tests suite)) name)))
(defun register-test (name description test-lambda suite depends-on compile-at profile)
(declare (ignore compile-at))
(setf (get-test name)
(make-instance 'test-case
:name name
:runtime-package (find-package (package-name *package*))
:test-lambda test-lambda
:description description
:depends-on depends-on
:collect-profiling-info profile
:test-suite suite))
(setf (gethash name (tests suite)) name))

(defvar *run-test-when-defined* nil
"When non-NIL tests are run as soon as they are defined.")
Expand Down