Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1161)

Side by Side Diff: go/util/util.go

Issue 1300273002: Reland of Add a library for running external commands, providing timeouts and test injection. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Fix squashWriters for struct arguments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/util/command.go ('k') | go/util/util_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package util 1 package util
2 2
3 import ( 3 import (
4 "crypto/rand" 4 "crypto/rand"
5 "crypto/sha256" 5 "crypto/sha256"
6 "fmt" 6 "fmt"
7 "io" 7 "io"
8 mathrand "math/rand" 8 mathrand "math/rand"
9 "os" 9 "os"
10 "reflect"
10 "regexp" 11 "regexp"
11 "runtime" 12 "runtime"
12 "sort" 13 "sort"
13 "strings" 14 "strings"
14 "time" 15 "time"
15 16
16 "github.com/skia-dev/glog" 17 "github.com/skia-dev/glog"
17 ) 18 )
18 19
19 const ( 20 const (
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 439
439 // AnyMatch returns true iff the given string matches any regexp in the slice. 440 // AnyMatch returns true iff the given string matches any regexp in the slice.
440 func AnyMatch(re []*regexp.Regexp, s string) bool { 441 func AnyMatch(re []*regexp.Regexp, s string) bool {
441 for _, r := range re { 442 for _, r := range re {
442 if r.MatchString(s) { 443 if r.MatchString(s) {
443 return true 444 return true
444 } 445 }
445 } 446 }
446 return false 447 return false
447 } 448 }
449
450 // Returns true if i is nil or is an interface containing a nil or invalid value .
451 func IsNil(i interface{}) bool {
452 if i == nil {
453 return true
454 }
455 v := reflect.ValueOf(i)
456 if !v.IsValid() {
457 return true
458 }
459 switch v.Kind() {
460 case reflect.Chan, reflect.Func, reflect.Map, reflect.Slice:
461 return v.IsNil()
462 case reflect.Interface, reflect.Ptr:
463 if v.IsNil() {
464 return true
465 }
466 inner := v.Elem()
467 if !inner.IsValid() {
468 return true
469 }
470 if inner.CanInterface() {
471 return IsNil(inner.Interface())
472 }
473 return false
474 default:
475 return false
476 }
477 }
OLDNEW
« no previous file with comments | « go/util/command.go ('k') | go/util/util_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698