Skip to content

Commit fea2bbb

Browse files
committed
Tweaks kcov option
1 parent 191b23e commit fea2bbb

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

.shellspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
--skip-message moderate
33
--fail-no-examples
44
--env-from spec/env.sh
5-
--kcov-common-options "--include-path=./lib,./libexec,./shellspec"
5+
--kcov-common-options "--path-strip-level=1 --include-path=./lib,./libexec,./shellspec"

lib/libexec/kcov-executor.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
executor() {
77
translator --functrace --fd=537 "$@" > "$SHELLSPEC_KCOV_IN_FILE"
88
#shellcheck disable=SC2039,SC2086
9-
"$SHELLSPEC_KCOV_PATH" --bash-parser="$SHELLSPEC_SHELL" --bash-method=DEBUG \
9+
"$SHELLSPEC_KCOV_PATH" --bash-method=DEBUG \
10+
--bash-parser="$SHELLSPEC_SHELL" \
11+
--bash-parse-files-in-dir="$SHELLSPEC_PROJECT_ROOT" \
1012
$SHELLSPEC_KCOV_COMMON_OPTS $SHELLSPEC_KCOV_OPTS \
1113
"$SHELLSPEC_COVERAGEDIR" "$SHELLSPEC_KCOV_IN_FILE" 537>&1
1214
}

libexec/shellspec-runner.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ cleanup() {
2121
tmpbase="$SHELLSPEC_TMPBASE"
2222
SHELLSPEC_TMPBASE=''
2323
rmtempdir "$tmpbase"
24-
rm -f "$SHELLSPEC_KCOV_IN_FILE"
24+
if [ -f "$SHELLSPEC_KCOV_IN_FILE" ]; then
25+
rm "$SHELLSPEC_KCOV_IN_FILE"
26+
fi
2527
}
2628
trap 'cleanup' EXIT
2729

shellspec

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set -eu
66
export SHELLSPEC_VERSION='0.16.0'
77
export SHELLSPEC_PATH=''
88
export SHELLSPEC_ROOT=''
9+
export SHELLSPEC_PROJECT_ROOT=''
10+
export SHELLSPEC_PROJECT_NAME=''
911
export SHELLSPEC_LIB=''
1012
export SHELLSPEC_LIBEXEC=''
1113
export SHELLSPEC_SPECDIR=''
@@ -47,9 +49,10 @@ export SHELLSPEC_SEED=''
4749
export SHELLSPEC_COVERAGEDIR=''
4850
export SHELLSPEC_KCOV=''
4951
export SHELLSPEC_KCOV_PATH='kcov'
50-
export SHELLSPEC_KCOV_IN_FILE=''
5152
export SHELLSPEC_KCOV_COMMON_OPTS=''
5253
export SHELLSPEC_KCOV_OPTS=''
54+
export SHELLSPEC_KCOV_FILENAME=''
55+
export SHELLSPEC_KCOV_IN_FILE=''
5356

5457
#shellcheck disable=SC2039
5558
export SHELLSPEC_HOSTNAME=${HOSTNAME:-localhost}
@@ -77,19 +80,12 @@ SHELLSPEC_REPORTERLIB="$SHELLSPEC_LIB/libexec/reporter"
7780
. "$SHELLSPEC_LIB/libexec/shellspec.sh"
7881

7982
SHELLSPEC_LIBEXEC="$SHELLSPEC_ROOT/libexec"
80-
SHELLSPEC_SPECDIR=$PWD/spec
81-
SHELLSPEC_REPORTDIR=$PWD/report
82-
SHELLSPEC_COVERAGEDIR=$PWD/coverage
83-
SHELLSPEC_LOAD_PATH=$SHELLSPEC_SPECDIR:$SHELLSPEC_LIB:$SHELLSPEC_REPORTERLIB
84-
85-
SHELLSPEC_KCOV_IN_FILE=${PWD##*/}_specs.kcov-in-file
86-
while IFS= read -r option; do
87-
SHELLSPEC_KCOV_COMMON_OPTS="$SHELLSPEC_KCOV_COMMON_OPTS$option "
88-
done <<HERE
89-
--include-path=.
90-
--include-pattern=.sh
91-
--exclude-pattern=/coverage/,/spec/,/report/
92-
HERE
83+
SHELLSPEC_PROJECT_ROOT="$PWD"
84+
SHELLSPEC_PROJECT_NAME="${SHELLSPEC_PROJECT_ROOT##*/}"
85+
SHELLSPEC_SPECDIR="$SHELLSPEC_PROJECT_ROOT/spec"
86+
SHELLSPEC_REPORTDIR="$SHELLSPEC_PROJECT_ROOT/report"
87+
SHELLSPEC_COVERAGEDIR="$SHELLSPEC_PROJECT_ROOT/coverage"
88+
SHELLSPEC_LOAD_PATH="$SHELLSPEC_SPECDIR:$SHELLSPEC_LIB:$SHELLSPEC_REPORTERLIB"
9389

9490
SHELLSPEC_UNIXTIME=$(date +%s)
9591
SHELLSPEC_TMPBASE="${SHELLSPEC_TMPDIR%/}/shellspec.$SHELLSPEC_UNIXTIME.$$"
@@ -106,6 +102,17 @@ elif command_path ksh > /dev/null; then
106102
SHELLSPEC_TIME="ksh $SHELLSPEC_TIME"
107103
fi
108104

105+
while IFS= read -r option; do
106+
SHELLSPEC_KCOV_COMMON_OPTS="$SHELLSPEC_KCOV_COMMON_OPTS$option "
107+
done <<HERE
108+
--path-strip-level=1
109+
--include-path=.
110+
--include-pattern=.sh
111+
--exclude-pattern=/coverage/,/spec/,/report/
112+
HERE
113+
SHELLSPEC_KCOV_FILENAME="$SHELLSPEC_PROJECT_NAME [specfiles]"
114+
SHELLSPEC_KCOV_IN_FILE="$SHELLSPEC_PROJECT_ROOT/$SHELLSPEC_KCOV_FILENAME"
115+
109116
usage() {
110117
while IFS= read -r line; do echo "$line"; done <<USAGE
111118
Usage: shellspec [options] [files or directories]
@@ -168,6 +175,7 @@ Usage: shellspec [options] [files or directories]
168175
Note: Requires kcov and bash, parallel execution is ignored.
169176
--kcov-path PATH Specify kcov path [default: kcov]
170177
--kcov-common-options OPTIONS Specify kcov common options [default: see below]
178+
--path-strip-level=1
171179
--include-path=.
172180
--include-pattern=.sh
173181
--exclude-pattern=/coverage/,/spec/,/report/

0 commit comments

Comments
 (0)