{"size": 1629, "ext": "scrbl", "max_stars_repo_path": "rackunit-doc/rackunit/scribblings/control-flow.scrbl", "max_stars_repo_name": "aymanosman/rackunit", "max_stars_repo_stars_event_min_datetime": "2015-10-23T20:17:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T15:53:52.000Z", "max_issues_repo_path": "rackunit-doc/rackunit/scribblings/control-flow.scrbl", "max_issues_repo_name": "aymanosman/rackunit", "max_issues_repo_issues_event_min_datetime": "2015-01-09T22:52:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T20:34:12.000Z", "max_forks_repo_path": "rackunit-doc/rackunit/scribblings/control-flow.scrbl", "max_forks_repo_name": "aymanosman/rackunit", "max_forks_repo_forks_event_min_datetime": "2015-01-09T19:10:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:55:18.000Z"}
{"max_stars_count": 10, "max_issues_count": 125, "max_forks_count": 34, "avg_line_length": 30.7358490566, "max_line_length": 84, "alphanum_fraction": 0.7188459177}
#lang scribble/doc
@(require "base.rkt")

@title{Test Control Flow}

The @racket[before], @racket[after], and @racket[around]
macros allow you to specify code that is always run before,
after, or around expressions in a test case.

@defform[(before before-expr expr-1 expr-2 ...)]{

Whenever control enters the scope execute the @racket[before-expr]
before executing @racket[expr-1], and @racket[expr-2 ...]}

@defform[(after expr-1 expr-2 ... after-expr)]{

Whenever control exits the scope execute the @racket[after-expr]
after executing @racket[expr-1], and @racket[expr-2 ...]  The @racket[after-expr] is
executed even if control exits via an exception or other means.}

@defform[(around before-expr expr-1 expr-2 ... after-expr)]{

Whenever control enters the scope execute the
@racket[before-expr] before executing @racket[expr-1 expr-2
...], and execute @racket[after-expr] whenever control
leaves the scope.}

Example:

The test below checks that the file @tt{test.dat} contains
the string @tt{"foo"}.  The before action writes to this
file.  The after action deletes it.

@racketblock[
 (around
   (with-output-to-file "test.dat"
      (lambda ()
        (write "foo")))
   (with-input-from-file "test.dat"
     (lambda ()
       (check-equal? "foo" (read))))
   (delete-file "test.dat"))
]


@defform[(delay-test test1 test2 ...)]{

This somewhat curious macro evaluates the given tests in a
context where @racket[current-test-case-around] is
parameterized to @racket[test-suite-test-case-around].  This
has been useful in testing RackUnit.  It might be useful
for you if you create test cases that create test cases.}
