Skip to content

Commit f1aca1d

Browse files
twpaynemvdan
authored andcommitted
testscript: tidy up condition logic
1 parent b66946f commit f1aca1d

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

testscript/testscript.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -572,32 +572,29 @@ func (ts *TestScript) applyScriptUpdates() {
572572

573573
// condition reports whether the given condition is satisfied.
574574
func (ts *TestScript) condition(cond string) (bool, error) {
575-
switch cond {
576-
case "short":
575+
switch {
576+
case cond == "short":
577577
return testing.Short(), nil
578-
case "net":
578+
case cond == "net":
579579
return testenv.HasExternalNetwork(), nil
580-
case "link":
580+
case cond == "link":
581581
return testenv.HasLink(), nil
582-
case "symlink":
582+
case cond == "symlink":
583583
return testenv.HasSymlink(), nil
584-
case runtime.GOOS, runtime.GOARCH:
585-
return true, nil
584+
case imports.KnownOS[cond]:
585+
return cond == runtime.GOOS, nil
586+
case imports.KnownArch[cond]:
587+
return cond == runtime.GOARCH, nil
588+
case strings.HasPrefix(cond, "exec:"):
589+
prog := cond[len("exec:"):]
590+
ok := execCache.Do(prog, func() interface{} {
591+
_, err := execpath.Look(prog, ts.Getenv)
592+
return err == nil
593+
}).(bool)
594+
return ok, nil
595+
case ts.params.Condition != nil:
596+
return ts.params.Condition(cond)
586597
default:
587-
if imports.KnownArch[cond] || imports.KnownOS[cond] {
588-
return false, nil
589-
}
590-
if strings.HasPrefix(cond, "exec:") {
591-
prog := cond[len("exec:"):]
592-
ok := execCache.Do(prog, func() interface{} {
593-
_, err := execpath.Look(prog, ts.Getenv)
594-
return err == nil
595-
}).(bool)
596-
return ok, nil
597-
}
598-
if ts.params.Condition != nil {
599-
return ts.params.Condition(cond)
600-
}
601598
ts.Fatalf("unknown condition %q", cond)
602599
panic("unreachable")
603600
}

0 commit comments

Comments
 (0)