Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Request errortrace to annotate check-* thunks

* Fix the format string of check-within errors.

  When reporting "not given an inexact number" in check-within, the given
  value has to be formatted with ~s since it could have been a string:

      (check-within (sqrt 2) 3/2 "0.1")

* Fix check-random error message so check-randoms don't report
  themselves as check-expect anymore.

* Revise check-expect error messages
   + Refer to "the second argument" in the messages
   + Remove the fix suggestion per the comment <#228 (comment)>

See tests/drracket/module-lang-tests for the tests (racket/drracket#689).
  • Loading branch information
shhyou authored Nov 9, 2024
1 parent e1fa945 commit 3eab980
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
21 changes: 12 additions & 9 deletions htdp-lib/test-engine/racket-tests.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@
simple-tree-text-markup/construct
simple-tree-text-markup/port)

(define INEXACT-NUMBERS-FMT
"check-expect cannot compare inexact numbers. Try (check-within test ~a range).")
(define CHECK-EXPECT-INEXACT-NUMBERS-FMT
"check-expect: cannot compare inexact numbers, but the second argument is ~a.")
(define FUNCTION-FMT
"check-expect cannot compare functions.")
"check-expect: cannot compare functions, but the second argument ~a is a function.")
;; No fix were available; don't suggest anything.
(define CHECK-RANDOM-INEXACT-NUMBERS-FMT
"check-random: cannot compare inexact numbers, but the second argument is ~a.")
(define SATISFIED-FMT
"check-satisfied: expects function of one argument in second position. Given ~a")
(define CHECK-ERROR-STR-FMT
"check-error: expects a string (the expected error message) for the second argument. Given ~s")
(define CHECK-WITHIN-INEXACT-FMT
"check-within: expects an inexact number for the range. ~a is not inexact.")
"check-within: expects an inexact number for the range. ~s is not inexact.")
(define CHECK-WITHIN-FUNCTION-FMT
"check-within cannot compare functions.")
"check-within cannot compare functions, but the second argument is ~a.")
(define LIST-FMT
"check-member-of: expects a list for the second argument (the possible outcomes). Given ~s")
(define CHECK-MEMBER-OF-FUNCTION-FMT
Expand Down Expand Up @@ -109,9 +112,9 @@

(define (do-check-expect test expected src)
(error-check (lambda (v) (if (number? v) (exact? v) #t))
expected INEXACT-NUMBERS-FMT #t)
expected CHECK-EXPECT-INEXACT-NUMBERS-FMT #t)
(error-check (lambda (v) (not (procedure? v)))
expected FUNCTION-FMT #f)
expected FUNCTION-FMT #t)
(execute-test
src
(lambda ()
Expand All @@ -136,7 +139,7 @@
(random-seed k)
(expected-thunk))))
(error-check (lambda (v) (if (number? v) (exact? v) #t))
expected INEXACT-NUMBERS-FMT #t)
expected CHECK-RANDOM-INEXACT-NUMBERS-FMT #t)
(execute-test
src
(lambda ()
Expand Down Expand Up @@ -217,7 +220,7 @@

(define (do-check-within test expected within src)
(error-check number? within CHECK-WITHIN-INEXACT-FMT #t)
(error-check (lambda (v) (not (procedure? v))) expected CHECK-WITHIN-FUNCTION-FMT #f)
(error-check (lambda (v) (not (procedure? v))) expected CHECK-WITHIN-FUNCTION-FMT #t)
(execute-test
src
(lambda ()
Expand Down
13 changes: 8 additions & 5 deletions htdp-lib/test-engine/syntax.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@
(['stepper-hint hint-tag]
['stepper-hide-reduction #t]
['stepper-use-val-as-final #t])
(quasisyntax/loc stx
(#,checker-proc-stx
(lambda () #,test-expr-checked-for-syntax-error)
#,@embedded-stxes
#,src-info)))))
(syntax-property
(quasisyntax/loc stx
(#,checker-proc-stx
(lambda () #,test-expr-checked-for-syntax-error)
#,@embedded-stxes
#,src-info))
'errortrace:annotate
#t))))
'stepper-skipto
(append skipto/cdr
skipto/second ;; outer lambda
Expand Down
2 changes: 1 addition & 1 deletion htdp-test/tests/stepper/test-cases.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@
(t 'check-expect-err m:upto-int/lam
(check-expect 0 (sqrt 2))
:: (check-expect 0 {(sqrt 2)}) -> (check-expect 0 {1.4142135623730951})
:: error: "check-expect cannot compare inexact numbers")
:: error: "check-expect: cannot compare inexact numbers")

(t1 'check-within
m:upto-int/lam
Expand Down

1 comment on commit 3eab980

@shhyou
Copy link
Collaborator Author

@shhyou shhyou commented on 3eab980 Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title should have been: fix the stack trace of check-expect forms

Please sign in to comment.