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

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

Closed
pfiaux opened this issue Apr 12, 2024 · 2 comments

Comments

@pfiaux
Copy link

pfiaux commented Apr 12, 2024

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 #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:

  • All the test files are present
  • There's a binary called "scripts" (name after the filegroup)
  • None of the .sh files I expect are present

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?

  • Should it work when using deps to bring in multiple scripts?
  • Should we bring in the scripts we want to test with using data rather than deps? (it feels wierd to bring executable scripts as data)
@filmil
Copy link
Owner

filmil commented Apr 12, 2024

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
Copy link
Author

pfiaux commented Apr 15, 2024

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

@pfiaux pfiaux closed this as completed Apr 15, 2024
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

2 participants