From eabaee5aa7838e2364cf592309c65b74632a5a6e Mon Sep 17 00:00:00 2001 From: denisonbarbosa Date: Fri, 10 Nov 2023 13:37:30 +0200 Subject: [PATCH] Improve script based on JB suggestion --- gotestcov | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gotestcov b/gotestcov index 4fa2f8dac..d86b04fd6 100755 --- a/gotestcov +++ b/gotestcov @@ -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)" @@ -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"