neotest: gracefully report about coverage setup error

Don't use panic when we can use t.Fatal.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-10-15 15:17:11 +03:00
parent 2dc588ea95
commit 49f2e1dc64
2 changed files with 6 additions and 6 deletions

View file

@ -48,7 +48,7 @@ func NewExecutor(t testing.TB, bc *core.Blockchain, validator, committee Signer)
Validator: validator, Validator: validator,
Committee: committee, Committee: committee,
CommitteeHash: committee.ScriptHash(), 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. // EnableCoverage enables coverage collection for this executor, but only when `go test` is running with coverage enabled.
func (e *Executor) EnableCoverage() { func (e *Executor) EnableCoverage(t testing.TB) {
e.collectCoverage = isCoverageEnabled() e.collectCoverage = isCoverageEnabled(t)
} }
// DisableCoverage disables coverage collection for this executor until enabled explicitly through EnableCoverage. // DisableCoverage disables coverage collection for this executor until enabled explicitly through EnableCoverage.

View file

@ -70,7 +70,7 @@ type coverBlock struct {
// documentName makes it clear when a `string` maps path to the script file. // documentName makes it clear when a `string` maps path to the script file.
type documentName = string type documentName = string
func isCoverageEnabled() bool { func isCoverageEnabled(t testing.TB) bool {
coverageLock.Lock() coverageLock.Lock()
defer coverageLock.Unlock() defer coverageLock.Unlock()
@ -83,7 +83,7 @@ func isCoverageEnabled() bool {
if v, ok := os.LookupEnv(disableNeotestCover); ok { if v, ok := os.LookupEnv(disableNeotestCover); ok {
disabled, err := strconv.ParseBool(v) disabled, err := strconv.ParseBool(v)
if err != nil { 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 disabledByEnvironment = disabled
} }
@ -109,7 +109,7 @@ func isCoverageEnabled() bool {
// the file with our coverage when all tests are done. // the file with our coverage when all tests are done.
err := flag.Set(goCoverProfileFlag, "") err := flag.Set(goCoverProfileFlag, "")
if err != nil { if err != nil {
panic(err) t.Fatalf("coverage: failed to overwrite coverprofile flag: %v", err)
} }
} }