infertux / bashcov

Code coverage tool for Bash
MIT License
151 stars 20 forks source link

Fix shebang #72

Closed Freed-Wu closed 1 year ago

Freed-Wu commented 1 year ago

NixOS doesn't have /bin/bash. Replace it by /usr/bin/env bash.

Freed-Wu commented 1 year ago

https://github.com/infertux/bashcov/blob/master/lib/bashcov.rb#L79

Why not get bash path from env bash?

infertux commented 1 year ago

https://github.com/infertux/bashcov/blob/master/lib/bashcov.rb#L79

Why not get bash path from env bash?

The main issue with using env is that you cannot pass arguments to bash that way, e.g. /usr/bin/env bash -eu doesn't work. You need to call set -eu as a separate command. This would also fail here.

I started working on it in this commit however the build is still failing. I don't have more time for this at the moment so feel free to continue the work in the pr-72 branch, either here or on GitLab to run tests with GitLab CI. You can also run tests locally with the ./test.sh script in the repo.

Freed-Wu commented 1 year ago

I file a package request for NixOS here. If we want to use bashcov in NixOS, we should fix those shebangs. I am not faimilar with ruby, and anyone who is familiar can discuss on the issue

Freed-Wu commented 1 year ago

The main issue with using env is that you cannot pass arguments to bash that way, e.g. /usr/bin/env bash -eu doesn't work. You need to call set -eu as a separate command. This would also fail here.

I think it should be /usr/bin/env -S bash -eu.

infertux commented 1 year ago

Superseded by #74

infertux commented 1 year ago

Bashcov 3.0.3 has been released, please give it a try.

tomeon commented 1 year ago

@infertux -- the changes in this PR are still needed, I think.

infertux commented 1 year ago

@tomeon It's only touching test files so we only need it if we want to run the test suite on NixOS. I assumed we wouldn't but now that we have GitHub Actions set up, is there a way to leverage it and run the tests under NixOS as well?

tomeon commented 1 year ago

[I]s there a way to leverage [GitHub Actions] and run the tests under NixOS as well?

There sure is :). I will see about adding it to the nix-support branch.

FWIW, NixOS is my distro of choice these days, so the updated shebangs are helpful for my development workflow. Anyway, better portability is better portability :).

However! Switching from #!/bin/bash to #!/usr/bin/env bash in the test suite is neither necessary nor sufficient to solve "file not found" errors when running the test suite in the Nix build sandbox while constructing a Nix package of Bashcov. The build sandbox provides neither /bin/bash nor /usr/bin/env. Instead, I've use the patchShebangs hook function from the Nixpkgs standard environment to fix up the test scripts' shebangs prior to running RSpec and Cucumber tests.

@Freed-Wu -- if you are a Nix flakes user, I'd be much obliged if you could check out the nix-support branch.

Freed-Wu commented 1 year ago

check out the nix-support branch.

nix build can work. :+1: