Hey look! There’s a demo: infertux.github.io/bashcov/test_app.

What is it?

I’m a big fan of both Ruby’s SimpleCov and Bash. Bashcov is my dream to have in Bash what SimpleCov is to Ruby.

Oddly enough, I didn’t find any coverage tool for Bash except shcov but as stated there, shcov is:

somewhat simplistic and doesn’t handle all possible cases very well (especially when we’re talking about long and complex lines)

Indeed, it doesn’t work very well for me. I have covered lines marked as uncovered and some files completely missed although executed through another script (via source). Moreover, I’m not sure it is still being actively maintained. This makes me feel like a sad panda :(

Bashcov aims to be a neat and working coverage tool backed by SimpleCov and simplecov-html.

How does it work?

Ruby has a coverage module which computes the coverage on demand. Unfortunately, Bash doesn’t have such niceties but we can use the xtrace feature which prints every line executed using PS4.

After a bit of parsing, it sends results through SimpleCov which generates an awesome HTML report.

And of course, you can take great advantage of SimpleCov by adding a .simplecov file in your project’s root (like this).

Is it ready?

Well, I’ve been working on it for a few months now and it looks stable enough for a 1.0.0 release. There is one glitch I’d like to get rid of but apart from that, it works pretty well for me.

My yardstick is currently RVM because it has a relatively big codebase and extensive tests.

If you have a Bash project and tests for your code, you could give Bashcov a try to see what code you’re actually covering through your testsuite. I’d love to hear your feedback if so!