bashcov
bashcov copied to clipboard
Option to suppress all bashcov output
I'm assuming here that --mute
was added to suppress the output from scripts under coverage
bashcov generates some output of its own, like the "Run completed using ..." at the end of its execution. There is no bashcov switch to suppress such output (amongst others)
Scenario: This would be useful in tests which execute shell script and verify stdout/stderr. The script-under-test's invocation could be prefixed with bashcov with a suppress switch; thus gathering coverage without breaking any existing stdout/stderr based validation.
I'm not sure I understand that scenario. Couldn't you use bashcov ./validate-output.sh < ./script.sh
instead of ./validate-output.sh bashcov ./script.sh
to work around that issue?
Couldn't you use bashcov ./validate-output.sh < ./script.sh instead of ./validate-output.sh bashcov ./script.sh to work around that issue?
In the scenario you've suggested, it looks like bashcov
would generate coverage stats for validate-output.sh
but not script.sh
, no?
In the scenario you've suggested, it looks like bashcov would generate coverage stats for
validate-output.sh
but notscript.sh
, no?
Correct. Sorry for the sloppy example. My point was that you should be able to use a wrapper script that checks the output of your actual script. Bashcov would call the wrapper script which in turn would call the actual script, similarly to this. Or am I missing something?
My point was that you should be able to use a wrapper script that checks the output of your actual script. Bashcov would call the wrapper script which in turn would call the actual script.
No, the wrapper script would invoke bashcov <script-under-test.sh>
.
Let me illustrate an example:
showvars.sh -- This is the script under test
#!/bin/bash
echo $@
testvars.sh -- A crude example of a script that tests showvars.sh
#!/bin/bash
TEST_SCRIPT='./showvars.sh'
test_one () {
output=$($TEST_SCRIPT 1 2 3 4 5 2> /dev/null)
if [[ "$output" != "1 2 3 4 5" ]]; then
echo "FAIL"
echo "--- <stdout> ---"
echo "$output"
echo "--- </stdout> ---"
exit 1
else
echo "PASS"
fi
}
# ...
# Assume that there are more tests, each of which invokes
# TEST_SCRIPT with different args, and verifies exitCode,
# stdout, stderr either in full or in parts
test_one
In the above case, if I could modify TEST_SCRIPT
to something like:
TEST_SCRIPT='bashcov <suppress-switch> ./showvars.sh
then I could generate coverage for ./showvars.sh
using the test execution paths defined in ./testvars.sh
.
Since a suppress switch doesn't exist, if I currently switch to using bashcov ./showvars.sh
, I'd get:
FAIL
--- <stdout> ---
1 2 3 4 5
Run completed using bashcov 1.8.2 with Bash 3.2, Ruby 2.3.7, and SimpleCov 0.15.1.
Coverage report generated for /bin/bash ./showvars.sh 1 2 3 4 5 to /Users/praveen/temp/bashcov/coverage. 1 / 11 LOC (9.09%) covered.
--- </stdout> ---
Note that the aim here is to get coverage on ./showvars.sh
and not on ./testvars.sh
. It's possible that the wrapper ./testvars.sh
may not always be written in bash (may be perl/python). So, ideally bashcov
should be prepended to ./showvars.sh
and not the wrapper ./testvars.sh
If there was a switch on bashcov
that would suppress its own stdout, stderr and also exit with the same exit code as the bash-script-under-test (./showvars.sh), then bashcov
could be a drop-in that'd generate coverage without breaking any existing tests.
It needs to be possible to suppress all bashcov output so that it doesn't produce unwanted output that can disturb test harnesses, CI systems, etc.