jackfirth / racket-disposable

An experimental Racket library providing an abstraction for values associated with external resources that allows automatic resource pooling, per-thread virtual construction, and monadic composition
Apache License 2.0
7 stars 0 forks source link

Add rackunit integration via fixtures #6

Closed jackfirth closed 7 years ago

jackfirth commented 7 years ago

Given a bunch of test cases, it should be possible to define a fixture foo that contains a disposable. Each test case should get its own instance of the fixture, and the value of the fixture should be added to the check information stack of all checks in test cases using the fixture. This might look something like this:

(require disposable
         disposable/file
         rackunit/fixture)

(define-fixture foo (disposable-file))

(test-begin/fixture
  #:fixtures (foo)
  (check-equal? #"blah" (file->bytes (foo))))

...which should fail while looking something like this:

----------------
FAILURE
name:         check-equal?
location:     ...blah...
actual:       #""
expected:  #"blah"
fixtures:
  foo:        "/tmp/path/to/tmpfile/12345"
-----------------

Allowing fixtures to depend on other fixtures might be important as well. Additionally, defining lists of fixtures statically might be useful, or defining some sort of simpler with-fixtures building block that can be abstracted over.

jackfirth commented 7 years ago

Brainstorm v2: the with-fixture option would definitely be simpler, and it wouldn't require redefining test-begin / test-case / test-suite etc:

(test-begin
  (with-fixture [foo]
    (check-equal? #"blah" (file->bytes (foo)))))

This requires each test declare individual fixtures, and makes it painful to use the same fixtures across a whole bunch of tests. However, those tests could be grouped into a single test with nested tests instead, or some other mechanism could be provided.

jackfirth commented 7 years ago

Done in separate package.