Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

code coverage #222

Open
030 opened this issue Jun 18, 2017 · 4 comments
Open

code coverage #222

030 opened this issue Jun 18, 2017 · 4 comments

Comments

@030
Copy link

030 commented Jun 18, 2017

Is it possible to show the code coverage when bats has been run?

@mosbth
Copy link

mosbth commented Nov 14, 2017

In general you must use an external tool to do this. A tool specific to generate a code coverage report from the test execution.

I am about to try integrate some tool for code coverage into my own test, perhaps bashcov or kcov.

It seems like a discussion on code coverage is ongoing in the new repo for Bats.

@alexRambo
Copy link

Not sure if this is the right place to ask, but does anyone have an example (command and index.html output) of kcov working with bats???
Problem: When the following command is run (kcov being fed bats bash file with arguments):
kcov [outputdir]/coverage/ bats [bats_test_path]/test_AFF_Simple.bats
the OUTPUT is 0% code coverage for the "bats" only with 20 lines instrumented and 0 hit.
This is the file output:

Coverage Report

Command:batsLine numberDate:2018-06-13 19:44:55Instrumented lines:20HitsCode covered:0.0%Executed lines:0Order | Command: | bats | Line number | Date: | 2018-06-13 19:44:55 | Instrumented lines: | 20 | Hits | Code covered: | 0.0% | Executed lines: | 0 | Order
Command: | bats | Line number
Date: | 2018-06-13 19:44:55 | Instrumented lines: | 20 | Hits
Code covered: | 0.0% | Executed lines: | 0 | Order

#!/usr/bin/env bash
2
30 set -e
4
50 export BATS_READLINK='true'
60 if command -v 'greadlink' >/dev/null; then
70 BATS_READLINK='greadlink'
80 elif command -v 'readlink' >/dev/null; then
90 BATS_READLINK='readlink'
10 fi
11
12 bats_resolve_link() {
130 if ! "$BATS_READLINK" "$1"; then
140 return 0
15 fi
16 }
17
18 bats_absolute_path() {
190 local cwd="$PWD"
200 local path="$1"
210 local result="$2"
22
230 while [[ -n "$path" ]]; do
240 cd "${path%/}"
250 path="$(bats_resolve_link "${path##/}")"
26 done
27
280 printf -v "$result" -- '%s' "$PWD"
290 cd "$cwd"
30 }
31
320 export BATS_ROOT
330 bats_absolute_path "$0" 'BATS_ROOT'
340 BATS_ROOT="${BATS_ROOT%/*}"
350 exec "$BATS_ROOT/libexec/bats" "$@"

Any and ALL help is appreciated.
Note: I managed to get code coverage for PYTHON files; but NOT for BAT files....

Thanks,
-Alex

@sunwei
Copy link

sunwei commented Mar 2, 2019

Is there any updates about the bats coverage?

@Potherca
Copy link

@sunwei There isn't going to be any updates in this repo. I would advise you to move over to https://github.com/bats-core/bats-core, as that is where active development has moved after the call for maintainers in issue #150

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants