-
Notifications
You must be signed in to change notification settings - Fork 12
Description
It would be good to be able to provide data files inline in the test file somehow, rather than requiring a fixture for every such file, which is the recommended workflow in the docs: https://facebookincubator.github.io/scrut/docs/tutorial/#pattern-test-fixtures.
I don't always want to add a new fixture file for every piece of data I want to run as part of the test:
- Many of them are probably specific to the one test, rather than shared across multiple tests, for which it would make more sense to commit a dedicated fixture file.
- In my particular workflow, I try to run tests on commit messages, so it's not realistic to provide fixture files at all.
Possible solutions
Fixture syntax
You could imagine a syntax like
```scrut-fixture
my-fixture.txt
line 1
line 2
line 3
```
Then scrut might automatically write my-fixture.txt to $TESTDIR
scrut subcommand to read fixtures
Rather than automatically write fixture files, you could create a re-entrant scrut command which could read arbitrary metadata from the test. Perhaps your test would look like
```scrut-fixture
my-fixture.txt
line 1
line 2
line 3
```
```scrut
# determines the current test file from the environment
# and reads the appropriate fixture contents:
$ scrut fixture my-fixture.txt | grep '2'
line 2
```
stdin syntax
It would also work to be able to manually provide stdin. (I believe there is no such syntax right now?) Then you could recover inline data with a passthrough command. For example:
```scrut
$ cat >my-fixture.txt <<EOT
line 1
line 2
line 3
```
I don't think there's a way to provide stdin today?
Note that providing stdin can be meaningfully different compared to piping from a file or subprocess (i.e. the command can potentially observe the difference, depending on the OS), although it might not be an important problem in practice.