]> Cypherpunks repositories - gostls13.git/commitdiff
gotest: if the benchmark list is empty, print it in a way that
authorRob Pike <r@golang.org>
Mon, 1 Nov 2010 21:23:07 +0000 (14:23 -0700)
committerRob Pike <r@golang.org>
Mon, 1 Nov 2010 21:23:07 +0000 (14:23 -0700)
gofmt will leave alone.

R=rsc, bradfitz, bradfitzpatrick
CC=golang-dev
https://golang.org/cl/2816041

src/cmd/gotest/gotest

index 112192ecdc78dff5f0e1178a741b0dc0a5be0d78..7c2c5fbaafcdf8fd6754033f876f6c4521a28501 100755 (executable)
@@ -153,17 +153,23 @@ importpath=$(gomake -s importpath)
        echo 'var tests = []testing.Test{'
        for i in $tests
        do
-               echo '  testing.Test{"'$i'", '$i'},'
+               echo '  {"'$i'", '$i'},'
        done
        echo '}'
        # benchmark array
-       echo 'var benchmarks = []testing.InternalBenchmark{'
-       for i in $benchmarks
-       do
-               echo '  testing.InternalBenchmark{"'$i'", '$i'},'
-       done
-       echo '}'
-
+       if [ "$benchmarks" = "" ]
+       then
+               # keep the empty array gofmt-safe.
+               # (not an issue for the test array, which is never empty.)
+               echo 'var benchmarks = []testing.InternalBenchmark{}'
+       else
+               echo 'var benchmarks = []testing.InternalBenchmark{'
+               for i in $benchmarks
+               do
+                       echo '  {"'$i'", '$i'},'
+               done
+               echo '}'
+       fi
        # body
        echo
        echo 'func main() {'