From 49f2e1dc64dd38ceaa1cbd82c99b814e6f50cb11 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 15 Oct 2024 15:17:11 +0300 Subject: [PATCH] neotest: gracefully report about coverage setup error Don't use panic when we can use t.Fatal. Signed-off-by: Anna Shaleva --- pkg/neotest/basic.go | 6 +++--- pkg/neotest/coverage.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/neotest/basic.go b/pkg/neotest/basic.go index 3a0de0305..3e03b5a68 100644 --- a/pkg/neotest/basic.go +++ b/pkg/neotest/basic.go @@ -48,7 +48,7 @@ func NewExecutor(t testing.TB, bc *core.Blockchain, validator, committee Signer) Validator: validator, Committee: committee, CommitteeHash: committee.ScriptHash(), - collectCoverage: isCoverageEnabled(), + collectCoverage: isCoverageEnabled(t), } } @@ -452,8 +452,8 @@ func (e *Executor) GetTxExecResult(t testing.TB, h util.Uint256) *state.AppExecR } // EnableCoverage enables coverage collection for this executor, but only when `go test` is running with coverage enabled. -func (e *Executor) EnableCoverage() { - e.collectCoverage = isCoverageEnabled() +func (e *Executor) EnableCoverage(t testing.TB) { + e.collectCoverage = isCoverageEnabled(t) } // DisableCoverage disables coverage collection for this executor until enabled explicitly through EnableCoverage. diff --git a/pkg/neotest/coverage.go b/pkg/neotest/coverage.go index 4dc285865..bd6218511 100644 --- a/pkg/neotest/coverage.go +++ b/pkg/neotest/coverage.go @@ -70,7 +70,7 @@ type coverBlock struct { // documentName makes it clear when a `string` maps path to the script file. type documentName = string -func isCoverageEnabled() bool { +func isCoverageEnabled(t testing.TB) bool { coverageLock.Lock() defer coverageLock.Unlock() @@ -83,7 +83,7 @@ func isCoverageEnabled() bool { if v, ok := os.LookupEnv(disableNeotestCover); ok { disabled, err := strconv.ParseBool(v) if err != nil { - panic(fmt.Sprintf("coverage: error when parsing environment variable '%s', expected bool, but got '%s'", disableNeotestCover, v)) + t.Fatalf("coverage: error when parsing environment variable '%s', expected bool, but got '%s'", disableNeotestCover, v) } disabledByEnvironment = disabled } @@ -109,7 +109,7 @@ func isCoverageEnabled() bool { // the file with our coverage when all tests are done. err := flag.Set(goCoverProfileFlag, "") if err != nil { - panic(err) + t.Fatalf("coverage: failed to overwrite coverprofile flag: %v", err) } }