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

Fix ASSERTIONS test in FIASCO-BASIC-SELF-TESTS #35

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
110 changes: 62 additions & 48 deletions test/basic.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
(:import-from #:fiasco #:*suite*
#:name-of
#:parent-of
#:children-of
#:delete-test
#:count-tests

Expand Down Expand Up @@ -88,55 +89,68 @@
t)

(deftest assertions (&key (test-name (gensym "TEMP-TEST")))
(unwind-protect
(eval `(deftest ,test-name ()
(is (= 42 42))
(is (= 1 42)) ; fails
(is (not (= 42 42))) ; fails
(is (true-macro))
(is (true-macro) "Oh yes, glad that it's ~a" "true")
(is (not (false-macro)))

(signals serious-condition (error "foo"))
(signals serious-condition 'not) ; fails

(not-signals warning (warn "foo")) ; fails
(not-signals warning 'not)
(let* ((this-suite (find-test 'fiasco-suites::fiasco-basic-self-tests))
(old-children (children-of this-suite)))
(unwind-protect
(progn
;; The DEFTEST form will modify the (CHILDREN-OF THIS-SUITE), but we
;; might currently be iterating over that HASH-TABLE, e.g. if this
;; test was invoked via FIASCO:ALL-TESTS or similar. According to the
;; spec, the consequences are undefined if you add a new element to a
;; HASH-TABLE while traversing it, so make a copy here and restore
;; the old value below.
(setf (children-of this-suite) (alexandria:copy-hash-table old-children))
(eval `(deftest ,test-name ()
(is (= 42 42))
(is (= 1 42)) ; fails
(is (not (= 42 42))) ; fails
(is (true-macro))
(is (true-macro) "Oh yes, glad that it's ~a" "true")
(is (not (false-macro)))

(signals serious-condition (error "foo"))
(signals serious-condition 'not) ; fails

(not-signals warning (warn "foo")) ; fails
(not-signals warning 'not)

(with-expected-failures
(ignore-errors
(finishes (error "expected failure")))) ; fails
(finishes 42)
(ignore-errors ; fails
(finishes (error "foo")))))
(progn
;; this uglyness here is due to testing the test framework which is inherently
;; not nestable, so we need to backup and restore some state
(let* ((context *context*)
(old-assertion-count (length (assertions-of context)))
(old-failure-description-count (length (failures-of context))))
(unwind-protect
(progn
(let ((*debug-on-unexpected-error* nil)
(*debug-on-assertion-failure* nil)
(*print-test-run-progress* nil))
(funcall test-name))))
(is (= (length (assertions-of context))
(+ old-assertion-count 14))) ; also includes the current assertion
(is (= (length (failures-of context))
(+ old-failure-description-count 6)))
(is (= 1 (count-if 'expected-p (failures-of context))))
(is (= 1 (length (children-contexts-of context))))
;; drop the subtest by the test-test
;;
(setf (parent-context-of (first (children-contexts-of context))) nil)
(is (= 0 (length (children-contexts-of context)))))
;; Take this occasion to test some deleting, too
;;
(delete-test test-name :otherwise nil)
(signals error (delete-test test-name :otherwise :error))
(is (not (find-test test-name :otherwise nil)))
))
(with-expected-failures
(ignore-errors
(finishes (error "expected failure")))) ; fails
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why my emacs has changed to a 1-space indent on these ignore-errors forms... indent-tabs-mode doesn't seem to change it

(finishes 42)
(ignore-errors ; fails
(finishes (error "foo"))))))
(progn
;; this uglyness here is due to testing the test framework which is inherently
;; not nestable, so we need to backup and restore some state
(let* ((context *context*)
(old-assertion-count (length (assertions-of context)))
(old-failure-description-count (length (failures-of context))))
(unwind-protect
(progn
(let ((*debug-on-unexpected-error* nil)
(*debug-on-assertion-failure* nil)
(*print-test-run-progress* nil))
(funcall test-name))))
(is (= (length (assertions-of context))
(+ old-assertion-count 14))) ; also includes the current assertion
(is (= (length (failures-of context))
(+ old-failure-description-count 6)))
(is (= 1 (count-if 'expected-p (failures-of context))))
(is (= 1 (length (children-contexts-of context))))
;; drop the subtest by the test-test
;;
(setf (parent-context-of (first (children-contexts-of context))) nil)
(is (= 0 (length (children-contexts-of context)))))
;; Take this occasion to test some deleting, too
;;
(delete-test test-name :otherwise nil)
(signals error (delete-test test-name :otherwise :error))
(is (not (find-test test-name :otherwise nil)))
;; Restore children
;;
(setf (children-of this-suite) old-children)
)))
(values))

(deftest slightly-verbose-test ()
Expand Down