bashcov icon indicating copy to clipboard operation
bashcov copied to clipboard

Option to suppress all bashcov output

Open pshirali opened this issue 6 years ago • 5 comments

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.

pshirali avatar Jan 25 '19 10:01 pshirali

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?

infertux avatar Jan 26 '19 04:01 infertux

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?

tomeon avatar Jan 26 '19 14:01 tomeon

In the scenario you've suggested, it looks like bashcov would generate coverage stats for validate-output.sh but not script.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?

infertux avatar Jan 27 '19 05:01 infertux

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.

pshirali avatar Jan 27 '19 07:01 pshirali

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.

bje- avatar Jun 27 '19 04:06 bje-