9

Is it possible to measure the code coverage of an executed shell script instead of a sourced one?

I have a shell script with a couple of switches, options. I have added a few tests and I want to measure the test suite's coverage.

Sources:

The script.

And its tests.

As you can see the tests.sh executes the shell script instead of calling its functions in the same shell. This way I couldn't get kcov to measure the coverage on the script. I was only able to measure the coverage on the file tests.sh.

Is it possible somehow to force kcov to measure the main script's coverage?

This command was the best I could achieve:

/usr/local/bin/kcov --debug=31 coverage/ test/tests.sh

And in the result I see only coverage report about shunit2 and tests.sh, but in the debug output I see references to misspell_fixer.sh as well. So I'm suspicious that it could work.

pants
  • 192
  • 13
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
  • Please take a look to LCOV.SH full BASH implementation of coverage... no need additional interpreters like RUBY or BINARY executable in your machine. Check coverage of BASH just with BASH https://github.com/javanile/lcov.sh – Francesco Bianco Jun 07 '20 at 10:00

1 Answers1

7

Please submit a bug report to the kcov issue tracker,

https://github.com/SimonKagstrom/kcov

it should support this as far as I can tell. (I'm the author of Kcov).

  • Thank you. I just created: https://github.com/SimonKagstrom/kcov/issues/45 I noticed that `set +x` can stop collecting data. Should I open a ticket for this as well? – Lajos Veres Dec 26 '14 at 19:37
  • kcov uses bash tracing to collect it's data, so that particular issue is probably difficult to get around. I can file a bug about it myself though, since other people are also likely to run into it at times. – Simon Kågström Dec 27 '14 at 09:10