mirror of
https://github.com/golang/go
synced 2024-11-25 06:47:56 -07:00
gotest: enable unit tests for cmd directories
R=r CC=golang-dev https://golang.org/cl/4001056
This commit is contained in:
parent
c1a695c160
commit
9d3db4b62e
19
src/Make.cmd
19
src/Make.cmd
@ -27,3 +27,22 @@ CLEANFILES+=$(TARG)
|
|||||||
|
|
||||||
nuke: clean
|
nuke: clean
|
||||||
rm -f $(QUOTED_GOBIN)/$(TARG)
|
rm -f $(QUOTED_GOBIN)/$(TARG)
|
||||||
|
|
||||||
|
# for gotest
|
||||||
|
testpackage: _test/main.a
|
||||||
|
|
||||||
|
testpackage-clean:
|
||||||
|
rm -f _test/main.a _gotest_.$O
|
||||||
|
|
||||||
|
testpackage: _test/main.a
|
||||||
|
|
||||||
|
_test/main.a: _gotest_.$O
|
||||||
|
@mkdir -p _test
|
||||||
|
rm -f $@
|
||||||
|
gopack grc $@ _gotest_.$O
|
||||||
|
|
||||||
|
_gotest_.$O: $(GOFILES) $(GOTESTFILES)
|
||||||
|
$(GC) -o $@ $(GOFILES) $(GOTESTFILES)
|
||||||
|
|
||||||
|
importpath:
|
||||||
|
echo main
|
||||||
|
@ -119,6 +119,12 @@ nmgrep() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localname() {
|
||||||
|
# The package main has been renamed to __main__ when imported.
|
||||||
|
# Adjust its uses.
|
||||||
|
echo $1 | sed 's/^main\./__main__./'
|
||||||
|
}
|
||||||
|
|
||||||
importpath=$(gomake -s importpath)
|
importpath=$(gomake -s importpath)
|
||||||
{
|
{
|
||||||
# test functions are named TestFoo
|
# test functions are named TestFoo
|
||||||
@ -139,9 +145,20 @@ importpath=$(gomake -s importpath)
|
|||||||
echo
|
echo
|
||||||
# imports
|
# imports
|
||||||
if echo "$tests" | egrep -v '_test\.' >/dev/null; then
|
if echo "$tests" | egrep -v '_test\.' >/dev/null; then
|
||||||
if [ "$importpath" != "testing" ]; then
|
case "$importpath" in
|
||||||
|
testing)
|
||||||
|
;;
|
||||||
|
main)
|
||||||
|
# Import path main is reserved, so import with
|
||||||
|
# explicit reference to ./_test/main instead.
|
||||||
|
# Also, the file we are writing defines a function named main,
|
||||||
|
# so rename this import to __main__ to avoid name conflict.
|
||||||
|
echo 'import __main__ "./_test/main"'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
echo 'import "'$importpath'"'
|
echo 'import "'$importpath'"'
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
if $havex; then
|
if $havex; then
|
||||||
echo 'import "./_xtest_"'
|
echo 'import "./_xtest_"'
|
||||||
@ -153,23 +170,20 @@ importpath=$(gomake -s importpath)
|
|||||||
echo 'var tests = []testing.InternalTest{'
|
echo 'var tests = []testing.InternalTest{'
|
||||||
for i in $tests
|
for i in $tests
|
||||||
do
|
do
|
||||||
echo ' {"'$i'", '$i'},'
|
j=$(localname $i)
|
||||||
|
echo ' {"'$i'", '$j'},'
|
||||||
done
|
done
|
||||||
echo '}'
|
echo '}'
|
||||||
# benchmark array
|
# benchmark array
|
||||||
if [ "$benchmarks" = "" ]
|
# The comment makes the multiline declaration
|
||||||
then
|
# gofmt-safe even when there are no benchmarks.
|
||||||
# keep the empty array gofmt-safe.
|
echo 'var benchmarks = []testing.InternalBenchmark{ //'
|
||||||
# (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
|
for i in $benchmarks
|
||||||
do
|
do
|
||||||
echo ' {"'$i'", '$i'},'
|
j=$(localname $i)
|
||||||
|
echo ' {"'$i'", '$j'},'
|
||||||
done
|
done
|
||||||
echo '}'
|
echo '}'
|
||||||
fi
|
|
||||||
# body
|
# body
|
||||||
echo
|
echo
|
||||||
echo 'func main() {'
|
echo 'func main() {'
|
||||||
|
Loading…
Reference in New Issue
Block a user