Skip to content

Commit

Permalink
Basic TestMain support (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianludwin authored and pmbethe09 committed Aug 16, 2016
1 parent 2f6d0d7 commit 6b3d120
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions go/tools/generate_test_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import (

// Cases holds template data.
type Cases struct {
Package string
RunDir string
Names []string
Package string
RunDir string
Names []string
HasTestMain bool
}

func main() {
Expand Down Expand Up @@ -76,6 +77,11 @@ func main() {
if !strings.HasPrefix(fn.Name.Name, "Test") {
continue
}
if fn.Name.Name == "TestMain" {
// TestMain is not, itself, a test
cases.HasTestMain = true
continue
}
cases.Names = append(cases.Names, fn.Name.Name)
}
}
Expand All @@ -101,7 +107,12 @@ var tests = []testing.InternalTest{
func main() {
os.Chdir("{{.RunDir}}")
{{if not .HasTestMain}}
testing.Main(everything, tests, nil, nil)
{{else}}
m := testing.MainStart(everything, tests, nil, nil)
undertest.TestMain(m)
{{end}}
}
`))
if err := tpl.Execute(outFile, &cases); err != nil {
Expand Down

0 comments on commit 6b3d120

Please sign in to comment.