-
-
Notifications
You must be signed in to change notification settings - Fork 35
Compile time check implementation #131
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
Open
tommymchugh
wants to merge
4
commits into
racket:master
Choose a base branch
from
tommymchugh:check-compile-time-exn
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
42c42c7
moved reg exp match outside of check-exn and implemented check-compil…
tommymchugh 99416ff
created basic tests for check-not-compile-time-exn and check-compile-…
tommymchugh 0bdc059
Created documentation for check-compile-time-exn and check-not-compil…
tommymchugh 730fe22
Fixed check-not-compile-time-exn typos
tommymchugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
racket/match | ||
rackunit/log | ||
syntax/parse/define | ||
syntax/macro-testing | ||
"base.rkt" | ||
"equal-within.rkt" | ||
"check-info.rkt" | ||
|
@@ -29,6 +30,8 @@ | |
check | ||
check-exn | ||
check-not-exn | ||
check-compile-time-exn | ||
check-not-compile-time-exn | ||
check-true | ||
check-false | ||
check-pred | ||
|
@@ -147,14 +150,16 @@ | |
(procedure-arity-includes? thunk 0)) | ||
(raise-arguments-error name "thunk must be a procedure that accepts 0 arguments" "thunk" thunk))) | ||
|
||
(define (get-pred raw-pred) | ||
(cond [(regexp? raw-pred) | ||
(λ (x) (and (exn:fail? x) (regexp-match raw-pred (exn-message x))))] | ||
[(and (procedure? raw-pred) (procedure-arity-includes? raw-pred 1)) | ||
raw-pred] | ||
[else | ||
(raise-argument-error 'check-exn "(or/c (-> any/c any/c) regexp?)" raw-pred)])) | ||
|
||
(define-check (check-exn raw-pred thunk) | ||
(let ([pred | ||
(cond [(regexp? raw-pred) | ||
(λ (x) (and (exn:fail? x) (regexp-match raw-pred (exn-message x))))] | ||
[(and (procedure? raw-pred) (procedure-arity-includes? raw-pred 1)) | ||
raw-pred] | ||
[else | ||
(raise-argument-error 'check-exn "(or/c (-> any/c any/c) regexp?)" raw-pred)])]) | ||
(let ([pred (get-pred raw-pred)]) | ||
(raise-error-if-not-thunk 'check-exn thunk) | ||
(let/ec succeed | ||
(with-handlers | ||
|
@@ -196,6 +201,48 @@ | |
(lambda () (fail-check))))]) | ||
(thunk))) | ||
|
||
(define-syntax (check-compile-time-exn stx) | ||
(syntax-parse stx | ||
[(_ raw-pred expr:expr) | ||
#:with loc (datum->syntax #f 'loc stx) | ||
#'(let ([pred (get-pred raw-pred)] | ||
[location (syntax->location #'loc)]) | ||
(with-check-info (['name 'check-compile-time-exn] | ||
['location location] | ||
['params (list raw-pred (syntax->datum #'expr))]) | ||
(let/ec finish | ||
(with-check-info (['message "Wrong exception raised"]) | ||
(with-handlers | ||
([pred | ||
(lambda (exn) (finish))] | ||
[exn:fail? | ||
(lambda (exn) | ||
(with-check-info (['exn exn]) | ||
(fail) | ||
(finish)))]) | ||
(convert-compile-time-error expr))) | ||
(with-check-info (['message "No exception raised"]) | ||
(fail)))))])) | ||
|
||
(define-syntax (check-not-compile-time-exn stx) | ||
(syntax-parse stx | ||
[(_ expr:expr) | ||
#:with loc (datum->syntax #f 'loc stx) | ||
#'(let ([location (syntax->location #'loc)]) | ||
(with-check-info (['name 'check-compile-time-exn] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! These should be fixed now. |
||
['location location] | ||
['params (list (syntax->datum #'expr))]) | ||
(let/ec finish | ||
(with-check-info (['message "Exception raised"]) | ||
(with-handlers | ||
([exn:fail? | ||
(lambda (exn) | ||
(with-check-info (['exn exn]) | ||
(fail) | ||
(finish)))]) | ||
(convert-compile-time-error expr))) | ||
(finish))))])) | ||
|
||
(define-syntax-rule (define-simple-check-values [header body ...] ...) | ||
(begin (define-simple-check header body ...) ...)) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo. Should be
check-not-compile-time-exn
.