-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
syntax: add bats support #600
Comments
It's unfortunate that Bats isn't compatible with POSIX Shell; I imagine they could have done something similar to what Go did, like:
But in any case, that ship has sailed. They created their own language, and I clearly can't resist that or the tool's popularity. At least they stuck to Bash and only made that one language change. I think we could add another shell language variant based off of Bash, and teach the parser about an extra reserved word. |
Annoyingly enough, upstream bats allows this:
That is, it supports multiple words as the test description, not just one. I don't think anyone actually does that, and they don't have a formal language specification other than the somewhat horrifying regular expression below, so I'll go ahead and do the same thing shellcheck does - only support the
|
In addition to the above comment, bats convert those test names to valid bash function names, e.g.
The internal test name is available at The test name encoding is done here: https://github.com/bats-core/bats-core/blob/master/libexec/bats-core/bats-preprocess#L4 |
I imagine that doesn't really concern us, because we never have to build the test name. I still find it bizarre that they allow multiple words in that syntax. |
This is now in master; please test it and let me know how it works. Note that using something like |
@mvdan thanks so much for implementing this! I just compiled shfmt from the current HEAD (which happens to be c5ff78f) and it shows nothing for bats files. For example $ cat << EOF > a.bats
> @test "one two" {
> echo foo
> }
> EOF
$ ./shfmt -ln bats -d a.bats; echo $?
0
$ ./shfmt -ln bats a.bats; echo $?
0 Just in case, I checked the same binary works with bash input. Not sure if I'm missing something... |
Oh dear, this is why unit tests aren't always enough :) |
Okay, that was a silly regression introduced in a "cleanup" done around the same time, but unrelated to Bats support. I've added copious tests, so that won't happen again. Please try again. |
aaand it works now, thanks! 🤗 |
Most *.bats tests here use tabs; let's reformat this file, too. Brought to you by shfmt -ln bats -w status.bats (yes, shfmt added bats support recently, see mvdan/sh#600). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Various bats tests use various types of indentation (about half is tabs, the rest is 2 spaces, 4 spaces, etc.). Let's bring it to one style (tabs) using recently added shfmt support for bats files (see [1]). This commit is brought to you by shfmt -ln bats -w tests/integration/*.bats [1] mvdan/sh#600 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Most *.bats tests here use tabs; let's reformat this file, too. Brought to you by shfmt -ln bats -w status.bats (yes, shfmt added bats support recently, see mvdan/sh#600). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Most *.bats tests here use tabs; let's reformat this file, too. Brought to you by shfmt -ln bats -w status.bats (yes, shfmt added bats support recently, see mvdan/sh#600). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
shfmt has recently added support for bats files formatting (see mvdan/sh#600), so let's use it. We have to use git HEAD for now since there was no release done with this feature yet. Unfortunately, shfmt introduces an alledged regression (see [1]) so we have to specify `-ln bash` explicitly in Makefile. This commit has brought to you by go get 'mvdan.cc/sh/v3@master' go mod vendor go mod tidy [1] cri-o#4253 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
shfmt has recently added support for bats files formatting (see [1]), so let's use it. We have to use git HEAD for now since there was no release done with this feature yet. Unfortunately, shfmt introduces an alledged regression (see [2]) so we have to specify `-ln bash` explicitly in Makefile. This commit has (mostly) brought to you by go get 'mvdan.cc/sh/v3@master' go mod vendor go mod tidy [1] mvdan/sh#600 [2] mvdan/sh#617 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Various bats tests use various types of indentation (about half is tabs, the rest is 2 spaces, 4 spaces, etc.). Let's bring it to one style (tabs) using recently added shfmt support for bats files (see [1]). This commit is brought to you by shfmt -ln bats -w tests/integration/*.bats [1] mvdan/sh#600 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Bats (https://github.com/bats-core/bats-core/) is a tool to write scripts in bash, with a few twists. A .bats file looks very much like a shell file, except for some added functions and features.
I think, the only change that is absolutely required to support bats is to recognise
@test
statement.@test "some name" {
denotes a test case. From the purpose of a formatter, I think it can be treated similar tofunction some_name {
.For the reference, shellcheck has added .bats support here: damienrg/shellcheck@f187382
The text was updated successfully, but these errors were encountered: