Fix tests with TestMain
If tests have a TestMain method the os import is unused and breaks building the test. Test: gotestmain/testmain_test.go Change-Id: Ia46cdd0df71b0fc7a53d08644d220ecfd779b2ff
This commit is contained in:
parent
26c141fe68
commit
5f303b9ee8
6 changed files with 95 additions and 12 deletions
14
Blueprints
14
Blueprints
|
@ -123,6 +123,7 @@ bootstrap_core_go_binary(
|
||||||
deps = [
|
deps = [
|
||||||
"blueprint",
|
"blueprint",
|
||||||
"blueprint-bootstrap",
|
"blueprint-bootstrap",
|
||||||
|
"gotestmain-tests",
|
||||||
],
|
],
|
||||||
srcs = ["bootstrap/minibp/main.go"],
|
srcs = ["bootstrap/minibp/main.go"],
|
||||||
)
|
)
|
||||||
|
@ -150,6 +151,19 @@ bootstrap_core_go_binary(
|
||||||
srcs = ["gotestmain/gotestmain.go"],
|
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(
|
bootstrap_core_go_binary(
|
||||||
name = "gotestrunner",
|
name = "gotestrunner",
|
||||||
srcs = ["gotestrunner/gotestrunner.go"],
|
srcs = ["gotestrunner/gotestrunner.go"],
|
||||||
|
|
|
@ -199,7 +199,7 @@ default $
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_core_go_binary
|
# Type: bootstrap_core_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
|
# 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: $
|
build ${g.bootstrap.buildDir}/.bootstrap/bpglob/obj/bpglob.a: $
|
||||||
g.bootstrap.compile ${g.bootstrap.srcDir}/bootstrap/bpglob/bpglob.go | $
|
g.bootstrap.compile ${g.bootstrap.srcDir}/bootstrap/bpglob/bpglob.go | $
|
||||||
|
@ -225,7 +225,7 @@ default ${g.bootstrap.BinDir}/bpglob
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_core_go_binary
|
# Type: bootstrap_core_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
|
# 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: $
|
build ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/gotestmain.a: $
|
||||||
g.bootstrap.compile ${g.bootstrap.srcDir}/gotestmain/gotestmain.go | $
|
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
|
${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/a.out
|
||||||
default ${g.bootstrap.BinDir}/gotestmain
|
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
|
# Module: gotestrunner
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_core_go_binary
|
# Type: bootstrap_core_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
|
# 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: $
|
build ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/gotestrunner.a: $
|
||||||
g.bootstrap.compile ${g.bootstrap.srcDir}/gotestrunner/gotestrunner.go $
|
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-proptools/pkg/github.com/google/blueprint/proptools.a $
|
||||||
${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg/github.com/google/blueprint.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-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
|
||||||
${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.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/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
|
pkgPath = minibp
|
||||||
default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a
|
default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a
|
||||||
|
|
||||||
build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out: g.bootstrap.link $
|
build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out: g.bootstrap.link $
|
||||||
${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a | $
|
${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a | $
|
||||||
${g.bootstrap.linkCmd}
|
${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
|
default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out
|
||||||
|
|
||||||
build ${g.bootstrap.BinDir}/minibp: g.bootstrap.cp $
|
build ${g.bootstrap.BinDir}/minibp: g.bootstrap.cp $
|
||||||
|
|
1
gotestmain/dummy.go
Normal file
1
gotestmain/dummy.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package main
|
|
@ -106,7 +106,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
{{if not .HasMain}}
|
||||||
"os"
|
"os"
|
||||||
|
{{end}}
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
33
gotestmain/testmain_test.go
Normal file
33
gotestmain/testmain_test.go
Normal file
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -209,7 +209,7 @@ default $
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_core_go_binary
|
# Type: bootstrap_core_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
|
# 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: $
|
build ${g.bootstrap.buildDir}/.bootstrap/bpglob/obj/bpglob.a: $
|
||||||
g.bootstrap.compile $
|
g.bootstrap.compile $
|
||||||
|
@ -236,7 +236,7 @@ default ${g.bootstrap.BinDir}/bpglob
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_core_go_binary
|
# Type: bootstrap_core_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
|
# 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: $
|
build ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/gotestmain.a: $
|
||||||
g.bootstrap.compile $
|
g.bootstrap.compile $
|
||||||
|
@ -255,12 +255,28 @@ build ${g.bootstrap.BinDir}/gotestmain: g.bootstrap.cp $
|
||||||
${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/a.out
|
${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/a.out
|
||||||
default ${g.bootstrap.BinDir}/gotestmain
|
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
|
# Module: gotestrunner
|
||||||
# Variant:
|
# Variant:
|
||||||
# Type: bootstrap_core_go_binary
|
# Type: bootstrap_core_go_binary
|
||||||
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
|
# 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: $
|
build ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/gotestrunner.a: $
|
||||||
g.bootstrap.compile $
|
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-proptools/pkg/github.com/google/blueprint/proptools.a $
|
||||||
${g.bootstrap.buildDir}/.bootstrap/blueprint/pkg/github.com/google/blueprint.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-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
|
||||||
${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.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/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
|
pkgPath = minibp
|
||||||
default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a
|
default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a
|
||||||
|
|
||||||
build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out: g.bootstrap.link $
|
build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out: g.bootstrap.link $
|
||||||
${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a | $
|
${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a | $
|
||||||
${g.bootstrap.linkCmd}
|
${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
|
default ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/a.out
|
||||||
|
|
||||||
build ${g.bootstrap.BinDir}/minibp: g.bootstrap.cp $
|
build ${g.bootstrap.BinDir}/minibp: g.bootstrap.cp $
|
||||||
|
|
Loading…
Reference in a new issue