jorgebucaran / fishtape

100% pure-Fish test runner
MIT License
347 stars 20 forks source link

Missing $DIRNAME in fishtape 2.0.0 #39

Closed edouard-lopez closed 5 years ago

edouard-lopez commented 5 years ago

related: 2.0.0, #38


Thanks for the new release, I haven't made the switch yet, but look forward to it.

In the release note for 2.0.0 you mention removing $DIRNAME variable. That annoying, cause I'm using it a on every test files for pure to import function under test, like:

source $DIRNAME/../functions/_pure_prompt_first_line.fish

Sure it's possible to use $filename however such a name is prone to conflict and makes code a less readable:

source (dirname $filename)/../functions/_pure_prompt_first_line.fish

BATS as a series of special variables prefixed by $BATS_TEST_ (e.g. $BATS_TEST_DIRNAME).

I reckon namespacing is a must have, and would love to see dirname come back :heart:

Some namespace ideas:

$fishtape_test_dirname
$ft_test_dirname
$_test_dirname
jorgebucaran commented 5 years ago

@edouard-lopez I disagree on code readability, but I'm curious to know how $filename is prone to conflicts? Recall that tests run in their own subshell.

Your source trick will not work, because $filename is really just the name, not the full path, so I'm positive about adding $dirname back.

$dirname/Users/foo/bar $filenametest.fish

What about also?

$pathname/Users/foo/bar/test.fish

Too much? :)

edouard-lopez commented 5 years ago

Readability is not that bad indeed.

In several scripts I wrote, I rename files and use $filename as the variable name that contains the filename extracted from a path. Sure the subshell might prevent conflict, but shouldn't we know it's a fishtape variable and not one from our script?

I tend to prefer $filepath over $pathname. To have both $dirname, $filename and $pathname seem a bit redundant.

jorgebucaran commented 5 years ago

@edouard-lopez Like this?

Any ideas for more variables?

edouard-lopez commented 5 years ago

LGTM.

No other requirement for me at the moment.

jorgebucaran commented 5 years ago

Added in https://github.com/jorgebucaran/fishtape/commit/b195bc15de838887a153e6ad50555a04085ce307 (here).

In the end I went with$current_dirname and $current_filename instead.

Release notes coming up later! 👋

jorgebucaran commented 5 years ago

Release Notes