Skip to content

Commit

Permalink
[engine] Use slices.Contains
Browse files Browse the repository at this point in the history
Change-Id: I9382e5bece54bb4b3ee1744677d2034f1b51d725
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/shac/+/896618
Fuchsia-Auto-Submit: Oliver Newman <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Marc-Antoine Ruel <[email protected]>
  • Loading branch information
orn688 authored and CQ Bot committed Aug 7, 2023
1 parent f429c07 commit eea6195
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions internal/engine/runtime_ctx_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"

"go.fuchsia.dev/shac-project/shac/internal/sandbox"
"go.fuchsia.dev/shac-project/shac/internal/slices"
"go.starlark.net/starlark"
)

Expand Down Expand Up @@ -108,7 +109,7 @@ func (s *subprocess) wait() (starlark.Value, error) {
return nil, errors.New("process returned too much stderr")
}

if !contains(s.okRetcodes, retcode) && s.raiseOnFailure {
if !slices.Contains(s.okRetcodes, retcode) && s.raiseOnFailure {
var msgBuilder strings.Builder
msgBuilder.WriteString(fmt.Sprintf("command failed with exit code %d: %s", retcode, s.args))
if s.stderr.Len() > 0 {
Expand Down Expand Up @@ -401,12 +402,3 @@ func sequenceToInts(s starlark.Sequence) []int {
}
return out
}

func contains[T comparable](slice []T, target T) bool {
for _, item := range slice {
if item == target {
return true
}
}
return false
}

0 comments on commit eea6195

Please sign in to comment.