Skip to content

Measuring executed shell scripts coverage under shunit #45

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

Closed
vlajos opened this issue Dec 26, 2014 · 9 comments
Closed

Measuring executed shell scripts coverage under shunit #45

vlajos opened this issue Dec 26, 2014 · 9 comments

Comments

@vlajos
Copy link
Contributor

vlajos commented Dec 26, 2014

Hi,

Referencing this: http://stackoverflow.com/questions/27555639

Recipe to reproduce:
git clone git://github.com/vlajos/misspell_fixer.git
cd misspell_fixer
git checkout -qf 2d16e17c7901bd06e24d67f315e782f148d45d0b
curl -L "https://shunit2.googlecode.com/files/shunit2-2.1.6.tgz" | tar zx
rm -rf coverage;/usr/local/bin/kcov coverage/ test/tests.sh

And there isn't anything in the output regarding the misspell_fixer.sh

Finally I rewrote most of my script this way:
vlajos/misspell-fixer@b5ec1f7

Thank you.

Best regards,
Lajos

SimonKagstrom added a commit that referenced this issue Dec 27, 2014
Need to lookup BASH_XTRACEFD though, would be better than parsing
stderr.
@SimonKagstrom
Copy link
Owner

I tried running it with the lastest kcov commit, and I get coverage output at least. The above commit sees to it that the misspell_fixer.sh output to stderr is shown.

I saw you mentioned that set -x breaks coverage collection. This is true, since kcov actually uses the regular bash trace functionality to collect coverage data. I'm not sure if there's some workaround to fix that particular issue. There is a BASH_XTRACEFD environment variable, which perhaps can be used in some way, but I'm not sure it really bites.

@vlajos
Copy link
Contributor Author

vlajos commented Dec 27, 2014

I just compiled the latest version and used my above script, but I see only coverage report about tests.sh and shunit2 and nothing about the "main" misspell_fixer.sh.
Do I miss something?

@SimonKagstrom
Copy link
Owner

I tested the example you gave above (with the git commit referenced), and I get misspell_fixer.sh coverage. I ran it like

kcov /tmp/kcov ./misspell_fixer.sh -v ~/projects/kcov

and all coverage I see is from misspell_fixer.sh. How do you execute your test?

@vlajos
Copy link
Contributor Author

vlajos commented Dec 27, 2014

This way:
/usr/local/bin/kcov coverage/ test/tests.sh

@SimonKagstrom
Copy link
Owner

OK, good. I can reproduce it with that.

@SimonKagstrom
Copy link
Owner

Fixed with 57f6959.

The problem with the current solution was that kcov starts bash with -x <script>, which doesn't propagate into other programs executed. The fix above instead adds a file to be read in via BASH_ENV, so then it should be set for all scripts.

@vlajos
Copy link
Contributor Author

vlajos commented Dec 28, 2014

Thank you!

@vlajos
Copy link
Contributor Author

vlajos commented Dec 28, 2014

I don't know if it is related or not, but the loop_core function isn't covered . (The same recipe above.)

It is called this way: (after L200)
find "$@" -type f $cmd_part_ignore -and ( $opt_name_filter ) -exec bash -c 'loop_core "$0"' {} ;

The testReal0NoBackup test should call it.
The warning "Starting script" and warning "Done." before/after the find are covered.

@SimonKagstrom
Copy link
Owner

OK, I saw that too. I guess it might be a similar issue.

I can reproduce it with your script.

ericramos1980 added a commit to ericramos1980/codecov-bash that referenced this issue Feb 8, 2020
    steps:
      - checkout
      - run:
          name: Extract shunit
          name: Eric Ramos
          command: tar zxvf shunit2-2.1.6.tgz
      # per SimonKagstrom/kcov#45 (comment) this should work
      - run:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants