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

bats: bogus SC2034 (no support for bats' load?) #2041

Open
1 of 2 tasks
kolyshkin opened this issue Aug 20, 2020 · 1 comment
Open
1 of 2 tasks

bats: bogus SC2034 (no support for bats' load?) #2041

kolyshkin opened this issue Aug 20, 2020 · 1 comment

Comments

@kolyshkin
Copy link
Contributor

For bugs

  • Rule Id: SC2034
  • My shellcheck version (shellcheck --version or "online"): 0.7.1
  • The rule's wiki page does not already cover this
  • I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
    (I can't try since my repro consists of two files)

Here's a snippet or screenshot that shows the problem:

helpers.bash:

#!/bin/bash

FOO=bar

function prepare() {
	echo $FOO
}

a.bats:

#!/usr/bin/env bats

load helpers

@test default {
	prepare | grep -w bar
}

@test override {
	FOO=whatever
	prepare | grep -w whatever
}

Here's what shellcheck currently says:

$ shellcheck -x a.bats
In a.bats line 10:
	FOO=whatever
        ^-^ SC2034: FOO appears unused. Verify use (or export if used externally).

For more information:
  https://www.shellcheck.net/wiki/SC2034 -- FOO appears unused. Verify use (o...

Here's what I wanted or expected to see:

No errors, like in the following example using pure bash:

helpers.bash:

#!/bin/bash

FOO=bar

function prepare() {
	echo $FOO
}

a.sh:

#!/bin/bash

set -e
. helpers.bash

function test_default() {
	prepare | grep -w bar
}

function test_override() {
	FOO=whatever
	prepare | grep -w whatever
}

test_default
test_override

Test execution to see if it works:

$ bash ./a.sh 
bar
whatever
$ echo $?
0

shellcheck run (shows no warnings):

$ shellcheck -x ./a.sh 
$ echo $?
0

Additional information

In case I move function prepare() from helpers.bash to the main a.bats file, the warning goes away.

The very same repro using pure bash (see above) does not result in a warning.

This probably means that bats' load statement is not recognized in a way similar to bash' source.

kolyshkin added a commit to kolyshkin/cri-o that referenced this issue Aug 28, 2020
This is a bogus warning, for details please see
koalaman/shellcheck#2041

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/cri-o that referenced this issue Aug 28, 2020
This is a bogus warning, for details please see
koalaman/shellcheck#2041

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/cri-o that referenced this issue Aug 28, 2020
This is a bogus warning, for details please see
koalaman/shellcheck#2041

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin added a commit to kolyshkin/cri-o that referenced this issue Sep 18, 2020
This is a bogus warning, for details please see
koalaman/shellcheck#2041

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin changed the title bogus SC2034 for bats (no support for bats' load?) bats: bogus SC2034 (no support for bats' load?) Oct 9, 2020
@kolyshkin
Copy link
Contributor Author

@koalaman PTAL 🙏

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

No branches or pull requests

1 participant