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

Make fishtape file compatible with fish_indent #34

Closed
1 task
edouard-lopez opened this issue Dec 11, 2018 · 9 comments
Closed
1 task

Make fishtape file compatible with fish_indent #34

edouard-lopez opened this issue Dec 11, 2018 · 9 comments
Labels
enhancement New feature or request

Comments

@edouard-lopez
Copy link
Contributor

edouard-lopez commented Dec 11, 2018

related: #32, fish-shell/fish-shell#5399


From discussion with @jorgebucaran and @faho it appears using fishtape file aren't validcompatible fish file. Hence the problem met while trying to format them with fish_indent (cf. #32).

Rationale

Adopting a validcompatible fish syntax will let us leverage all the tooling related to fish and help developers adopt testing approaches. So we get better integration and better software quality.

Fishtape example

test "current directory is home"
    $HOME = $DIRNAME
end

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

test "test is a builtin"
    "test" = (builtin -n)
end

test "no odds are evens"
    1 3 5 7 != (
        for i in (seq $n)
            if test (math $i%2) = 0
                echo $i
            end
        end
        )
end

Roadblocks

Can we list the roadblocks that prevent fishtape file from being validcompatible fish file ?

  • test already has a specific meaning in fish, and it does not start blocks. test is a keyword in fish 3.0
@edouard-lopez
Copy link
Contributor Author

Note that I might lack some insight in both fishtape and fish.

Addressing the use of test, it seems straightforward to re-write test case as function, e.g. prefixed by test_. Thus, we can easily evolve the awk script to match function test_ and leave the test body untouched.

For instance, we could write test.fish:

function test_current_directory_is_home
    $HOME = $DIRNAME
end

function test_math_still_works
    42 -eq (math 41 + 1)
end

Neither source test.fish nor fish test.fish throw error.

@jorgebucaran
Copy link
Owner

@edouard-lopez I am sure you're already aware of this, but I should point out that this is not valid fish either.

@edouard-lopez edouard-lopez changed the title Make fishtape file valid fish files Make fishtape file compatible with fish_indent Dec 11, 2018
@edouard-lopez
Copy link
Contributor Author

Sure but fish doesn't complain about it until we call the function.

❯ source /tmp/fishtape.fish
❯ test_current_directory_is_home/tmp/fishtape.fish (line 1): Variables may not be used as commands. In fish, please define a function or use 'eval $HOME'.
in function “test_current_directory_is_home”
called on standard input
❯ test_math_still_works
42: command not found
in function “test_math_still_works”
        called on standard input

I update the issue to target compatibility instead of validity. Do you think it's an attainable goal?

@edouard-lopez
Copy link
Contributor Author

Using begin; [COMMANDS...;] end you can't source or execute the file as the code inside begin is executed. But you don't seem to source or execute test file and again it's simple to achieve.

Anyway it could be:

begin "say_hello"
    echo Hello $argv
end
begin test_say_hello
    $HOME = $DIRNAME
end
begin test:say_hello
    echo Hello $argv
end

Is there other alternative syntax you can think of?

@jorgebucaran
Copy link
Owner

@edouard-lopez All of those look good, also:

begin test "is home"
    $HOME = $DIRNAME
end

@edouard-lopez
Copy link
Contributor Author

Good one. However vscode-fish-ide show a syntax error:

selection_217

Variables may not be used as commands. In fish, please define a function or use 'eval $HOME'.

For reference, it's not the case with the function
selection_218

@faho
Copy link
Contributor

faho commented Dec 12, 2018

Variables may not be used as commands. In fish, please define a function or use 'eval $HOME'.

Fortunately, that's not true with fish 3.0 anymore, so you can just upgrade to the 3.0 beta and that bit should be gone.

/plug


So... what you two seem to be discussing is how to make this look like fish-script.

That solves the immediate concern that fish_indent indents it "wrong", but it's still essentially invalid fish-script. You're still saving this as ".fish", and fish some-tape-test.fish would do something nonsensical.

E.g.

begin test "is home"
    $HOME = $DIRNAME
end

will test if "is home" is a non-empty string, throw away the result, then try to run $HOME as a command with the arguments "=" and "$DIRNAME" (post-3.0) or print an error that variables aren't allowed as commands (pre-3.0).

Why not either invent syntax whole-cloth and call the scripts ".tape", or find a way to make this working fish-script, just with some convenience functions?

@jorgebucaran
Copy link
Owner

@edouard-lopez I've updated #31 with the new syntax I have in mind. Feedback welcome. 🙏

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

@edouard-lopez Fishtape tests are now compatible with fish_indent. See the changelog:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants