{"size": 2592, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/syntax/scribblings/macro-testing.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "pkgs/racket-doc/syntax/scribblings/macro-testing.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "pkgs/racket-doc/syntax/scribblings/macro-testing.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": 3, "avg_line_length": 32.4, "max_line_length": 96, "alphanum_fraction": 0.6755401235}
#lang scribble/manual
@(require scribble/eval
          (for-label racket/base 
                     racket/contract
                     racket/struct-info
                     rackunit
                     syntax/macro-testing))

@(define the-eval (make-base-eval))
@(the-eval '(require rackunit syntax/macro-testing (for-syntax racket/base racket/struct-info)))

@title[#:tag "macro-testing"]{Macro Testing}

@defmodule[syntax/macro-testing]

@defform/subs[(phase1-eval ct-expr maybe-quote maybe-catch?)
              ([maybe-quote (code:line)
                            (code:line #:quote quote-id)]
               [maybe-catch? (code:line)
                             (code:line #:catch? catch?)])]{

Evaluates @racket[ct-expr] at compile time and quotes the result using
@racket[quote-id], which defaults to @racket[quote]. Another suitable
argument for @racket[quote-id] is @racket[quote-syntax].

If @racket[catch?] is @racket[#t], then if the evaluation of
@racket[ct-expr] raises a compile-time exception, it is caught and
converted to a run-time exception.

@examples[#:eval the-eval
(struct point (x y))
(phase1-eval (extract-struct-info (syntax-local-value #'point)))
(phase1-eval (extract-struct-info (syntax-local-value #'point))
             #:quote quote-syntax)
]

@history[#:added "6.3"]{}
}

@defform[(convert-compile-time-error expr)]{

Equivalent to @racket[(#%expression expr)] except if expansion of
@racket[expr] causes a compile-time exception to be raised; in that
case, the compile-time exception is converted to a run-time exception
raised when the expression is evaluated.

Use @racket[convert-compile-time-error] to write tests for
compile-time error checking like syntax errors:

@examples[#:eval the-eval
(check-exn #rx"missing an \"else\" expression"
           (lambda () (convert-compile-time-error (if 1 2))))
(check-exn #rx"missing formals and body"
           (lambda () (convert-compile-time-error (lambda))))
]

Without the use of @racket[convert-compile-time-error], the checks
above would not be executed because the test program would not compile.

@history[#:added "6.3"]{}
}

@defform[(convert-syntax-error expr)]{

Like @racket[convert-compile-time-error], but only catches compile-time
@racket[exn:fail:syntax?] exceptions and sets
@racket[error-print-source-location] to @racket[#f] around the
expansion of @racket[expr] to make the message easier to match
exactly.

@examples[#:eval the-eval
(check-exn #rx"^lambda: bad syntax$"
           (lambda () (convert-syntax-error (lambda))))
]

@history[#:added "6.3"]{}
}

@(close-eval the-eval)
