diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-02-28 15:52:49 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-02-29 03:31:19 +0000 |
| commit | 351c15f1cee364a91ef606ef9114d55247a6a0c2 (patch) | |
| tree | 8dcea615817f3a640786e55a4ebcfe75306abe77 /src/testing | |
| parent | 28ce6f3600fd87a1ae39c492ee56307f0be3c32f (diff) | |
| download | go-351c15f1cee364a91ef606ef9114d55247a6a0c2.tar.xz | |
all: remove public named return values when useless
Named returned values should only be used on public funcs and methods
when it contributes to the documentation.
Named return values should not be used if they're only saving the
programmer a few lines of code inside the body of the function,
especially if that means there's stutter in the documentation or it
was only there so the programmer could use a naked return
statement. (Naked returns should not be used except in very small
functions)
This change is a manual audit & cleanup of public func signatures.
Signatures were not changed if:
* the func was private (wouldn't be in public godoc)
* the documentation referenced it
* the named return value was an interesting name. (i.e. it wasn't
simply stutter, repeating the name of the type)
There should be no changes in behavior. (At least: none intended)
Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109
Reviewed-on: https://go-review.googlesource.com/20024
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/testing')
| -rw-r--r-- | src/testing/quick/quick.go | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/testing/quick/quick.go b/src/testing/quick/quick.go index 0c2bf2d72b..1056aa2488 100644 --- a/src/testing/quick/quick.go +++ b/src/testing/quick/quick.go @@ -262,24 +262,21 @@ func (s *CheckEqualError) Error() string { // t.Error(err) // } // } -func Check(f interface{}, config *Config) (err error) { +func Check(f interface{}, config *Config) error { if config == nil { config = &defaultConfig } fVal, fType, ok := functionAndType(f) if !ok { - err = SetupError("argument is not a function") - return + return SetupError("argument is not a function") } if fType.NumOut() != 1 { - err = SetupError("function does not return one value") - return + return SetupError("function does not return one value") } if fType.Out(0).Kind() != reflect.Bool { - err = SetupError("function does not return a bool") - return + return SetupError("function does not return a bool") } arguments := make([]reflect.Value, fType.NumIn()) @@ -287,43 +284,39 @@ func Check(f interface{}, config *Config) (err error) { maxCount := config.getMaxCount() for i := 0; i < maxCount; i++ { - err = arbitraryValues(arguments, fType, config, rand) + err := arbitraryValues(arguments, fType, config, rand) if err != nil { - return + return err } if !fVal.Call(arguments)[0].Bool() { - err = &CheckError{i + 1, toInterfaces(arguments)} - return + return &CheckError{i + 1, toInterfaces(arguments)} } } - return + return nil } // CheckEqual looks for an input on which f and g return different results. // It calls f and g repeatedly with arbitrary values for each argument. // If f and g return different answers, CheckEqual returns a *CheckEqualError // describing the input and the outputs. -func CheckEqual(f, g interface{}, config *Config) (err error) { +func CheckEqual(f, g interface{}, config *Config) error { if config == nil { config = &defaultConfig } x, xType, ok := functionAndType(f) if !ok { - err = SetupError("f is not a function") - return + return SetupError("f is not a function") } y, yType, ok := functionAndType(g) if !ok { - err = SetupError("g is not a function") - return + return SetupError("g is not a function") } if xType != yType { - err = SetupError("functions have different types") - return + return SetupError("functions have different types") } arguments := make([]reflect.Value, xType.NumIn()) @@ -331,21 +324,20 @@ func CheckEqual(f, g interface{}, config *Config) (err error) { maxCount := config.getMaxCount() for i := 0; i < maxCount; i++ { - err = arbitraryValues(arguments, xType, config, rand) + err := arbitraryValues(arguments, xType, config, rand) if err != nil { - return + return err } xOut := toInterfaces(x.Call(arguments)) yOut := toInterfaces(y.Call(arguments)) if !reflect.DeepEqual(xOut, yOut) { - err = &CheckEqualError{CheckError{i + 1, toInterfaces(arguments)}, xOut, yOut} - return + return &CheckEqualError{CheckError{i + 1, toInterfaces(arguments)}, xOut, yOut} } } - return + return nil } // arbitraryValues writes Values to args such that args contains Values |
