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

bash coverage problems with for loops and while #387

Open
sschmid opened this issue Oct 21, 2022 · 1 comment
Open

bash coverage problems with for loops and while #387

sschmid opened this issue Oct 21, 2022 · 1 comment

Comments

@sschmid
Copy link

sschmid commented Oct 21, 2022

Hi @SimonKagstrom,

I hope you're doing well.

I ran into issues where certain lines being reported as not covered when using kcov, bash and bats.
I extracted samples to reproduce:

I attached the coverage report to the kcov-coverage GitHub action artifacts:

main() {
  while read -r i; do
    echo -n "-$i"
  done < <(seq 1 3)     # not covered
}

while read -r i; do
  echo -n "-$i"
done < <(seq 1 3)       # covered

main

Screen Shot 2022-10-21 at 16 35 03

The kcov-coverage sample also includes for loops which are covered as expected.
In my actual project they are not.

example 1: https://coveralls.io/builds/53486336/source?filename=src%2Fbee-run.bash#L147
example 2: https://coveralls.io/builds/53486336/source?filename=src%2Fbee-run.bash#L155

When scolling through the report you will find multiple locations where for or while loops are not covered.

This is how I use kcov: see GitHub action ci.yml
https://github.com/sschmid/kcov-coverage/blob/main/.github/workflows/ci.yml

Do you have an idea what is going on or how I can fix this?

@SimonKagstrom
Copy link
Owner

Unfortunately, it probably comes down to #145, i.e., a real parser for shell scripts. As to why these two cases differ, I can't say. Seems like strange behavior from bash I'd say.

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