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

Option to suppress all bashcov output #47

Open
pshirali opened this issue Jan 25, 2019 · 5 comments
Open

Option to suppress all bashcov output #47

pshirali opened this issue Jan 25, 2019 · 5 comments

Comments

@pshirali
Copy link

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.

@infertux
Copy link
Owner

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?

@tomeon
Copy link
Collaborator

tomeon commented Jan 26, 2019

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?

@infertux
Copy link
Owner

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?

@pshirali
Copy link
Author

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.

@bje-
Copy link

bje- commented Jun 27, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants