diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go index 63a6c2e5c..71660a8e1 100644 --- a/bp2build/build_conversion_test.go +++ b/bp2build/build_conversion_test.go @@ -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 } diff --git a/bp2build/bzl_conversion_test.go b/bp2build/bzl_conversion_test.go index 32b12e42e..204c51986 100644 --- a/bp2build/bzl_conversion_test.go +++ b/bp2build/bzl_conversion_test.go @@ -22,8 +22,6 @@ import ( "testing" ) -var buildDir string - func setUp() { var err error buildDir, err = ioutil.TempDir("", "bazel_queryview_test") diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index da5444cf9..a1ffabce9 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -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 } diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go index 1202da64c..a3965ed9d 100644 --- a/bp2build/cc_library_headers_conversion_test.go +++ b/bp2build/cc_library_headers_conversion_test.go @@ -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 } diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index bb1246210..4fcf5e474 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -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 } diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go index ea8b9f158..ebc9c9449 100644 --- a/bp2build/cc_object_conversion_test.go +++ b/bp2build/cc_object_conversion_test.go @@ -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 } diff --git a/bp2build/python_binary_conversion_test.go b/bp2build/python_binary_conversion_test.go index 2054e0678..ed509bf15 100644 --- a/bp2build/python_binary_conversion_test.go +++ b/bp2build/python_binary_conversion_test.go @@ -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 } diff --git a/bp2build/sh_conversion_test.go b/bp2build/sh_conversion_test.go index 37f542ef7..575bf585c 100644 --- a/bp2build/sh_conversion_test.go +++ b/bp2build/sh_conversion_test.go @@ -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 } diff --git a/bp2build/testing.go b/bp2build/testing.go index b925682c4..e575bc6ff 100644 --- a/bp2build/testing.go +++ b/bp2build/testing.go @@ -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) {