comparison 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
comparison
equal deleted inserted replaced
4854:95c4ced5c07c 4855:189fb67ca31a
289 ,(or description `(quote ,assertion)) 289 ,(or description `(quote ,assertion))
290 error-info ,failing-case) 290 error-info ,failing-case)
291 (incf other-failures) 291 (incf other-failures)
292 ))) 292 )))
293 293
294 (defmacro Assert-test (test testval expected &optional failing-case
295 description)
296 "Test passes if TESTVAL is equal to EXPECTED, using TEST as comparator.
297 TEST should be a function such as `eq', `equal', `equalp', `=', `<=', etc.
298 Optional FAILING-CASE describes the particular failure; any value given
299 here will be concatenated with a phrase describing the expected and actual
300 values of the comparison. Optional DESCRIPTION describes the assertion; by
301 default, the unevalated comparison expressions are given. FAILING-CASE and
302 DESCRIPTION are useful when Assert is used in a loop."
303 (let* ((assertion `(,test ,testval ,expected))
304 (failmsg `(format "expected %S, got %S" ,expected ,testval))
305 (failmsg2 (if failing-case `(concat
306 (format "%S, " ,failing-case)
307 ,failmsg)
308 failmsg)))
309 `(Assert ,assertion ,failmsg2 ,description)))
310
311 (defmacro Assert-eq (testval expected &optional failing-case description)
312 "Test passes if TESTVAL is 'eq' to EXPECTED.
313 Optional FAILING-CASE describes the particular failure; any value given
314 here will be concatenated with a phrase describing the expected and actual
315 values of the comparison. Optional DESCRIPTION describes the assertion; by
316 default, the unevalated comparison expressions are given. FAILING-CASE and
317 DESCRIPTION are useful when Assert is used in a loop."
318 `(Assert-test eq ,testval ,expected ,failing-case ,description))
319
320 (defmacro Assert-eql (testval expected &optional failing-case description)
321 "Test passes if TESTVAL is 'eql' to EXPECTED.
322 Optional FAILING-CASE describes the particular failure; any value given
323 here will be concatenated with a phrase describing the expected and actual
324 values of the comparison. Optional DESCRIPTION describes the assertion; by
325 default, the unevalated comparison expressions are given. FAILING-CASE and
326 DESCRIPTION are useful when Assert is used in a loop."
327 `(Assert-test eql ,testval ,expected ,failing-case ,description))
328
329 (defmacro Assert-equal (testval expected &optional failing-case
330 description)
331 "Test passes if TESTVAL is 'equal' to EXPECTED.
332 Optional FAILING-CASE describes the particular failure; any value given
333 here will be concatenated with a phrase describing the expected and actual
334 values of the comparison. Optional DESCRIPTION describes the assertion; by
335 default, the unevalated comparison expressions are given. FAILING-CASE and
336 DESCRIPTION are useful when Assert is used in a loop."
337 `(Assert-test equal ,testval ,expected ,failing-case ,description))
338
339 (defmacro Assert-equalp (testval expected &optional failing-case
340 description)
341 "Test passes if TESTVAL is 'equalp' to EXPECTED.
342 Optional FAILING-CASE describes the particular failure; any value given
343 here will be concatenated with a phrase describing the expected and actual
344 values of the comparison. Optional DESCRIPTION describes the assertion; by
345 default, the unevalated comparison expressions are given. FAILING-CASE and
346 DESCRIPTION are useful when Assert is used in a loop."
347 `(Assert-test equalp ,testval ,expected ,failing-case ,description))
348
349 (defmacro Assert-string= (testval expected &optional failing-case
350 description)
351 "Test passes if TESTVAL is 'string=' to EXPECTED.
352 Optional FAILING-CASE describes the particular failure; any value given
353 here will be concatenated with a phrase describing the expected and actual
354 values of the comparison. Optional DESCRIPTION describes the assertion; by
355 default, the unevalated comparison expressions are given. FAILING-CASE and
356 DESCRIPTION are useful when Assert is used in a loop."
357 `(Assert-test string= ,testval ,expected ,failing-case ,description))
358
359 (defmacro Assert= (testval expected &optional failing-case description)
360 "Test passes if TESTVAL is '=' to EXPECTED.
361 Optional FAILING-CASE describes the particular failure; any value given
362 here will be concatenated with a phrase describing the expected and actual
363 values of the comparison. Optional DESCRIPTION describes the assertion; by
364 default, the unevalated comparison expressions are given. FAILING-CASE and
365 DESCRIPTION are useful when Assert is used in a loop."
366 `(Assert-test = ,testval ,expected ,failing-case ,description))
367
368 (defmacro Assert<= (testval expected &optional failing-case description)
369 "Test passes if TESTVAL is '<=' to EXPECTED.
370 Optional FAILING-CASE describes the particular failure; any value given
371 here will be concatenated with a phrase describing the expected and actual
372 values of the comparison. Optional DESCRIPTION describes the assertion; by
373 default, the unevalated comparison expressions are given. FAILING-CASE and
374 DESCRIPTION are useful when Assert is used in a loop."
375 `(Assert-test <= ,testval ,expected ,failing-case ,description))
294 376
295 (defmacro Check-Error (expected-error &rest body) 377 (defmacro Check-Error (expected-error &rest body)
296 (let ((quoted-body (if (= 1 (length body)) 378 (let ((quoted-body (if (= 1 (length body))
297 `(quote ,(car body)) `(quote (progn ,@body))))) 379 `(quote ,(car body)) `(quote (progn ,@body)))))
298 `(condition-case error-info 380 `(condition-case error-info