Mercurial > hg > xemacs-beta
diff tests/automated/test-harness.el @ 4855:189fb67ca31a
Create Assert-eq, Assert-equal, etc.
These are equivalent to (Assert (eq ...)) but display both the actual value
and the expected value of the comparison.
Use them throughout the test suite.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Thu, 14 Jan 2010 02:18:03 -0600 |
parents | a3c673c0720b |
children | 9bf09492cff7 |
line wrap: on
line diff
--- a/tests/automated/test-harness.el Thu Jan 14 01:25:16 2010 -0600 +++ b/tests/automated/test-harness.el Thu Jan 14 02:18:03 2010 -0600 @@ -291,6 +291,88 @@ (incf other-failures) ))) + (defmacro Assert-test (test testval expected &optional failing-case + description) + "Test passes if TESTVAL is equal to EXPECTED, using TEST as comparator. +TEST should be a function such as `eq', `equal', `equalp', `=', `<=', etc. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + (let* ((assertion `(,test ,testval ,expected)) + (failmsg `(format "expected %S, got %S" ,expected ,testval)) + (failmsg2 (if failing-case `(concat + (format "%S, " ,failing-case) + ,failmsg) + failmsg))) + `(Assert ,assertion ,failmsg2 ,description))) + + (defmacro Assert-eq (testval expected &optional failing-case description) + "Test passes if TESTVAL is 'eq' to EXPECTED. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + `(Assert-test eq ,testval ,expected ,failing-case ,description)) + + (defmacro Assert-eql (testval expected &optional failing-case description) + "Test passes if TESTVAL is 'eql' to EXPECTED. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + `(Assert-test eql ,testval ,expected ,failing-case ,description)) + + (defmacro Assert-equal (testval expected &optional failing-case + description) + "Test passes if TESTVAL is 'equal' to EXPECTED. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + `(Assert-test equal ,testval ,expected ,failing-case ,description)) + + (defmacro Assert-equalp (testval expected &optional failing-case + description) + "Test passes if TESTVAL is 'equalp' to EXPECTED. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + `(Assert-test equalp ,testval ,expected ,failing-case ,description)) + + (defmacro Assert-string= (testval expected &optional failing-case + description) + "Test passes if TESTVAL is 'string=' to EXPECTED. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + `(Assert-test string= ,testval ,expected ,failing-case ,description)) + + (defmacro Assert= (testval expected &optional failing-case description) + "Test passes if TESTVAL is '=' to EXPECTED. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + `(Assert-test = ,testval ,expected ,failing-case ,description)) + + (defmacro Assert<= (testval expected &optional failing-case description) + "Test passes if TESTVAL is '<=' to EXPECTED. +Optional FAILING-CASE describes the particular failure; any value given +here will be concatenated with a phrase describing the expected and actual +values of the comparison. Optional DESCRIPTION describes the assertion; by +default, the unevalated comparison expressions are given. FAILING-CASE and +DESCRIPTION are useful when Assert is used in a loop." + `(Assert-test <= ,testval ,expected ,failing-case ,description)) (defmacro Check-Error (expected-error &rest body) (let ((quoted-body (if (= 1 (length body))