Skip to content

Commit 1dd65dd

Browse files
committed
fix_: fix test coverage when rerunning tests
1 parent bdc5bea commit 1dd65dd

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ test-unit: export UNIT_TEST_PACKAGES_NOT_PARALLELIZABLE ?= \
366366
test-unit: export UNIT_TEST_PACKAGES_WITH_EXTENDED_TIMEOUT ?= \
367367
github.com/status-im/status-go/protocol
368368
test-unit: ##@tests Run unit and integration tests
369+
go install github.com/wadey/gocovmerge@latest
369370
./_assets/scripts/run_unit_tests.sh
370371

371372
test-unit-race: export GOTEST_EXTRAFLAGS=-race

_assets/scripts/run_unit_tests.sh

+13-4
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,24 @@ run_test_for_package() {
7979
gotestsum_flags="${gotestsum_flags} --junitfile=${report_file} --rerun-fails-report=${rerun_report_file}"
8080
fi
8181

82-
gotestsum --packages="${package}" ${gotestsum_flags} -- \
82+
# Cleanup previous coverage reports
83+
rm -f ${package_dir}/coverage.out.rerun.*
84+
85+
PACKAGE_DIR=${package_dir} gotestsum --packages="${package}" ${gotestsum_flags} --raw-command -- \
86+
./_assets/scripts/test-with-coverage.sh \
87+
${package} \
8388
-v ${GOTEST_EXTRAFLAGS} \
8489
-timeout "${package_timeout}" \
8590
-count 1 \
86-
-tags "${BUILD_TAGS}" \
87-
-covermode=atomic \
88-
-coverprofile="${coverage_file}" | \
91+
-tags "${BUILD_TAGS}" |
8992
redirect_stdout "${output_file}"
9093

94+
# Merge package coverage results
95+
gocovmerge ${package_dir}/coverage.out.rerun.* > ${coverage_file}
96+
97+
# Cleanup coverage reports
98+
rm -f ${package_dir}/coverage.out.rerun.*
99+
91100
local go_test_exit=$?
92101
echo "${go_test_exit}" > "${exit_code_file}"
93102
if [[ "${go_test_exit}" -ne 0 ]]; then

_assets/scripts/test-with-coverage.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
coverage_file_path="${PACKAGE_DIR}/$(mktemp coverage.out.rerun.XXXXXXXXXX)"
4+
go test -json \
5+
-covermode=atomic \
6+
-coverprofile="${coverage_file_path}" \
7+
"$@"

0 commit comments

Comments
 (0)