1
0
mirror of synced 2026-05-03 06:39:40 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/24-2-ASSERT.TEST

112 lines
3.4 KiB
Plaintext

;; Function To Be Tested: assert
;;
;; Source: Guy L Steele's CLTL
;; Section: 24.2 ERRORS (Specialized Error-Signalling Forms and Macros)
;; Page: 434
;;
;; Created By: John Park
;;
;; Creation Date: Nov 6, 1986
;;
;; Last Update: Jan 15, 1987
;;
;; Filed As: {ERIS}<LISPCORE>CML>TEST>24-2-assert.test
;;
;;
;; Syntax: (assert test-from [({place}*) [string {arg}*]])
;;
;; Function Description: Assert signals an error if the value of test-form is nil ;; Continuing from this error will allow the user to alter the values of some
;; variables, and assert will then start over, evaluating test-form again.
;;
;; Argument(s): Test-form: any form
;; Place: each place (none or more than one) must be a generalized
;; variable reference acceptable to setf. These should be
;; variables on which test-from depends, whose values may
;; sensibly be changed by the user in attempting to correct the
;; error.
;; String: Error message string
;; Arg: additional arguments; they are evaluated only if an error
;; is signalled, and may be re-evluated if the error is re-signalled.
;;
;; Returns: NIL
;;
;; Constraints/Limitations: Due to the nature of assert function, which enters the
;; debugger (break), this test should be conducted manually to see if correct error
;; messages are returned. Tests requiring user interface are commented out.
(do-test "assert-test-0"
(macro-function 'assert) ; Does assert have a macro definition?
)
(do-test "assert-test1"
(and (setq status '(switch-1 switch-2 switch-3))
(defun valve-closed-p (x)
(if (member x status) T))
(eq (assert (valve-closed-p 'switch-3)) NIL) ; Should not break
)
)
;; The following should break and print the error message as indicated.
;; (assert (valve-closed-p 'switch-9) () "Live stream is escaping!"))
;; (assert (valve-closed-p 'switch-4) (status) "Live stream is escaping!"))
(do-test "assert-test2"
(and (setq minbase 10 base 20 maxbase 30)
(eq (assert (<= minbase base maxbase)
(base)
"Base ~D is not in the range [~D, ~D]"
base minbase maxbase)
NIL)
)
)
;; The following should break and print the error message as indicated.
;; Note here that the user is invited to change BASE, but not the bounds
;; MINBASE and MAXBASE.
;;
;; (setq base 40)
;; (assert (<= minbase base maxbase)
;; (base)
;; "Base ~D is not in the range [~D, ~D]"
;; base minbase maxbase)
(do-test "assert-test3"
(and (setq a (make-array '(2 3)))
(setq b (make-array '(3 2)))
(eq (assert (= (array-dimension a 1)
(array-dimension b 0))
(a b)
"cannot multiply a ~D-by-~D matrix ~
and a ~D-by-~D matrix."
(array-dimension a 0)
(array-dimension a 1)
(array-dimension b 0)
(array-dimension b 1))
NIL)
)
)
;; The following should break and print the error message as indicated. It should
;; exit the debeugger and return NIL after an appropriate change is made.
;; Note here that it is probably not desirable to include the entire contents
;; of the two matrices in the error message. It is reasonable to assume that the
;; debugger will give the user access to the values of the places a and b.
;;
;;(setq b (make-array '(2 2)))
;;(assert (= (array-dimension a 1)
;; (array-dimension b 0))
;; (a b)
;; "cannot multiply a ~D-by-~D matrix ~
;; and a ~D-by-~D matrix."
;; (array-dimension a 0)
;; (array-dimension a 1)
;; (array-dimension b 0)
;; (array-dimension b 1))
STOP