Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RackUnit check-exn fails to catch raised syntax error when error not called directly #2996

Closed
tommymchugh opened this issue Jan 2, 2020 · 11 comments · May be fixed by racket/rackunit#131
Closed

Comments

@tommymchugh
Copy link
Contributor

Example:

#lang racket
(require rackunit)

(check-exn
   exn:fail:syntax?
   (lambda ()
     (raise-syntax-error #f "Failed" #f #f null "")))

(check-exn
   exn:fail:syntax?
   (lambda ()
     (struct apple (seeds) #:constructor-name pear)
     (apple 53)))

First check passes, but second check never seems to catch that raise-syntax-error (and thus produces an exn:fail:syntax) is called when the identifier is called for a struct that has a different constructor name.

@rfindler
Copy link
Member

rfindler commented Jan 2, 2020

I believe that's because the exception is being raise at compile time (phase 1) and that's not when check-exn is catching errors.

@sorawee
Copy link
Collaborator

sorawee commented Jan 2, 2020

I think you will find https://docs.racket-lang.org/syntax/macro-testing.html#%28form._%28%28lib._syntax%2Fmacro-testing..rkt%29._convert-compile-time-error%29%29 useful.

Edit: what about this?

#lang racket

(require rackunit
         syntax/macro-testing)

(check-exn
 #rx"identifier for static struct-type"
 (lambda ()
   (convert-syntax-error
    (let ()
      (struct apple (seeds) #:constructor-name pear)
      (apple 53)))))

@tommymchugh
Copy link
Contributor Author

Yes that is very helpful thanks a bunch works perfectly! Not that that is a hassle at at all, but for curiosities sake, is there a reason why check-exn does't wrap the convert-compile-time-error procedure around the check-exn thunk procedure? It seems that would be useful especially for syntax errors unit testing which may often produce the error testing for not at runtime.

@rfindler
Copy link
Member

rfindler commented Jan 2, 2020 via email

@tommymchugh
Copy link
Contributor Author

Gotcha, make sense. Thanks for the assistance on this!

@jackfirth
Copy link
Sponsor Contributor

A separate check-compile-time-exn form would be very handy though.

@tommymchugh
Copy link
Contributor Author

@jackfirth I'll build it out and report back. Will reopen for now to see if there is interest in this.

@tommymchugh tommymchugh reopened this Jan 3, 2020
@jackfirth
Copy link
Sponsor Contributor

jackfirth commented Jan 3, 2020

@tommymchugh Sounds great 🙂 Heads up: the implementation of rackunit is in the repository racket/rackunit, not racket/racket.

@tommymchugh
Copy link
Contributor Author

racket/rackunit#114 is the PR with the implementation. Comments, contributions, etc. are welcome!

@sorawee
Copy link
Collaborator

sorawee commented Apr 22, 2020

Since everything works as expected, can we close this issue, @tommymchugh?

@tommymchugh
Copy link
Contributor Author

Yup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants