Skip to content

Commit

Permalink
Improve script based on JB suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
denisonbarbosa committed Nov 10, 2023
1 parent 4c238a9 commit eabaee5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions gotestcov
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

set -eu

# find_go_mod walks up the directory tree looking for the go.mod file.
# If it doesn't find it, the script will be aborted.
find_go_mod() {
cwd="$(pwd)"

while :; do
if [ -e "$cwd/go.mod" ]; then
echo $cwd
while [ "$cwd" != "/" ]; do
if [ -f "$cwd/go.mod" ]; then
echo "$cwd"
return
elif [ "$cwd" = "/" ]; then
echo "E: go.mod not found in parent path. Aborting!"
exit 1
else
cwd="$(dirname "$cwd")"
fi
cwd=$(dirname "$cwd")
done
echo "Error: go.mod not found in parent path. Aborting!"
exit 1
}

projectroot="$(find_go_mod)"
Expand Down Expand Up @@ -43,10 +43,10 @@ go test -cover -covermode=set $@ -args -test.gocoverdir="${raw_cov_dir}"
go tool covdata textfmt -i="${raw_cov_dir}" -o="${cov_dir}/coverage.out"

# Append the Rust coverage data to the Go one
cat "${raw_cov_dir}/rust-cov/rust2go_coverage" >> "${cov_dir}/coverage.out"
cat "${raw_cov_dir}/rust-cov/rust2go_coverage" >>"${cov_dir}/coverage.out"

# Filter out the testutils package and the pb.go file
grep -v -e "testutils" -e "pb.go" "${cov_dir}/coverage.out" > "${cov_dir}/coverage.out.filtered"
grep -v -e "testutils" -e "pb.go" "${cov_dir}/coverage.out" >"${cov_dir}/coverage.out.filtered"

# Generate the HTML report
go tool cover -o "${cov_dir}/index.html" -html="${cov_dir}/coverage.out.filtered"

0 comments on commit eabaee5

Please sign in to comment.