Move some implicitly shared testing code for bp2build into testing.go.

Test: go test
Change-Id: I403d703184e517dbffbdccb8007229cad00858c1
This commit is contained in:
Rupert Shuttleworth 2021-05-19 09:14:26 -04:00
parent b81b29c2f6
commit 06559d07cb
9 changed files with 37 additions and 35 deletions

View file

@ -324,11 +324,11 @@ custom {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
if Errored(t, "", errs) {
if errored(t, "", errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, "", errs) {
if errored(t, "", errs) {
continue
}
@ -925,11 +925,11 @@ genrule {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
@ -957,17 +957,6 @@ genrule {
}
}
func Errored(t *testing.T, desc string, errs []error) bool {
t.Helper()
if len(errs) > 0 {
for _, err := range errs {
t.Errorf("%s: %s", desc, err)
}
return true
}
return false
}
type bp2buildMutator = func(android.TopDownMutatorContext)
func TestBp2BuildInlinesDefaults(t *testing.T) {
@ -1483,11 +1472,11 @@ filegroup {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
@ -1606,11 +1595,11 @@ func TestGlobExcludeSrcs(t *testing.T) {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}

View file

@ -22,8 +22,6 @@ import (
"testing"
)
var buildDir string
func setUp() {
var err error
buildDir, err = ioutil.TempDir("", "bazel_queryview_test")

View file

@ -617,11 +617,11 @@ cc_library {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}

View file

@ -385,11 +385,11 @@ cc_library_headers {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}

View file

@ -1132,11 +1132,11 @@ cc_library_static {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}

View file

@ -228,11 +228,11 @@ cc_object {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
@ -411,11 +411,11 @@ func TestCcObjectConfigurableAttributesBp2Build(t *testing.T) {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}

View file

@ -128,11 +128,11 @@ func TestPythonBinaryHost(t *testing.T) {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}

View file

@ -101,11 +101,11 @@ func TestShBinaryBp2Build(t *testing.T) {
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}
_, errs = ctx.ResolveDependencies(config)
if Errored(t, testCase.description, errs) {
if errored(t, testCase.description, errs) {
continue
}

View file

@ -1,6 +1,8 @@
package bp2build
import (
"testing"
"android/soong/android"
"android/soong/bazel"
)
@ -10,6 +12,8 @@ var (
bp2buildConfig = android.Bp2BuildConfig{
android.BP2BUILD_TOPLEVEL: android.Bp2BuildDefaultTrueRecursively,
}
buildDir string
)
type nestedProps struct {
@ -39,6 +43,17 @@ type customModule struct {
props customProps
}
func errored(t *testing.T, desc string, errs []error) bool {
t.Helper()
if len(errs) > 0 {
for _, err := range errs {
t.Errorf("%s: %s", desc, err)
}
return true
}
return false
}
// OutputFiles is needed because some instances of this module use dist with a
// tag property which requires the module implements OutputFileProducer.
func (m *customModule) OutputFiles(tag string) (android.Paths, error) {