Skip to content

Commit dc985b3

Browse files
shhyoumfelleisen
authored andcommitted
Do not capture syntax errors in check-error
1 parent aa2ad71 commit dc985b3

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

htdp-lib/test-engine/racket-tests.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@
253253
(execute-test
254254
src
255255
(lambda ()
256-
(with-handlers ([exn:fail?
256+
(with-handlers ([(lambda (exn)
257+
(and (exn:fail? exn)
258+
(not (exn:fail:syntax? exn))))
257259
(lambda (exn)
258260
(let ((msg (get-rewritten-error-message exn)))
259261
(if (equal? msg error)

htdp-test/tests/test-engine/racket-tests.rkt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
(require (only-in lang/private/teach check-property
44
for-all Integer)
5+
(only-in lang/htdp-beginner
6+
[#%app #%app/bsl]
7+
empty)
58
(only-in lang/htdp-intermediate-lambda
69
[define define/isl]
10+
[#%app #%app/isl]
711
local)
812
(only-in htdp/bsl/runtime configure)
913
(except-in rackunit check-within)
@@ -254,6 +258,56 @@
254258
incorrect-error-expected "another message"
255259
incorrect-error-exn exn:fail:contract?)
256260

261+
(check-error (empty) "function call: expected a function after the open parenthesis, but received '()")
262+
(check-success)
263+
264+
;; rational: x is unbound so this check-error shall not pass
265+
;; (but it also should not raise the syntax error immediately at expansion)
266+
(check-error x "x: this variable is not defined")
267+
(check-failure unexpected-error?
268+
unexpected-error-exn exn:fail:syntax?
269+
unexpected-error-expected "x: this variable is not defined"
270+
unexpected-error/markup-error-markup
271+
(lambda (m)
272+
(regexp-match?
273+
;; From the command line, tests/test-engine/racket-tests[.]rkt is
274+
;; in the error message
275+
;;
276+
;; Ideally, we want to see the message "x: this variable is not defined" in
277+
;; the exception. Unfortunately, the #%top binding is not from *sl.
278+
#rx"x: unbound identifier.*tests/test-engine/racket-tests[.]rkt"
279+
(with-output-to-string
280+
(lambda () (display-markup m))))))
281+
282+
(check-error (#%app/isl 123) "function call: expected a function after the open parenthesis, but received 123")
283+
(check-success)
284+
285+
(check-error (#%app/bsl 123) "function call: expected a function after the open parenthesis, but found a number")
286+
(check-failure unexpected-error?
287+
unexpected-error-exn exn:fail:syntax?
288+
unexpected-error-expected "function call: expected a function after the open parenthesis, but found a number"
289+
unexpected-error/markup-error-markup
290+
(lambda (m)
291+
(regexp-match?
292+
;; From the command line, tests/test-engine/racket-tests[.]rkt is
293+
;; in the error message
294+
#rx"function call: expected a function after the open parenthesis, but found a number.*tests/test-engine/racket-tests[.]rkt"
295+
(with-output-to-string
296+
(lambda () (display-markup m))))))
297+
298+
(check-error define/isl "define: expected an open parenthesis before define, but found none")
299+
(check-failure unexpected-error?
300+
unexpected-error-exn exn:fail:syntax?
301+
unexpected-error-expected "define: expected an open parenthesis before define, but found none"
302+
unexpected-error/markup-error-markup
303+
(lambda (m)
304+
(regexp-match?
305+
;; From the command line, tests/test-engine/racket-tests[.]rkt is
306+
;; in the error message
307+
#rx"define: expected an open parenthesis before define, but found none.*tests/test-engine/racket-tests[.]rkt"
308+
(with-output-to-string
309+
(lambda () (display-markup m))))))
310+
257311
(define (create n)
258312
(make-ball n n 'blue))
259313

0 commit comments

Comments
 (0)