Skip to content

Commit

Permalink
testscript: tidy up condition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 12, 2022
1 parent f3cb5c2 commit 2247aee
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,32 +572,29 @@ func (ts *TestScript) applyScriptUpdates() {

// condition reports whether the given condition is satisfied.
func (ts *TestScript) condition(cond string) (bool, error) {
switch cond {
case "short":
switch {
case cond == "short":
return testing.Short(), nil
case "net":
case cond == "net":
return testenv.HasExternalNetwork(), nil
case "link":
case cond == "link":
return testenv.HasLink(), nil
case "symlink":
case cond == "symlink":
return testenv.HasSymlink(), nil
case runtime.GOOS, runtime.GOARCH:
return true, nil
case imports.KnownOS[cond]:
return cond == runtime.GOOS, nil
case imports.KnownArch[cond]:
return cond == runtime.GOARCH, nil
case strings.HasPrefix(cond, "exec:"):
prog := cond[len("exec:"):]
ok := execCache.Do(prog, func() interface{} {
_, err := execpath.Look(prog, ts.Getenv)
return err == nil
}).(bool)
return ok, nil
case ts.params.Condition != nil:
return ts.params.Condition(cond)
default:
if imports.KnownArch[cond] || imports.KnownOS[cond] {
return false, nil
}
if strings.HasPrefix(cond, "exec:") {
prog := cond[len("exec:"):]
ok := execCache.Do(prog, func() interface{} {
_, err := execpath.Look(prog, ts.Getenv)
return err == nil
}).(bool)
return ok, nil
}
if ts.params.Condition != nil {
return ts.params.Condition(cond)
}
ts.Fatalf("unknown condition %q", cond)
panic("unreachable")
}
Expand Down

0 comments on commit 2247aee

Please sign in to comment.