bashcov icon indicating copy to clipboard operation
bashcov copied to clipboard

Coverage report is not generated when running the bash script via Java getRuntime().exec()

Open randheerar opened this issue 1 year ago • 4 comments

Hi,

I am executing a bash script from Java code using Java getRuntime().exec() as below. Though the script executed without any issues, still the coverage report is not generated String[] cmd = new String[]{"echo", ""SUDOPASSWORD"", "|", "sudo", "-s", "bashcov", "/tmp/script.sh", "--root", "/tmp/"}; Runtime.getRuntime().exec(cmd);

Is there a known limitation in running this way?

randheerar avatar Mar 11 '24 17:03 randheerar

@randheerar -- what version of Bashcov are you using? Given that you are running Bashcov as root, this may be related to #31, #43, #56 (Bash versions 4.4 and above, when run as root, do not inherit PS4 from their environment). If you are not on Bashcov 3.x, could you please upgrade Bashcov and then check whether the issue persists?

For what it's worth, I don't think that there are any known limitations with running Bashcov under Java.

tomeon avatar Mar 12 '24 04:03 tomeon

@tomeon bashcov 3.1.2 with Bash 5.1, Ruby 3.0.4, and SimpleCov 0.22.0 Let me check if there is any new update

randheerar avatar Mar 13 '24 06:03 randheerar

3.1.2 is the latest release, and the bashcov executable in this release can be run as root (though "it is not recommended", to quote the linked changelog entry).

@randheerar -- could you provide a link to the code that suffers from this issue, if one is available? Otherwise, could you provide a minimal reproduction case that I can test?

tomeon avatar Mar 14 '24 15:03 tomeon

@tomeon Apologies for the delay. With v3.1.2, I was able to get the coverage. Let me start with that.

Thanks a lot for the help!

randheerar avatar Apr 11 '24 11:04 randheerar

Looks like this is resolved, thank you @tomeon :)

infertux avatar Aug 28 '24 23:08 infertux