-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtesting.rkt
51 lines (43 loc) · 1.52 KB
/
testing.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#lang racket/base
(require "main.rkt"
syntax/macro-testing
rackunit
racket/exn
(for-syntax racket/base syntax/parse racket/syntax))
(provide expand-nonterminal/datum
check-decl-error
check-phase1-error
check-syntax-error
(all-from-out "main.rkt"
rackunit
syntax/macro-testing)
(for-syntax (all-from-out racket/base syntax/parse)))
(define-syntax expand-nonterminal/datum
(syntax-parser
[(_ nonterm:id form)
(define/syntax-parse ctx this-syntax)
#'(phase1-eval
(parameterize ([current-syntax-context (quote-syntax ctx)])
((nonterminal-expander nonterm) (quote-syntax form)))
#:catch? #t)]))
(define ((check-formatted-error-matches rx) exn)
;; I previously used exn->string, but that raised an error
;; re: writing special values when handling an ambiguous binding
;; error.
(regexp-match? rx (exn-message exn)))
(define-syntax-rule (check-decl-error rx decl-stx)
(check-exn
(check-formatted-error-matches rx)
(lambda ()
(eval-syntax (quote-syntax
(module m racket/base
(require "../main.rkt")
decl-stx))))))
(define-syntax-rule (check-phase1-error rx e)
(check-exn
(check-formatted-error-matches rx)
(lambda () (phase1-eval e #:catch? #t))))
(define-syntax-rule (check-syntax-error rx e)
(check-exn
(check-formatted-error-matches rx)
(lambda () (convert-compile-time-error e))))