Skip to content

kcov and bash_unit doesn't play well out of the box #137

@jbergstroem

Description

@jbergstroem

I'm trying to add coverage to hadolint-gh-action and the most output friendly tool seems to be kcov. It does not work very well out of the box though. It only shows the coverage paths through bash_unit and not the test files themselves:

kcov coverage bash_unit test/e2e.sh test/unit.sh
Running tests in test/e2e.sh
test_bash_glob_expansion
test_ci_vs_non_ci_annotation_behavior
test_ci_vs_non_ci_hadolint_version_output
test_custom_config
test_custom_dockerfile_path
test_custom_hadolint_path
test_custom_output_format
test_default_hadolint_config
test_default_path
test_default_path_with_dockerfile
test_disable_annotate
test_multiple_dockerfiles
test_output_with_nonzero_exit
test_override_errorlevel
test_version_output ]]
        Running test_annotate ... SUCCESS
        Running test_bash_glob_expansion ... SUCCESS
        Running test_ci_vs_non_ci_annotation_behavior ... SUCCESS
        Running test_ci_vs_non_ci_hadolint_version_output ... SUCCESS
        Running test_custom_config ... SUCCESS
        Running test_custom_dockerfile_path ... SUCCESS
        Running test_custom_hadolint_path ... SUCCESS
        Running test_custom_output_format ... SUCCESS
        Running test_default_hadolint_config ... SUCCESS
        Running test_default_path ... SUCCESS
        Running test_default_path_with_dockerfile ... SUCCESS
        Running test_disable_annotate ... SUCCESS
        Running test_multiple_dockerfiles ... SUCCESS
        Running test_output_with_nonzero_exit ... SUCCESS
        Running test_override_errorlevel ... SUCCESS
        Running test_version_output ... SUCCESS
Running tests in test/unit.sh
test_missing_hadolint_binary
test_missing_jq_binary
test_output_hadolint_version
test_validate_annotate
test_validate_error_level
test_validate_invalid_annotate
test_validate_invalid_error_level
test_validate_invalid_output_format
test_validate_output_format ]]
        Running test_exit_with_error ... SUCCESS
        Running test_missing_hadolint_binary ... SUCCESS
        Running test_missing_jq_binary ... SUCCESS
        Running test_output_hadolint_version ... SUCCESS
hadolint_version=2.10.0 =~ .*hadolint_version=2.10.0.* ]]
        Running test_validate_annotate ... SUCCESS
        Running test_validate_error_level ... SUCCESS
        Running test_validate_invalid_annotate ... SUCCESS
        Running test_validate_invalid_error_level ... SUCCESS
        Running test_validate_invalid_output_format ... SUCCESS
        Running test_validate_output_format ... SUCCESS
Overall result: SUCCESS

jq . coverage/bash_unit.1cf006142dc477ff/coverage.json:

{
  "files": [
    {
      "file": "/opt/homebrew/Cellar/bash_unit/2.3.3/bin/bash_unit",
      "percent_covered": "45.74",
      "covered_lines": "129",
      "total_lines": "282"
    }
  ],
  "percent_covered": "45.74",
  "covered_lines": 129,
  "total_lines": 282,
  "percent_low": 25,                                                                                                                                            "percent_high": 75,
  "command": "bash_unit",
  "date": "2025-09-06 12:51:01"
}

I wrote a few small tests with bats and it seems to work out of the box.

Mostly sharing as I go at this point to see the differences and possibly lead to a PR or just documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions