diff --git a/Blueprints b/Blueprints index 582a0aa..c33b981 100644 --- a/Blueprints +++ b/Blueprints @@ -123,6 +123,7 @@ bootstrap_core_go_binary( deps = [ "blueprint", "blueprint-bootstrap", + "gotestmain-tests", ], srcs = ["bootstrap/minibp/main.go"], ) @@ -150,6 +151,19 @@ bootstrap_core_go_binary( srcs = ["gotestmain/gotestmain.go"], ) +// gotestmain tests can't be on the gotestmain module because it is an implicit dependency of tests. +// Put the tests in their own package and make it a dependency of minibp to make sure they run. +bootstrap_go_package( + name = "gotestmain-tests", + pkgPath = "github.com/google/blueprint/gotestmain", + srcs = [ + "gotestmain/dummy.go", + ], + testSrcs = [ + "gotestmain/testmain_test.go", + ], +) + bootstrap_core_go_binary( name = "gotestrunner", srcs = ["gotestrunner/gotestrunner.go"], diff --git a/build.ninja.in b/build.ninja.in index 1de3dbb..51476ca 100644 --- a/build.ninja.in +++ b/build.ninja.in @@ -199,7 +199,7 @@ default $ # Variant: # Type: bootstrap_core_go_binary # Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1 -# Defined: Blueprints:130:1 +# Defined: Blueprints:131:1 build ${g.bootstrap.buildDir}/.bootstrap/bpglob/obj/bpglob.a: $ g.bootstrap.compile ${g.bootstrap.srcDir}/bootstrap/bpglob/bpglob.go | $ @@ -225,7 +225,7 @@ default ${g.bootstrap.BinDir}/bpglob # Variant: # Type: bootstrap_core_go_binary # Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1 -# Defined: Blueprints:148:1 +# Defined: Blueprints:149:1 build ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/gotestmain.a: $ g.bootstrap.compile ${g.bootstrap.srcDir}/gotestmain/gotestmain.go | $ @@ -243,12 +243,27 @@ build ${g.bootstrap.BinDir}/gotestmain: g.bootstrap.cp $ ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/a.out default ${g.bootstrap.BinDir}/gotestmain +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Module: gotestmain-tests +# Variant: +# Type: bootstrap_go_package +# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1 +# Defined: Blueprints:156:1 + +build $ + ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg/github.com/google/blueprint/gotestmain.a $ + : g.bootstrap.compile ${g.bootstrap.srcDir}/gotestmain/dummy.go | $ + ${g.bootstrap.compileCmd} + pkgPath = github.com/google/blueprint/gotestmain +default $ + ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg/github.com/google/blueprint/gotestmain.a + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Module: gotestrunner # Variant: # Type: bootstrap_core_go_binary # Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1 -# Defined: Blueprints:153:1 +# Defined: Blueprints:167:1 build ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/gotestrunner.a: $ g.bootstrap.compile ${g.bootstrap.srcDir}/gotestrunner/gotestrunner.go $ @@ -282,15 +297,16 @@ build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a: $ ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $ ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg/github.com/google/blueprint.a $ ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $ - ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a - incFlags = -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg + ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $ + ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg/github.com/google/blueprint/gotestmain.a + incFlags = -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg -I ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg pkgPath = minibp default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out: g.bootstrap.link $ ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a | $ ${g.bootstrap.linkCmd} - libDirFlags = -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg + libDirFlags = -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg -L ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out build ${g.bootstrap.BinDir}/minibp: g.bootstrap.cp $ diff --git a/gotestmain/dummy.go b/gotestmain/dummy.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/gotestmain/dummy.go @@ -0,0 +1 @@ +package main diff --git a/gotestmain/gotestmain.go b/gotestmain/gotestmain.go index e05e4a3..9bf78b5 100644 --- a/gotestmain/gotestmain.go +++ b/gotestmain/gotestmain.go @@ -106,7 +106,9 @@ package main import ( "io" +{{if not .HasMain}} "os" +{{end}} "regexp" "testing" diff --git a/gotestmain/testmain_test.go b/gotestmain/testmain_test.go new file mode 100644 index 0000000..e011eeb --- /dev/null +++ b/gotestmain/testmain_test.go @@ -0,0 +1,33 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "os" + "testing" +) + +var a int + +func TestMain(m *testing.M) { + a = 1 + os.Exit(m.Run()) +} + +func TestTestMain(t *testing.T) { + if a != 1 { + t.Errorf("TestMain didn't run") + } +} diff --git a/tests/test_tree/build.ninja.in b/tests/test_tree/build.ninja.in index 7728ca3..b3ef0a3 100644 --- a/tests/test_tree/build.ninja.in +++ b/tests/test_tree/build.ninja.in @@ -209,7 +209,7 @@ default $ # Variant: # Type: bootstrap_core_go_binary # Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1 -# Defined: blueprint/Blueprints:130:1 +# Defined: blueprint/Blueprints:131:1 build ${g.bootstrap.buildDir}/.bootstrap/bpglob/obj/bpglob.a: $ g.bootstrap.compile $ @@ -236,7 +236,7 @@ default ${g.bootstrap.BinDir}/bpglob # Variant: # Type: bootstrap_core_go_binary # Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1 -# Defined: blueprint/Blueprints:148:1 +# Defined: blueprint/Blueprints:149:1 build ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/gotestmain.a: $ g.bootstrap.compile $ @@ -255,12 +255,28 @@ build ${g.bootstrap.BinDir}/gotestmain: g.bootstrap.cp $ ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/a.out default ${g.bootstrap.BinDir}/gotestmain +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Module: gotestmain-tests +# Variant: +# Type: bootstrap_go_package +# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1 +# Defined: blueprint/Blueprints:156:1 + +build $ + ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg/github.com/google/blueprint/gotestmain.a $ + : g.bootstrap.compile $ + ${g.bootstrap.srcDir}/blueprint/gotestmain/dummy.go | $ + ${g.bootstrap.compileCmd} + pkgPath = github.com/google/blueprint/gotestmain +default $ + ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg/github.com/google/blueprint/gotestmain.a + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Module: gotestrunner # Variant: # Type: bootstrap_core_go_binary # Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1 -# Defined: blueprint/Blueprints:153:1 +# Defined: blueprint/Blueprints:167:1 build ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/gotestrunner.a: $ g.bootstrap.compile $ @@ -296,15 +312,16 @@ build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a: $ ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $ ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg/github.com/google/blueprint.a $ ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $ - ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a - incFlags = -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg + ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $ + ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg/github.com/google/blueprint/gotestmain.a + incFlags = -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -I ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg -I ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg pkgPath = minibp default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out: g.bootstrap.link $ ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a | $ ${g.bootstrap.linkCmd} - libDirFlags = -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg + libDirFlags = -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-parser/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-deptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-pathtools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg -L ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg -L ${g.bootstrap.buildDir}/.bootstrap/gotestmain-tests/pkg default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out build ${g.bootstrap.BinDir}/minibp: g.bootstrap.cp $