infertux / bashcov Goto Github PK
View Code? Open in Web Editor NEWCode coverage tool for Bash
License: MIT License
Code coverage tool for Bash
License: MIT License
Hi,
The simplecov
version is set to 0.15.1
in bashcov
1.8.2
. I'd like to use a more recent version. Are you planning a new release with the dependencies updates?
This snippet should have 100% coverage
#!/usr/bin/env bash
function this_command_runs {
true
}
function main {
# awk script -> it just a long string passed to the awk.
# Both the command and arguments should could as covered.
awk -F, 'NR==1{
print("Some long script")
}
NR > 1 {
print("And script continues")
}' /dev/null
# multiline array specification
local some_array=( "Some" "values" "${and[@]}"
"${many}" other $(echo 123)
)
local some_array=(
"Some" "values" "${and[@]}"
"${many}" other $(echo 123)
)
declare -A some_hashmap=(
[A]="aaa"
[B]="bbb"
[C]="..."
)
##### multiline with && and ||
true line 1 \
line 2 \
line 3
true line 1 \
"$(true && echo line 2)" \
line 3
true line 1 \
"$(false || echo line 2)" \
line 3
##### multiline with redirect and boolean operator
false line 1 \
line 2 2> >(cat) || this_command_runs
false line 1 \
line 2 2> >(cat) || \
this_command_runs
true line 1 \
line 2 2> >(cat) && this_command_runs
true line 1 \
line 2 2> >(cat) && \
this_command_runs
##### A for loop in multiple lines
for ((k = 1;
k <= 2;
k++));
do
true
done
echo "This test case should have 100% line coverage"
exit 0
}
main "$@"
Instead I'm getting 60%.
Using bashcov 1.8.2.
Thank you.
Hello,
We maintain a shell 'standard library' that we use across our projects: https://github.com/sdelements/shtdlib/blob/master/shtdlib.sh
If a script sources shtdlib.sh
, would it be possible to use bashcov
to determine which functions of shtdlib.sh
were used and export/write those functions to a file?
E.g. the script below would generate a smaller file that only contains the debug
, assert
and color_echo
(called from debug
and assert
) functions.
# Import the shell standard library
source /bin/shtdlib.sh
debug 10 "Running as ${UID:-$(id -u)}"
assert test -d "${script_dir}/build"
assert test -d "${script_dir}/dist"
When trying to install this on Red Hat's UBI8 container image I get the following error. What am I missing for the install?
#5 11.47 Successfully installed docile-1.1.5
#5 11.47 Successfully installed simplecov-html-0.10.2
#5 11.47 Building native extensions. This could take a while...
#5 11.55 ERROR: Error installing bashcov:
#5 11.55 ERROR: Failed to build gem native extension.
I'm using this Dockerfile:
ARG BASE_REGISTRY=registry.access.redhat.com
ARG BASE_IMAGE=ubi8/ubi
ARG BASE_TAG=8.3
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG}
ENV VERSION="1.8.2"
RUN yum -y install ruby ruby-devel make gcc && \
gem install bashcov --version ${VERSION} --no-format-exec && \
adduser bashcov -D -h /app
ENV PS4="+%N:%i>"
WORKDIR /app
CMD ["bashcov", "--help"]
Hi,
I have a bit of an odd setup for my test suite.
We use a combination of Python and Bash for our project (probably 70-80% bash scripts right now).
We are building a unit test suite retrospectively and I was looking for a tool to show us where the gaps are in our testing.
We started to build the test suite on Python as we felt it offered more features. So we have test classes that call bash scripts and check the stdout and stderr. They are run using the standard...
python -m unittest discover -s test -p '*_test.py'
This call is in a bash script called "runTests.sh" and we call it using "bashcov ./runTests.sh".
This produces a report which includes all the bash scripts even if they aren't touched by a test (which is great!). However, what seems to be happening is the results are getting nobbled as the tests progress. The only data in the report is generally the last test that ran. The coverage stats for all the other test (which have run) is 0.
Do you know if there is a way to get this working?
Thanks!
BASH_VERSION
is computed before taking into account the --bash-path
argument, meaning that the bash version will be detected based on /bin/bash
rather than the path passed in.
As an example use case, I'm trying to get coverage working on macOS while not clobbering stderr
; I installed Bash 5 via Homebrew, but bashcov
still thinks I'm using the system version even when I pass the --bash-path
argument in.
I tried to patch in a workaround, but I'm pretty much brand new to ruby and was still seeing some "instrumentation" output (though not all) print to stderr
; I'll continue to work on it a little, but any pointers you might have would be helpful.
$ bats tests
✓ errors without arguments
✓ correctly initializes a loop
✓ correctly stops a loop
✓ correctly pauses a loop
✓ correctly resumes a loop
✓ a just initialized loop is alive
✓ can't initialize an already existing loop
✓ can't stop a dead loop
✓ can't pause a dead loop
✓ can't resume a dead loop
✓ pausing a paused loop has no effect
✓ resuming an alive loop has no effect
✓ control returns 1 with dead loop
✓ control correctly breaks a loop
✓ control lets loop run when alive
15 tests, 0 failures
$ bashcov bats tests
/home/pawamoy/.basher/cellar/bin/bats: line 44: /media/Data/git/shellm/libexec/bats-core/bats: No such file or directory
Run completed using bashcov 1.8.2 with Bash 4.4, Ruby 2.5.3, and SimpleCov 0.15.1.
Coverage report generated for /bin/bash bats tests to /media/Data/git/shellm/loop/coverage. 0 / 267 LOC (0.0%) covered.
Am I using bashcov correctly? bashcov bats tests
env: line 93: SHELLOPTS: readonly variable
env: line 93: SHELLOPTS: readonly variable
env: line 93: SHELLOPTS: readonly variable
#<Thread:0x00005572d91039d8@/hpc/aa30891/gems/gems/bashcov-1.8.2/lib/bashcov/runner.rb:42 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
4: from /hpc/aa30891/gems/gems/bashcov-1.8.2/lib/bashcov/runner.rb:42:in block (2 levels) in run' 3: from /hpc/aa30891/gems/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:94:in
read'
2: from /hpc/aa30891/gems/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:94:in loop' 1: from /hpc/aa30891/gems/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:96:in
block in read'
/hpc/aa30891/gems/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:121:in `parse_hit!': expected integer for LINENO, got "${LINENO-}" (Bashcov::XtraceError)
the latest release no longer finds any coverage on scripts at all. If this is a change in setup needed that needs to be documented:
repo steps on macos with Run completed using bashcov 3.0.2 with Bash 3.2, Ruby 3.0.0, and SimpleCov 0.21.2
:
hello.sh:
#!/bin/bash
echo "hello"
bash-3.2$ bashcov hello.sh
+BASHCOV>4a74ab0b-0f09-46b7-b474-2fc705aaea0024a74ab0b-0f09-46b7-b474-2fc705aaea00hello.sh4a74ab0b-set -x
+BASHCOV>4a74ab0b-0f09-46b7-b474-2fc705aaea0034a74ab0b-0f09-46b7-b474-2fc705aaea00hello.sh4a74ab0b-echo hello
hello
Run completed using bashcov 3.0.2 with Bash 3.2, Ruby 3.0.0, and SimpleCov 0.21.2
Coverage report generated for /bin/bash hello.sh to /Users/joehale/projects/hel/coverage. 0 / 2 LOC (0.0%) covered.
Previous versions would return 100% coverage
I'm assuming here that --mute
was added to suppress the output from scripts under coverage
bashcov generates some output of its own, like the "Run completed using ..." at the end of its execution. There is no bashcov switch to suppress such output (amongst others)
Scenario:
This would be useful in tests which execute shell script and verify stdout/stderr. The script-under-test's invocation could be prefixed with bashcov with a suppress switch; thus gathering coverage without breaking any existing stdout/stderr based validation.
Consider these scripts:
cat > child.sh <<'EOF'
#!/bin/bash
echo $unset
echo "Survived!"
EOF
cat > parent.sh <<'EOF'
#!/bin/bash
set -eu
./child.sh
EOF
chmod +x parent.sh child.sh
The behavior is different depending on whether the script is run under bashcov or not:
$ ./parent.sh
Survived!
$ bashcov ./parent.sh
./child.sh: line 3: unset: unbound variable
Run completed using bashcov 1.8.2 with Bash 5.0, Ruby 2.6.2, and SimpleCov 0.15.1.
Coverage report generated for /bin/bash ./parent.sh to /home/vladimir/tmp/2019-04-04-scratch/04:43:13/coverage. 2 / 4 LOC (50.0%) covered.
Version: 1.6.0
Steps that will reproduce the problem?
git clone https://github.com/alexanderwillner/things.sh
cd things.sh
THINGSDB=test/Things.sqlite3 bashcov ./things.sh today
coverage/index.html
What is the expected result?
Coverage around a few percent.
What happens instead?
Coverage of 81.09%
Possible workaround:
Unknown.
Any additional information:
Needs sqlite
. Only tested on macOS.
Hello,
I am running bash unit (https://github.com/pgrange/bash_unit/blob/master/bash_unit) v1.6.1 script to run tests. Those tests are calling functions from a bash script previously sourced in the environment.
I cannot get any coverage on the sourced bash script functions. Is it currently possible with bashcov ?
variable=($(
echo hi
))
echo after
Reported coverage is [nil, 0, 1, 2]
. It should be [nil, 1, 1, 1]
.
This seems to be a bug in Bash?
See the pending spec in spec/bashcov/runner_spec.rb
.
Passing an empty file to bashcov causes it to crash with an exception:
~/tmp/2018-12-29b » bashcov /dev/null
#<Thread:0x000055b65717d1e0@/home/vladimir/.gem/ruby/2.5.0/gems/bashcov-1.8.0/lib/bashcov/runner.rb:42 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
4: from /home/vladimir/.gem/ruby/2.5.0/gems/bashcov-1.8.0/lib/bashcov/runner.rb:42:in `block (2 levels) in run'
3: from /home/vladimir/.gem/ruby/2.5.0/gems/bashcov-1.8.0/lib/bashcov/xtrace.rb:94:in `read'
2: from /home/vladimir/.gem/ruby/2.5.0/gems/bashcov-1.8.0/lib/bashcov/xtrace.rb:94:in `loop'
1: from /home/vladimir/.gem/ruby/2.5.0/gems/bashcov-1.8.0/lib/bashcov/xtrace.rb:96:in `block in read'
/home/vladimir/.gem/ruby/2.5.0/gems/bashcov-1.8.0/lib/bashcov/xtrace.rb:121:in `parse_hit!': expected integer for LINENO, got "" (Bashcov::XtraceError)
bashcov: warning: encountered an error parsing Bash's output (error was: expected integer for LINENO, got ""). This can occur if your script or its path contains the sequence "67f53df5-ad00-4ad7-879f-e8a986e1c478", or if your script unsets LINENO. Aborting early; coverage report will be incomplete.
Run completed using bashcov 1.8.0 with Bash 4.4, Ruby 2.5.3, and SimpleCov 0.15.1.
Coverage report generated for /bin/bash /dev/null to /home/vladimir/tmp/2018-12-29b/coverage. 0.0 / 0.0 LOC (100.0%) covered.
Hi, I'm using bashcov to cover https://github.com/albfan/git-ignore
Problem with git-ignore is it is launched by git when you issue "git ignore". By now I hack this with
https://github.com/albfan/git-ignore/blob/master/t/setup.sh#L7
where COV_PROGRAM is "bashcov --"
That works but would be great to find a way that bashcov replaces /bin/sh to avoid extra config for code coverage.
https://github.com/albfan/git-ignore/blob/master/t/t0001-exclude.sh#L3
something like:
SHARNESS_TEST_EXTENSION="bashcov"
When Bash runs under set -o nounset
/set -u
, attempts to expand unset variables in non-interactive shells are considered fatal errors. Under some circumstances, one or more of the environment variables in Bashcov's PS4
can be unset, causing Bash to exit when it tries to expand the PS4
. This is particularly common with OLDPWD
, which is only set when there's been at least one change of directory.
The solution for this is simple -- use th ${MYVAR-}
parameter expansion construct to expand the PS4
variables to empty strings when they are unset. Fix will be in shortly 😄.
bashcov
produces output like this at the end of a run:
Run completed using bashcov 1.8.2 with Bash 4.4, Ruby 2.5.1, and SimpleCov 0.15.1.
Coverage report generated for /bin/bash script.sh ... etc ...
This output is sent to standard output which contaminates the output of the user's script and makes it difficult to use bashcov as part of a test harness. As the above output is not diagnostic in nature (that could be sent to standard error), I suggest that this output is suppressed by default but can be enabled with a -v
/--verbose
option.
.
Hi, first of all thanks for this great tool! :)
I noticed case statements don't get reported by simplecov.
For example this simple script:
#!/bin/bash
arg=$1
case $arg in
0)
echo "arg was 0"
;;
1)
echo "arg was 1"
;;
esac
bashcov -- ./script.sh 0
bashcov: warning: you are using a version of Bash that does not support BASH_XTRACEFD. All xtrace output will print to standard error, and your script's output on standard error will not be printed to the console.
arg was 0
Coverage report generated for bashcov v1.3.1 to /Users/simone/Projects/bashcov-switch-bug/coverage. 3 / 6 LOC (50.0%) covered.
As you can see, line 6 was missed.
I'm on OS X 10.11.6.
For the same simple test script, bashcov runs fine on my PC, but crashes inside a minimal container.
Here is the Dockerfile + script which reproduces the problem:
https://gist.github.com/CyberShadow/79422aea8ee896378785c273b56ec07c
(run docker build -t bashcov . && docker run bashcov
to reproduce).
Here is the output:
+ bashcov test.sh
Hello
#<Thread:0x0000561f4f35b708@/var/lib/gems/2.5.0/gems/bashcov-1.8.2/lib/bashcov/runner.rb:42 run> terminated with exception (report_on_exception is true):
/var/lib/gems/2.5.0/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:121:in `parse_hit!': expected integer for LINENO, got "" (Bashcov::XtraceError)
from /var/lib/gems/2.5.0/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:96:in `block in read'
from /var/lib/gems/2.5.0/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:94:in `loop'
from /var/lib/gems/2.5.0/gems/bashcov-1.8.2/lib/bashcov/xtrace.rb:94:in `read'
from /var/lib/gems/2.5.0/gems/bashcov-1.8.2/lib/bashcov/runner.rb:42:in `block (2 levels) in run'
bashcov: warning: encountered an error parsing Bash's output (error was: expected integer for LINENO, got ""). This can occur if your script or its path contains the sequence "\u001E", or if your script unsets LINENO. Aborting early; coverage report will be incomplete.
Run completed using bashcov 1.8.2 with Bash 4.4, Ruby 2.5.1, and SimpleCov 0.15.1.
Coverage report generated for /bin/bash test.sh to /root/covtest/coverage. 0 / 1 LOC (0.0%) covered.
Any hints on how to narrow this down?
Similar to #48, I get the following output:
$ bashcov -s /usr/local/bin/bats tests
bashcov: warning: you are using a version of Bash that does not support BASH_XTRACEFD. All xtrace output will print to standard error, and your script's output on standard error will not be printed to the console.
✓ test something
1 test, 0 failures
bashcov: warning: /private/var/folders/15/3v34mvyj0xl17rhb89m70px00000gn/T/bats.13239.src was executed but has been deleted since then - it won't be reported in coverage.
Run completed using bashcov 1.8.2 with Bash 3.2, Ruby 2.6.0, and SimpleCov 0.15.1.
Coverage report generated for /bin/bash /usr/local/bin/bats tests to /private/tmp/tmp/coverage. 0.0 / 0.0 LOC (100.0%) covered.
Notice the last bit of the last line: 0.0 / 0.0 LOC (100.0%) covered
. I tried running this from an absolute bats
location, to avoid #48, but I get 0% coverage. It looks like BATS is running properly, but bashcov is not tracing any of the files.
Now if I run the command without BATS, i.e. bashcov -s ./hello.sh 1
, then it works great and I get an accurate coverage metric. My testing is solely BATS, and don't think it should be necessary to write another script file to run the BATS tests (even tried that, and it's still not working 100% as I'd expect it to).
Please help!
when running bashcov with shunit2 test case, i got "bashcov: warning: encountered an error parsing Bash's output (error was: expected integer for LINENO, got ""). This can occur if your script or its path contains the sequence "\u001E", or if your script unsets LINENO. Aborting early; coverage report will be incomplete.
Coverage report generated for bashcov 1.6.0 (bash 4.3) to /home/XXXX/installation/unit-test/coverage. 0 / 986 LOC (0.0%) covered."
Could someone here help on this ?
http://semver.org/ when it is solid enough.
bashcov
's test suite fails on OS X.
It appears that the reason for this three fold:
BASH_SOURCE
isn't always guaranteed to give an absolute path. It gives a relative path for our test cases on OS X.find -executable
is GNU specificI'm using bashcov on a project and have nearly 100% coverage. The only lines not reported as covered of known executed code are the function names. After running unit-tests (using shunit2) with bashcov and the report generated, the following line is output:
Run completed using bashcov 1.8.2 with Bash 5.1, Ruby 3.1.2, and SimpleCov 0.15.1.
The HTML report specifies the following:
Generated by simplecov v0.15.1 and simplecov-html v0.10.2
I'm not sure if this is an issue with bashcov or simplecov, I have a strong suspicion that the issue involves the characters used in the function names; though the characters are valid in BASH. Bellow are examples of the function names that aren't registering as covered:
ansi::es() {
# ...
}
ansi::nc() {
# ...
}
Though, when modifying the function definitions to use the function
keyword as below:
function ansi::es {
# ...
}
function ansi::nc() {
# ...
}
The definition lines are not listed as missed, just as the other functions not named with colons.
As there is a workaround with the naming in this format, this is not a show-stopper, but this is an issue that should be corrected.
Hi, I'm looking for a tool to test a rather large sh script (it's around a 1000 lines atm). I have one main script for which I want to generate coverage (preferably also for the large command strings that are passed to xargs
to get around read
not supporting \0
-separation in most implementations), but I also have a collection of test scripts also written in sh
.
Does bashcov have support for pure sh
scripts? Would you recommend I use bashcov for this?
#!/bin/bash
echo foo
exec 9>/tmp/exec
echo bar
rm /tmp/exec
The last two lines will be marked as missed even though they do run. However I'm unable to write a test case for it as all lines are hit when I use Rspec or Cucumber. It seems the test framework is having some weird side effect :|
Hi,
My current script starts like this:
declare -x PS4='+ ${FUNCNAME[0]:+${FUNCNAME[0]}() }'
PS4+='${FUNCNAME[0]:-(${BASH_SOURCE[0]}:${BASH_LINENO[0]}) }'
So bashcov seems a bit confused ...
By injecting the bashcov version variable in the tested environment this issue can be avoided.
if [[ -z "${__bashcov_version__}" ]]; then
declare -x PS4='+ ${FUNCNAME[0]:+${FUNCNAME[0]}() }'
PS4+='${FUNCNAME[0]:-(${BASH_SOURCE[0]}:${BASH_LINENO[0]}) }'
fi
I did it in my script before calling bashcov and it works, however maybe your code is a better place. ;-)
declare -x __bashcov_version__
__bashcov_version__="$(bashcov --version)"
bashcov -- "./tools/bash_unit" "${test_files_lst[@]}" || retval=${?}
Thank's for your amazing work.
Best regards,
bashcov ./simple.sh
Coverage report generated for bashcov 1.6.0 (with Bash 4.4, Ruby 2.4.3, and SimpleCov 0.15.1) to /home/infertux/dev/bashcov/coverage. 1 / 649 LOC (0.15%) covered.
Coverage report generated for bashcov 1.6.0 (with Bash 4.4, Ruby 2.4.3, and SimpleCov 0.15.1) to /home/infertux/dev/bashcov/coverage. 0.0 / 0.0 LOC (100.0%) covered.
Second coverage has 0 LOC and overwrites the actual coverage.
Seems related to simplecov-ruby/simplecov#581
Hello there!
My name is Ana. I noted that you use the mutation testing tool mutant in the project.
I am a postdoctoral researcher at the University of Seville (Spain), and my colleagues and I are studying how mutation testing tools are used in practice. With this aim in mind, we have analysed over 3,500 public GitHub repositories using mutation testing tools, including yours! This work has recently been published in a journal paper available at https://link.springer.com/content/pdf/10.1007/s10664-022-10177-8.pdf.
To complete this study, we are asking for your help to understand better how mutation testing is used in practice, please! We would be extremely grateful if you could contribute to this study by answering a brief survey of 21 simple questions (no more than 6 minutes). This is the link to the questionnaire https://forms.gle/FvXNrimWAsJYC1zB9.
Drop me an e-mail if you have any questions or comments ([email protected]). Thank you very much in advance!!
I'm currently using shunit2 for unit testing my scripts. Some of my scripts are quite length. I'd like to use bashcov to generate code coverage data. When I call bashcov on my unit test script, there a lot of output from bashcov, that I can't see what shunit2 is reporting. Questions are:
Hi,
First let me say thank you very much for this project. I didn't expect to find anything that would provide coverage for Bash.
I am working on a project that has a lot of legacy Bash scripts and very few tests. We want to be able wrap these scripts with 'black box' functional tests written in Ruby. In short, each RSpec example sets up some state then calls the described Bash script and subsequently makes assertions. Ruby invokes the test subject using Bashcov.
Therefore, as RSpec is in charge of running all tests and each test delegates to Bashcov, this means that coverage is essentially measured cumulatively. This wouldn't be a problem, however Bashcov's behaviour is to regenerate the coverage report after each invocation which results in the loss of anything that was previously captured.
Therefore...
I would like to be able to run Bashcov in a manner similar to:
bashcov -a ./my_bash_script.sh
or
bashcov --append-results ./my_bash_script.sh
This is doable and for now I have rigged up a solution which essentially provides an alternative to bin/bashcov. This:
SimpleCov::ResultMerger
instead of SimpleCov::Result
to write the resultsIf you think that this feature would be useful, I would be happy to refine how it should work via a discussion in this ticket and submit a pull request with a proper implementation. That is as long as it's not to much work :)
Let me know your thoughts and thanks again.
I just installed bashcov using 'gem install bashcov' and get an error when running 'bashcov --help':
[root@watson golharr]# bashcov --help
/usr/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:55:in gem_original_require': /usr/lib64/ruby/gems/1.8/gems/bashcov-1.3.0/lib/bashcov.rb:17: unknown type of %string (SyntaxError) *%i(skip_uncovered mute bash_path root_directory command) ^ /usr/lib64/ruby/gems/1.8/gems/bashcov-1.3.0/lib/bashcov.rb:17: syntax error, unexpected $end *%i(skip_uncovered mute bash_path root_directory command) ^ from /usr/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:55:in
require'
from /usr/lib64/ruby/gems/1.8/gems/bashcov-1.3.0/bin/bashcov:7
from /usr/bin/bashcov:22:in `load'
from /usr/bin/bashcov:22
Thank you for your work on this project! While trying to run Bashcov on a basic BATS testing repo in a .GitLab-CI.yml
:
image: vergissberlin/alpine-development
stages:
- build
- deploy
test:
stage: build
image: ruby:slim
before_script:
- gem install bashcov
script:
# bashcov cannot run as root so here's a magic user
- useradd -s /bin/bash user
- su user -c "$(command -v bashcov) test"
coverage: '/\(\d+\.\d+%\) covered/'
artifacts:
untracked: true
I receive the error:
bashcov: warning: encountered an error parsing Bash's output (error was: expected integer for LINENO, got ""). This can occur if your script or its path contains the sequence "010ae148-b419-4384-b227-69b97f25cdb6", or if your script unsets LINENO. Aborting early; coverage report will be incomplete.
So after scanning the tested repo I noticed the bats installation packages at: test/libs/bats/*
contain the $lineno
variable.
So I thought I would perhaps be able to circumvent this error by adding the test/libs/bats/*
dir to the ignored folders when I run bashcov
with:
bashcov bats test
However, after inspecting the documentation:
bashcov --help
Usage: bashcov [options] [--] <command> [options]
Examples:
bashcov ./script.sh
bashcov --skip-uncovered ./script.sh
bashcov -- ./script.sh --some --flags
bashcov --skip-uncovered -- ./script.sh --some --flags
Specific options:
-s, --skip-uncovered Do not report uncovered files
-m, --mute Do not print script output
--bash-path PATH Path to Bash executable
--root PATH Project root directory
--command-name NAME Value to use as SimpleCov.command_name
Common options:
-h, --help Show this message
--version Show version
I did not find an option to ignore certain folders. Hence, I would like to ask:
How can I specify ignored folders and files when running bashcov bats test
?
Hello,
I've just upgraded to the latest (1.5.1) and I'm getting "invalid byte sequence in UTF-8 (ArgumentError)" when running bashcov against a very large legacy project. I don't think I saw that error when using version 1.2.1. With that version, I had 18 files listed in the coverage report and now I have only 7.
When all tests have been run, I see the following:
/home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:65:in `match': invalid byte sequence in UTF-8 (ArgumentError)
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:65:in `match'
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:65:in `mark_multiline'
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:37:in `block in complete_coverage'
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:35:in `each'
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:35:in `each_with_index'
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:35:in `complete_coverage'
from /home/aclark/workspace/bashcov/lib/bashcov/runner.rb:149:in `block in mark_relevant_lines!'
from /home/aclark/workspace/bashcov/lib/bashcov/runner.rb:147:in `each_pair'
from /home/aclark/workspace/bashcov/lib/bashcov/runner.rb:147:in `mark_relevant_lines!'
from /home/aclark/workspace/bashcov/lib/bashcov/runner.rb:68:in `result'
from /home/aclark/workspace/bashcov/bin/bashcov:13:in `<main>'
and, when handling the exception in mark_multiline
,
/home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:87:in `sub!': invalid byte sequence in UTF-8 (ArgumentError)
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:87:in `relevant?'
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:83:in `mark_line'
from /home/aclark/workspace/bashcov/lib/bashcov/lexer.rb:57:in `block in complete_coverage'
[...]
This code is likely riddled with invalid characters vis-a-vis UTF-8.
Anyone have any ideas how to get around this and report the true coverage? If it matters, I'm running bashcov 1.5.1 on Cygwin/Windows 8.1. Thanks in advance!
Right now, Bashcov detects shell scripts by searching the project root for files ending with the extension .sh
. There are a couple of gems that interface with libmagic to provide MIME type identification of files based on reading some of their contents. While it wouldn't be nice to mandate the use of one or the other of those gems, we could selectively load them if present on the user's system, falling back to extension-based detection when neither gem is available. What do you think, @infertux -- worth the effort?
The build is failing with SimpleCov 0.16+. The coverage is now empty when using SimpleCov::ResultMerger.results. I couldn't figure out why at first glance but it must be due to a change in this diff.
This seems to only affect feature tests and normal usage of Bashcov is working for me with SimpleCov 0.16.1.
We're currently parsing multiline strings using horrible regexpes. I'd like to keep lexer.rb
simple but it might be worth using Bison and the BNF definition of the Bash grammar next time we run into a regexp issue...
Send PR after 2.0 release.
I see that #34 was merged, so, I understand that it should be possible to merge multiple coverage runs. However, I don't understand how to actually achieve this, and don't see any documentation which explains it.
Would it be possible to document the steps necessary in order to:
Thanks!
Bash specific syntax is not supported in covered scripts, for instance, process substitution, e.g. echo "data" > >(my_function))
The reason for this is that bash's argv[0]
is not "bash", but instead the environment variables prepended to it. This causes bash to drop back to sh-compatible mode.
I would like to be able to run bashcov
over several testsuites simultaneously. Does it handle writing out the end-of-run data files safely if there are multiple instances running?
Hello there,
just following up from #23. This simple script doesn't seem to be reported correctly:
#!/bin/bash
synopsis='
Usage: fubar <PATH> [OPTIONS]
Some description.
Options:
-h --help Prints help information
'
echo "$synopsis"
I have used vim on code coverage
https://github.com/vim/vim/blob/master/.travis.yml#L39
How is supposed bashcov to generate report? Is there any working example?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.