Sharing functions not working when running single test file
edouard-lopez opened this issue · 4 comments
I'm looking for a way to run code before all tests in a test file. Currently I'm following suggestion from #10 and created a _setup.fish
:
function setup
docker pull edouardlopez/pure-fish
end
setup
Files
My tests/ directory contains:
❯ ls -1 tests/
ci.test.fish
__pure_set_default.test.fish
_setup.fish
Running tests using a glob
If I run my tests with a glob the _setup.fish
is run but not at the beginning. It seems it runs alphabetically.
$ fishtape tests/*
type: Could not find “”
TAP version 13
ok 1 set my_var default value
ok 2 skip setting value if default already exists
Using default tag: latest
latest: Pulling from edouardlopez/pure-fish
Digest: sha256:255942bf7c89a2423ccc38a3bb6f3ea96456fef5aee96f799e35ba18f7e2ac38
Status: Image is up to date for edouardlopez/pure-fish:latest
ok 3 install manually (default behaviour of `docker-pure-fish`)
ok 4 install with fisher
ok 5 install with OMF (Oh-My-Fish!)
ok 6 install with Fundle
Running specific test case
If I run a test case explicitly, then the _setup.fish
is not run at all (no mention of docker
pulling an image):
❯ fishtape tests/ci.test.fish
type: Could not find “”
TAP version 13
ok 1 install manually (default behaviour of `docker-pure-fish`)
ok 2 install with fisher
ok 3 install with OMF (Oh-My-Fish!)
ok 4 install with Fundle
1..4
# tests 4
# pass 4
# ok
Expectations
_setup.fish
runs even when calling a specific test case._setup.fish
should always run first.
For my particular purpose of running a code before all tests, extracting the content of the setup
function at the beginning of the ci.test.fish
file is sufficient.
@edouard-lopez Are you saying that __pure_set_default.test.fish runs before _setup.fish?
Maybe you misunderstand #10? Fishtape runs _setup.fish first because the name starts with an underscore, nothing else. If your test files are also preceded by an underscore, then you have a problem. I suggest you change your files names.
Or maybe we should reopen #10 :)
Reading #10 I assumed you were considering _init.fish
and _setup.fish
as special filename.
I put a comment on #10 to explicit it's based on filename order.
First point came from the same assumption, that you were looking for those file and run them prior to any test case.
@edouard-lopez Instead of confering special meaning to certain file names within Fishtape, we can use @setup.fish
instead of _setup.fish
and keep things simple.
$ printf "%s\n" *.fish
@setup.fish
_setup.fish