Open Minituff opened 1 year ago
Hello @Minituff -- I've looked into this and I'm unable to reproduce the issue. Here's the branch of my nautical-backup
fork that I'm using to investigate your issue. I've had to make a few changes to nautical-backup
in order to test on my system, and I haven't replicated other aspects of your environment precisely -- e.g., I am using Bash 5.2.15 rather than 5.0 and Ruby 3.2 rather than 3.3 -- so this may invalidate my "cannot reproduce". However, I encourage you to try using my branch and see if the issue persists.
Test results:
$ for i in {1..10}; do printf 1>&2 -- '# %s\n' "$i"; \rm -rf ./coverage; bundle exec bashcov --bash-path "$(type -P bash)" ./tests/tests.sh |& grep '^Coverage report generated'; done
# 1
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 2
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 3
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 4
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 5
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 6
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 7
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 8
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 9
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
# 10
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage/coverage.xml. 960 / 1407 LOC (68.23%) covered
Coverage report generated for /run/current-system/sw/bin/bash ./tests/tests.sh to /home/matt/src/github.com/Minituff/nautical-backup/coverage. 960 / 1407 LOC (68.23%) covered.
Hey @tomeon, thank you for putting in so much work to help me out with this.
I think I may have figured it out.
I am using WSL2 (Ubuntu 20.04) on my Windows 11 PC so I tried booting up a Ubuntu VM.
This is leading my to believe the issue is with WSL2. In retrospect, it might have been a little crazy of me to develop a Bash project on Windows.....
I can move my development and tests to full Ubuntu and that should mitigate the problem. I can leave the GitHub issue open if you want to try to figure out why WSL2 is having these issues.
@Minituff
In retrospect, it might have been a little crazy of me to develop a Bash project on Windows.....
Not terribly crazier than developing a Bash project, full stop :stuck_out_tongue_winking_eye:
Would be interesting to know whether the list of files with coverage stats changes between runs. If you've got jq
available, this command will show you the names of files with coverage data:
matt@srv1 ~/.../Minituff/nautical-backup :) $ jq --raw-output '.[].coverage | keys[]' < ./coverage/.resultset.json
/path/to/Minituff/nautical-backup/pkg/backup.sh
/path/to/Minituff/nautical-backup/pkg/entry.sh
/path/to/Minituff/nautical-backup/pkg/env.sh
/path/to/Minituff/nautical-backup/pkg/logger.sh
/path/to/Minituff/nautical-backup/pkg/test.sh
/path/to/Minituff/nautical-backup/pkg/utils.sh
/path/to/Minituff/nautical-backup/snippets/docker-run-semver-example.sh
/path/to/Minituff/nautical-backup/snippets/docker-run-semver-major-example.sh
/path/to/Minituff/nautical-backup/tests/tests.sh
/path/to/Minituff/nautical-backup/tests/validate_dockerfile.sh
Ha very true, its too late to turn back now 😜.
Looks like the tested files are the same each time.
I did have to modify your .simplecov
because I could not get Ruby to recognize my ENV variable.
# .simplecov
SimpleCov.profiles.define 'bashcov' do
load_profile 'rails'
command_name 'Unit Tests'
enable_coverage :branch
primary_coverage :branch
add_filter %r{^/snippets/}
add_filter %r{^/.git/}
add_filter %r{^/tests/}
add_filter "pkg/test.sh"
add_group "Pkg scripts", "/pkg"
# simplecov 0.22.0+
enable_coverage_for_eval if respond_to? :enable_coverage_for_eval
end
# Conditional loading of profiles
if ENV.key? 'SKIP_PROFILE'
puts "Skipping bashcov profile..."
else
puts "Loading bashcov configurations..."
SimpleCov.load_profile 'bashcov'
end
Coverage report generated for /bin/bash tests/tests.sh to /mnt/c/Users/James-PC/IdeaProjects/nautical-backup/coverage/coverage.xml. 0 / 385 LOC (0.00%) covered; 0 / 0 BC (100.00%) covered
Coverage report generated for /bin/bash tests/tests.sh to /mnt/c/Users/James-PC/IdeaProjects/nautical-backup/coverage. 0 / 385 LOC (0.0%) covered.
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/backup.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/entry.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/env.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/logger.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/utils.sh
Coverage report generated for /bin/bash tests/tests.sh to /mnt/c/Users/James-PC/IdeaProjects/nautical-backup/coverage/coverage.xml. 256 / 402 LOC (63.68%) covered; 0 / 0 BC (100.00%) covered
Coverage report generated for /bin/bash tests/tests.sh to /mnt/c/Users/James-PC/IdeaProjects/nautical-backup/coverage. 256 / 402 LOC (63.68%) covered.
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/backup.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/entry.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/env.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/logger.sh
/mnt/c/Users/James-PC/IdeaProjects/nautical-backup/pkg/utils.sh
@Minituff -- the BASHCOV_COMMAND_NAME
environment variable is set by Bashcov itself, so should activate the bashcov
profile when Bashcov is running (and only when Bashcov is running, unless something else sets it for some reason?).
I don't have a WSL2 environment to investigate this on, but perhaps you could try running Bashcov without a .simplecov
in place? This could help isolate the source of the issue. You could also check whether you see coverage data fluctuations when using other shell coverage tools (e.g. kcov
). Finally, you could try saving the coverage data from one run (e.g., mv coverage{,.last}
), re-run Bashcov, and then diff the results (e.g. diff coverage{,.last}/.resultset.json
).
Hey @infertux I got there debugging values and repo at there
BASHCOV>fa26f0a5-fe3f-465c-96ee-a0600be01651573fa26f0a5-fe3f-465c-96ee-a0600be01651./bash_unitfa26exit 0
+ bashcov: warning: encountered an error parsing Bash's output (error was: expected integer for LINENO, got "uname -m\n_source/bash/release-me/release.sh"). This can occur if your script or its path contains the sequence "fa26f0a5-fe3f-465c-96ee-a0600be01651", or if your script unsets LINENO. Aborting early; coverage report will be incomplete.
Run completed using bashcov 3.1.2 with Bash 3.2, Ruby 3.3.1, and SimpleCov 0.22.0
Coverage report generated for /bin/bash ./bash_unit tests/cli/core.test.sh tests/cli/no-git.test.sh tests/gpg-sign/git-gpg-sign.test.sh tests/plugins/changelog.test.sh tests/plugins/docker.test.sh tests/plugins/git.test.sh tests/plugins/github-release.test.sh tests/plugins/npm-post.test.sh tests/plugins/npm.test.sh tests/plugins/template.test.sh tests/presets/conventional-commits.test.sh tests/presets/workspace.cargo-undefined.test.sh tests/presets/workspace.cargo.test.sh tests/presets/workspace.nodejs-undefined.test.sh tests/presets/workspace.nodejs.test.sh tests/presets/workspace.python-undefined.test.sh tests/presets/workspace.python.test.sh tests/presets/workspace.undefined.test.sh to /Users/dalisoft/Desktop/open_source/bash/release-me/coverage. 307 / 548 LOC (56.02%) covered.
Repo lives at here and i'm running command via env (cat .env.test) bundle exec bashcov ./bash_unit tests/**.test.sh
locally
Hello,
I'm new to using Ruby so I apologized if this is a simple question, but every time I run my tests my
coverage\index.html
is giving me a different output.The strange thing is, the output is correct and consistent within my Github Actions pipeline.
My `.simplecov` file
```ruby require 'simplecov' require 'simplecov-cobertura' require "simplecov-html" # frozen_string_literal: true # SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter # Converts the `.resultset.json` to `coverage.xml` # SimpleCov::Formatter::JSONFormatter, # This formatter breaks the build # Use multiple formatters SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov::Formatter::SimpleFormatter, SimpleCov::Formatter::CoberturaFormatter, SimpleCov::Formatter::HTMLFormatter, ]) # .simplecov SimpleCov.start 'rails' do command_name 'Unit Tests' enable_coverage :branch primary_coverage :branch add_filter %r{^/snippets/} add_filter %r{^/.git/} add_filter %r{^/tests/} add_filter "pkg/test.sh" add_group "Pkg scripts", "/pkg" enable_coverage_for_eval # Must be at the bottom and Must be here, even though it throws a 'command not found' error end ```Here is the relevant part of my Gitlab CI workflow
```yml - uses: ruby/setup-ruby@v1 with: ruby-version: head - name: Install Ruby dependencies run: | gem install bashcov simplecov-cobertura simplecov-html - name: Run unit tests run: bashcov ./tests/tests.sh && ls -la coverage - name: Upload reports to Codecov uses: codecov/codecov-action@v4-beta # uses: codecov/codecov-action@v3 env: # Required for v4 CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: fail_ci_if_error: true files: coverage/coverage.xml # The json file will not work here ```This is the output when I run the tests locally changes each time, but ranges from 50-65%
This is the output generated from my testing pipeline. It's always accurate and consistent (~90%)
Are you able to help me determine why the coverage is not the same when run codecov locally?
How to replicate the issue
git clone git@github.com:Minituff/nautical-backup.git
gem install bashcov simplecov-cobertura simplecov-html
bashcov ./tests/tests.sh && ls -la coverage
My repo is open source so feel free to look around if I did not include something https://github.com/Minituff/nautical-backup
Thanks!