Skip to content

Commit

Permalink
Test several check-satisfied error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
shhyou committed Dec 28, 2024
1 parent ea06d4c commit e6b7936
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions htdp-test/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(define build-deps '("lazy"
"deinprogramm"
"pict-lib"
"simple-tree-text-markup-lib"
"redex-lib"
"racket-index"
"scheme-lib"
Expand Down
56 changes: 56 additions & 0 deletions htdp-test/tests/test-engine/racket-tests.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

(require (only-in lang/private/teach check-property
for-all Integer)
(only-in lang/htdp-intermediate-lambda
[define define/isl]
local)
(only-in htdp/bsl/runtime configure)
(except-in rackunit check-within)
racket/port
simple-tree-text-markup/text
test-engine/racket-tests
test-engine/test-engine)

(require racket/format)

;; To configure error messages
(configure ;; ISL options
'(abbreviate-cons-as-list
read-accept-quasiquote
use-function-output-syntax))

(define (assert-failed-check failed-check reason? . selector+value-list)
(check-pred failed-check? failed-check)
(let ((reason (failed-check-reason failed-check)))
Expand Down Expand Up @@ -60,6 +72,50 @@
unequal-actual 1
unequal-expected 2)

(check-satisfied (cdr (list 3514)) null)
(check-failure unsatisfied-error?
unsatisfied-error-exn (lambda (e)
(regexp-match? #rx"application: not a procedure"
(exn-message e)))
unsatisfied-error/markup-error-markup
(lambda (m)
(regexp-match? #rx"function call: expected a function after the open parenthesis, but received '[(][)]"
(with-output-to-string
(lambda () (display-markup m))))))

(define/isl even1
(local [(define/isl (local-even m k)
(even? (+ m k)))]
local-even))

(define/isl (even2 m k)
(even? (+ m k)))

(check-satisfied 4 even1)
(check-failure unsatisfied-error?
unsatisfied-error-exn (lambda (e)
(regexp-match? #rx"local-even.*arity mismatch"
(exn-message e)))
unsatisfied-error/markup-error-markup
(lambda (m)
(regexp-match? #rx"local-even.*expects 2 arguments.*found only 1"
(with-output-to-string
(lambda () (display-markup m))))))

(check-satisfied 4 even2)
(check-failure unsatisfied-error?
unsatisfied-error-exn
(lambda (e)
(regexp-match?
#rx"check-satisfied.*expects function of one argument.*Given even2"
(exn-message e)))
unsatisfied-error/markup-error-markup
(lambda (m)
(regexp-match?
#rx"check-satisfied.*expects function of one argument.*Given even2"
(with-output-to-string
(lambda () (display-markup m))))))

(check-satisfied 0 (lambda (n bad) #t))
(check-exn
(lambda (e)
Expand Down

0 comments on commit e6b7936

Please sign in to comment.