SimonKagstrom / kcov

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
http://simonkagstrom.github.io/kcov/
GNU General Public License v2.0
710 stars 109 forks source link

Missing coverage for multiline bash arrays and named pipes #363

Closed Ayowel closed 2 years ago

Ayowel commented 3 years ago

Tested on a CentOS 8 container with kcov tag pre-v40

As said in the title, kcov fails to detect usage of multiline arrays and named pipes in bash if they span multiple lines. What seems to happen is that the usage is detected but only attributed to the closing parenthesis' line.

Can be seen with this test file, which yields a 44.4% coverage rate instead of the expected 100%:

#!/bin/bash

# This works
a=( this is a test )

# This doesn't
b=(
  this is
  a test
)

# This works
cat <(echo Hello)

# This doesn't
cat <(
  echo Hello
)
SimonKagstrom commented 3 years ago

Yes, unfortunately I'd say this is yet another instance where #145 (a proper parser for Bash) would be needed. The current parser already has a set of nasty special-cases, and I suppose it would be possible to add more, but #145 would solve that once and for all.

Ayowel commented 3 years ago

Hadn't found the issue when searching, thanks for pointing me to it. Is there a list of sample codes that currently get an improper result or is the issue used to track the relevant issues and those individual issues should be used as code samples ? Re-using shfmt's parser was discussed, however after looking at shfmt's code it seems that you would need a wrapper library to be able to use it in C. Is this solution still on the table ?

SimonKagstrom commented 2 years ago

Unfortunately, there isn't really a conclusive list of improper results.

One way would be to add it to one of the scripts in tests, which gets run in the CI tests. That would be a good way of asserting that it works properly with a real parser.

I haven't looked more at shfmt, but I agree it would be a cumbersome way of implementing it.

Closing this since I think it's best to implement as a part of #145, although I can't really say when/if I'll work on that one. I'm personally mainly using kcov for compiled code and sometimes python, so I'm not actively bothered by the bash bugs.