简体   繁体   中英

Where to start modifying BashCov to implement --exclude option?

Context

While trying to build a/the --exclude / --ignore option to bashcov I am experiencing some difficulties in determining where to start.

Bashcov does not support the --exclude / --ignore option yet, as can be seen from the following output to: bashcov --help :

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

Motivation

Bashcov includes non-project related files and folders such as the .git folder, and the bats unit test modules in test/libs . This makes it difficult to understand how well the project code itself is actually tested:

在此处输入图像描述 For example, the above report shows a 17% coverage, even though of 100% of the custom project bash code lines are tested.

Options

  1. Bashcov relies on simplecov, so if I could modify bashcov to pass the bashcov --exclude / --ignore commands to simplecov, that may be sufficient. I found the bashcov arguments are parsed here .
  2. If Bashcov compiles the list of files to be checked itself, I could modify bashcov to only include those files if they are not within the --exclude / --ignore directories/list. However, I do not yet know whether bashcov does this and if yes where, or whether it relies on simplecov to do that.

Details Option II:

I found this answer that shows how the SimpleCov.start line can be modified to add a filter/exclude list. In bashcov, that SimpleCov.start line can be found here , however I do not yet know how to compile, build and install bashcov locally (without getting the default version from `sudo apt install bashcov on Ubuntu 22.10).

Question

What would be a practical place to start modifying bashcov to build the --exclude / --ignore function?

It is not needed to modify bashcov. The --exclude / --ignore option is supported through a SimpleCov configuration file. In the root directory of one's own project, one can add a .simplecov file with content:

SimpleCov.start do
  minimum_coverage 15
  add_filter "test/libs"
  add_filter "/.git/"
end

And that ensures the coverage report and result ignore those test/libs/ and .git/ directories.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM