filmil / bazel-bats

bazel-bats: bazel test rules for the BATS testing framework (based on bats-core)
Apache License 2.0
10 stars 4 forks source link

Tests fail with No such file or directory after updating to 0.32.1 from 0.32.0 #30

Closed pfiaux closed 6 months ago

pfiaux commented 6 months ago

I tried to run the new version (everything runs fine on 0.32.0) but all the tests are now failing with some version of

No such file or directory or exited with code 127, indicating 'Command not found'. Use run's return code checks, e.g. run -127, to fix this message.

I tested 0.33.0 initially but it seems to happen in 0.32.1 already, my guess is it is related to https://github.com/filmil/bazel-bats/pull/26

Our tests are mostly structured like this:

@test "some test" {
    run $BATS_TEST_DIRNAME/some-script.sh

    [ "$status" -eq 1 ]
    # Some more asserts here
}

The build file looks like:

bats_test(
  name = "tests_scripts",
  srcs = glob(["*.bats"]),
  size = "small",
  deps = [ ":scripts" ],
)

filegroup(
    name = "scripts",
    srcs = glob(["*.sh"]),
)

I added an ls $BATS_TEST_DIRNAME to my test case before the run and noticed:

If I change deps = [ ":scripts" ], to data = [ ":scripts" ], the files are once more available and it passes. It's a bit surprising for a change in the patch version but maybe we were using it wrong before. Any recommendation here?

filmil commented 6 months ago

I think you might need to use sh_library instead of filegroup for the target :scripts.

deps is supposed to be used to declare executable deps, but the dep target itself must be executable. While I think it is confusing that the old version used to work for you with deps = [ ...], its current behavior is correct strictly speaking. This is because data is supposed to declare non-executable files and filegroups, while deps declares executable files, such as libraries.

In the case of scripts, the difference is of course purely academic, since all files are interpreted. But strictly speaking, the use of data or filegroup for executable deps is incorrect.

pfiaux commented 6 months ago

replacing filegroup to sh_library works and no other changes needed (both use srcs). Thanks for the help and quick reply.