LEFT | RIGHT |
1 #!/usr/bin/env bash | 1 #!/usr/bin/env bash |
2 # Copyright 2009 The Go Authors. All rights reserved. | 2 # Copyright 2009 The Go Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style | 3 # Use of this source code is governed by a BSD-style |
4 # license that can be found in the LICENSE file. | 4 # license that can be found in the LICENSE file. |
5 | 5 |
6 # Using all the test*.go files in the current directory, write out a file | 6 # Using all the test*.go files in the current directory, write out a file |
7 # _testmain.go that runs all its tests. Compile everything and run the | 7 # _testmain.go that runs all its tests. Compile everything and run the |
8 # tests. | 8 # tests. |
9 # If files are named on the command line, use them instead of test*.go. | 9 # If files are named on the command line, use them instead of test*.go. |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 # External $O file | 87 # External $O file |
88 xofile="" | 88 xofile="" |
89 havex=false | 89 havex=false |
90 if [ "x$xgofiles" != "x" ]; then | 90 if [ "x$xgofiles" != "x" ]; then |
91 xofile="_xtest_.$O" | 91 xofile="_xtest_.$O" |
92 havex=true | 92 havex=true |
93 fi | 93 fi |
94 | 94 |
95 set -e | 95 set -e |
96 | 96 |
97 make testpackage-clean | 97 gomake testpackage-clean |
98 make testpackage "GOTESTFILES=$gofiles" | 98 gomake testpackage "GOTESTFILES=$gofiles" |
99 if $havex; then | 99 if $havex; then |
100 $GC -o $xofile $xgofiles | 100 $GC -o $xofile $xgofiles |
101 fi | 101 fi |
102 | 102 |
103 # They all compile; now generate the code to call them. | 103 # They all compile; now generate the code to call them. |
104 trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15 | 104 trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15 |
105 | 105 |
106 # Suppress output to stdout on Linux | 106 # Suppress output to stdout on Linux |
107 MAKEFLAGS= | 107 MAKEFLAGS= |
108 MAKELEVEL= | 108 MAKELEVEL= |
109 | 109 |
110 importpath=$(make -s importpath) | 110 importpath=$(gomake -s importpath) |
111 { | 111 { |
112 # test functions are named TestFoo | 112 # test functions are named TestFoo |
113 # the grep -v eliminates methods and other special names | 113 # the grep -v eliminates methods and other special names |
114 # that have multiple dots. | 114 # that have multiple dots. |
115 pattern='Test([^a-z].*)?' | 115 pattern='Test([^a-z].*)?' |
116 tests=$(6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' |
grep -v '·.*[.·]' | sed 's/.* //; s/·/./') | 116 tests=$(6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' |
grep -v '·.*[.·]' | sed 's/.* //; s/·/./') |
117 if [ "x$tests" = x ]; then | 117 if [ "x$tests" = x ]; then |
118 echo 'gotest: error: no tests matching '$pattern in _test/$impor
tpath.a $xofile 1>&2 | 118 echo 'gotest: error: no tests matching '$pattern in _test/$impor
tpath.a $xofile 1>&2 |
119 exit 2 | 119 exit 2 |
120 fi | 120 fi |
(...skipping 22 matching lines...) Expand all Loading... |
143 # body | 143 # body |
144 echo | 144 echo |
145 echo 'func main() {' | 145 echo 'func main() {' |
146 echo ' testing.Main(tests)' | 146 echo ' testing.Main(tests)' |
147 echo '}' | 147 echo '}' |
148 }>_testmain.go | 148 }>_testmain.go |
149 | 149 |
150 $GC _testmain.go | 150 $GC _testmain.go |
151 $GL _testmain.$O | 151 $GL _testmain.$O |
152 $E ./$O.out "$@" | 152 $E ./$O.out "$@" |
LEFT | RIGHT |