Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fishtape 2 #31

Closed
jorgebucaran opened this issue Oct 27, 2018 · 5 comments
Closed

Fishtape 2 #31

jorgebucaran opened this issue Oct 27, 2018 · 5 comments
Labels
meta Announcements, migration guides, news

Comments

@jorgebucaran
Copy link
Owner

jorgebucaran commented Oct 27, 2018

Fishtape 2 will break the test syntax as we want to make it compatible with fish_indent #32, #34.

Summary

  • Make test syntax compatible with fish_indent
  • Run test files in parallel (not assertions, but files)
  • Remove --pipe in favor of any userland solution like "fish -c "fishtape *.fish | tap-nyan"
  • Remove the built-in test array extensions (don't know what I am talking about? don't worry then)

Here's the new test syntax I have in mind. See that test blocks are now gone. The test builtin has been "enhanced" to take an optional test description. If you already know how to use the shell's test builtin you already know how to create valid assertions in Fishtape 2.

@test "current directory is home" $PWD = $HOME

@test "math works" 42 -eq (math 41 + 1)

@test "test is a builtin" (contains -- test (builtin -n)) $status -eq 0

for odd in 1 3 5 7 9
    @test "$odd is not an even number" (
        contains -- $odd (seq 10 | awk '!($0%2)')
    ) $status -eq 0
end

@test "git_is_dirty shows changes not staged for commit" (
    pushd /path/to/some/dirty/git/repo
    git_is_dirty
    echo $status
    popd
) = 1

Notice that there is no reason you couldn't write the last test from above as follows (if you prefer):

pushd /path/to/some/dirty/git/repo
git_is_dirty
@test "git_is_dirty shows changes not staged for commit" $status = 1
popd

Issue History

@jorgebucaran jorgebucaran mentioned this issue Jan 31, 2019
@jorgebucaran jorgebucaran added the meta Announcements, migration guides, news label Jan 31, 2019
@edouard-lopez
Copy link
Contributor

edouard-lopez commented Feb 3, 2019

Sound nice.

I will recommend to use the command substitution syntax test "description" ( … ) in order to isolate test from one another. The last example, with code outside, could have side effects on following test case.
I also reckon the former allow one to use local variables but not the letter (I'm on mobile so didn't check this)

@jorgebucaran
Copy link
Owner Author

jorgebucaran commented Feb 3, 2019

@edouard-lopez To isolate your test you have two options.

  1. Use a begin..end block:
begin
    pushd /path/to/some/dirty/git/repo
    git_is_dirty
    test "git_is_dirty shows changes not staged for commit" $status = 1
    popd
end
  1. Use command substitution:
test "git_is_dirty shows changes not staged for commit" (
    pushd /path/to/some/dirty/git/repo
    git_is_dirty
    echo $status
    popd
) = 1

@jorgebucaran jorgebucaran changed the title Rewrite Fishtape 2 Feb 6, 2019
@jorgebucaran
Copy link
Owner Author

jorgebucaran commented Feb 6, 2019

Instead of overloading the test builtin I propose using a different syntax for creating tests, e.g. assert or @test. I prefer @test (to take advantage of syntax highlighting).

This helps make clear when you are writing a test or using the test builtin for something else.

if test "$version" = 3.0.0
    @test "Has some file" -f somefile
end

@edouard-lopez
Copy link
Contributor

BATS, the test framework for bash use @test syntax too.

jorgebucaran added a commit that referenced this issue Feb 7, 2019
* Make test syntax compatible with fish_indent; #34 #27
* Run test files in parallel (not assertions, but files)
* Remove `--pipe` in favor of any userland solution like:
  `"fish -c "fishtape *.fish | tap-nyan"`
* Remove the built-in `test` array extensions
@jorgebucaran
Copy link
Owner Author

🎉 I'm done implementing everything. See the changelog:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Announcements, migration guides, news
Projects
None yet
Development

No branches or pull requests

2 participants