sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 518 forks source link

Why BATS syntax raises so many shellsheck errors? #188

Closed edouard-lopez closed 7 years ago

edouard-lopez commented 7 years ago

I wrote the following add-channel.tests.bats tests suite, works fine. However shellsheck keep raising errors.

Shellcheck errors

All the test case are seen has buggy and shellcheck stop on:

 ^-- SC1070: Parsing stopped here because of parsing errors.

output:

$ shellcheck -s bash ./test/add-channel.tests.bats

In ./test/add-channel.tests.bats line 1:
#!/usr/bin/env bats
^-- SC1008: This shebang was unrecognized. Note that ShellCheck only handles sh/bash/ksh.

In ./test/add-channel.tests.bats line 21:
@test "should raise error without NAME parameter" {                                                                                                                                                                                                                  ^-- SC1083: This { is literal. Check expression (missing ;/\n?) or quote it.

In ./test/add-channel.tests.bats line 25:
    [[ $(remove_ansi ${lines[1]}) == "NAME missing (see 'mast-utils list-host')" ]]
                     ^-- SC2086: Double quote to prevent globbing and word splitting.

In ./test/add-channel.tests.bats line 26:
}
^-- SC1070: Parsing stopped here because of parsing errors.

Question

How do I fix those BATS/shellcheck issues?

P.S.: cross-posting AtomLinter/linter-shellcheck#84.

jhmartin commented 7 years ago

The test files are not purely BASH, hence why the extension of the filename is .bats not .sh, and why the shebang is to bats. It is not reasonable to apply shellcheck to bats file as they are not parsed properly by shellcheck.

edouard-lopez commented 7 years ago

@jhmartin there is a branch to support bats in shellcheck and an issue koalaman/shellcheck#417