Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
62ed6ee6
Commit
62ed6ee6
authored
Mar 29, 2011
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ngotest: correctly handle packages with tests outside the package.
R=rsc CC=golang-dev
https://golang.org/cl/4330043
parent
9225bbfc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
17 deletions
+23
-17
ngotest.go
src/cmd/gotest/ngotest.go
+23
-17
No files found.
src/cmd/gotest/ngotest.go
View file @
62ed6ee6
...
...
@@ -23,6 +23,7 @@ import (
// Environment for commands.
var
(
XGC
[]
string
// 6g -I _test -o _xtest_.6
GC
[]
string
// 6g -I _test _testmain.go
GL
[]
string
// 6l -L _test _testmain.6
GOARCH
string
...
...
@@ -32,8 +33,14 @@ var (
env
=
os
.
Environ
()
)
// These strings are created by getTestNames.
var
(
files
=
make
([]
*
File
,
0
,
10
)
insideFileNames
[]
string
// list of *.go files inside the package.
outsideFileNames
[]
string
// list of *.go files outside the package (in package foo_test).
)
var
(
files
[]
*
File
importPath
string
)
...
...
@@ -72,7 +79,10 @@ func main() {
parseFiles
()
getTestNames
()
run
(
"gomake"
,
"testpackage-clean"
)
run
(
"gomake"
,
"testpackage"
,
fmt
.
Sprintf
(
"GOTESTFILES=%s"
,
insideFileNames
()))
run
(
"gomake"
,
"testpackage"
,
fmt
.
Sprintf
(
"GOTESTFILES=%s"
,
strings
.
Join
(
insideFileNames
,
" "
)))
if
len
(
outsideFileNames
)
>
0
{
run
(
append
(
XGC
,
outsideFileNames
...
)
...
)
}
importPath
=
runWithStdout
(
"gomake"
,
"-s"
,
"importpath"
)
writeTestmainGo
()
run
(
GC
...
)
...
...
@@ -149,6 +159,7 @@ func setEnvironment() {
if
gc
==
""
{
gc
=
O
+
"g"
}
XGC
=
[]
string
{
gc
,
"-I"
,
"_test"
,
"-o"
,
"_xtest_."
+
O
}
GC
=
[]
string
{
gc
,
"-I"
,
"_test"
,
"_testmain.go"
}
gl
:=
os
.
Getenv
(
"GL"
)
if
gl
==
""
{
...
...
@@ -185,9 +196,10 @@ func getTestFileNames() {
func
parseFiles
()
{
fileSet
:=
token
.
NewFileSet
()
for
_
,
f
:=
range
files
{
file
,
err
:=
parser
.
ParseFile
(
fileSet
,
f
.
name
,
nil
,
0
)
// Report declaration errors so we can abort if the files are incorrect Go.
file
,
err
:=
parser
.
ParseFile
(
fileSet
,
f
.
name
,
nil
,
parser
.
DeclarationErrors
)
if
err
!=
nil
{
Fatalf
(
"
could not parse %s: %s"
,
f
.
name
,
err
)
Fatalf
(
"
parse error: %s"
,
err
)
}
f
.
astFile
=
file
f
.
pkg
=
file
.
Name
.
String
()
...
...
@@ -217,6 +229,11 @@ func getTestNames() {
}
// TODO: worth checking the signature? Probably not.
}
if
strings
.
HasSuffix
(
f
.
pkg
,
"_test"
)
{
outsideFileNames
=
append
(
outsideFileNames
,
f
.
name
)
}
else
{
insideFileNames
=
append
(
insideFileNames
,
f
.
name
)
}
}
}
...
...
@@ -231,19 +248,6 @@ func isTest(name, prefix string) bool {
return
!
unicode
.
IsLower
(
rune
)
}
// insideFileNames returns the list of files in package foo, not a package foo_test, as a space-separated string.
func
insideFileNames
()
(
result
string
)
{
for
_
,
f
:=
range
files
{
if
!
strings
.
HasSuffix
(
f
.
pkg
,
"_test"
)
{
if
len
(
result
)
>
0
{
result
+=
" "
}
result
+=
f
.
name
}
}
return
}
func
run
(
args
...
string
)
{
doRun
(
args
,
false
)
}
...
...
@@ -349,6 +353,8 @@ func writeTestmainGo() {
// Package and imports.
fmt
.
Fprint
(
b
,
"package main
\n\n
"
)
// Are there tests from a package other than the one we're testing?
// We can't just use file names because some of the things we compiled
// contain no tests.
outsideTests
:=
false
insideTests
:=
false
for
_
,
f
:=
range
files
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment