Extract failIfErrored() to android/testing.go

Bug: 74506774
Test: lunch aosp_walleye-userdebug && make  # runs unit tests
Change-Id: I1c09412d5988dca2cc1c5f041893b313ab1c163a
diff --git a/android/namespace_test.go b/android/namespace_test.go
index a6fc9d5..8bec0ad 100644
--- a/android/namespace_test.go
+++ b/android/namespace_test.go
@@ -628,7 +628,7 @@
 
 func setupTest(t *testing.T, bps map[string]string) (ctx *TestContext) {
 	ctx, errs := setupTestExpectErrs(bps)
-	failIfErrored(t, errs)
+	FailIfErrored(t, errs)
 	return ctx
 }
 
@@ -692,12 +692,3 @@
 	InitAndroidModule(m)
 	return m
 }
-
-func failIfErrored(t *testing.T, errs []error) {
-	if len(errs) > 0 {
-		for _, err := range errs {
-			t.Error(err)
-		}
-		t.FailNow()
-	}
-}
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 93f5805..69ce16a 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -138,9 +138,9 @@
 			})
 
 			_, errs := ctx.ParseBlueprintsFiles("Blueprints")
-			fail(t, errs)
+			FailIfErrored(t, errs)
 			_, errs = ctx.PrepareBuildActions(config)
-			fail(t, errs)
+			FailIfErrored(t, errs)
 
 			foo := ctx.ModuleForTests("foo", "")
 
@@ -231,12 +231,3 @@
 
 func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) {
 }
-
-func fail(t *testing.T, errs []error) {
-	if len(errs) > 0 {
-		for _, err := range errs {
-			t.Error(err)
-		}
-		t.FailNow()
-	}
-}
diff --git a/android/testing.go b/android/testing.go
index ae012b0..6e80c53 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -18,6 +18,7 @@
 	"fmt"
 	"path/filepath"
 	"strings"
+	"testing"
 
 	"github.com/google/blueprint"
 )
@@ -152,3 +153,13 @@
 	panic(fmt.Errorf("couldn't find output %q.\nall outputs: %v",
 		file, searchedOutputs))
 }
+
+func FailIfErrored(t *testing.T, errs []error) {
+	t.Helper()
+	if len(errs) > 0 {
+		for _, err := range errs {
+			t.Error(err)
+		}
+		t.FailNow()
+	}
+}
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 19e4703..6329605 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -147,9 +147,9 @@
 	ctx := createTestContext(t, config, bp)
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
-	failIfErrored(t, errs)
+	android.FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(config)
-	failIfErrored(t, errs)
+	android.FailIfErrored(t, errs)
 
 	return ctx
 }
@@ -1064,15 +1064,6 @@
 	}
 }
 
-func failIfErrored(t *testing.T, errs []error) {
-	if len(errs) > 0 {
-		for _, err := range errs {
-			t.Error(err)
-		}
-		t.FailNow()
-	}
-}
-
 func failIfNoMatchingErrors(t *testing.T, pattern string, errs []error) {
 	matcher, err := regexp.Compile(pattern)
 	if err != nil {
diff --git a/cc/test_data_test.go b/cc/test_data_test.go
index 434edcd..4a7b0f7 100644
--- a/cc/test_data_test.go
+++ b/cc/test_data_test.go
@@ -135,9 +135,9 @@
 			ctx.Register()
 
 			_, errs := ctx.ParseBlueprintsFiles("Blueprints")
-			fail(t, errs)
+			android.FailIfErrored(t, errs)
 			_, errs = ctx.PrepareBuildActions(config)
-			fail(t, errs)
+			android.FailIfErrored(t, errs)
 
 			foo := ctx.ModuleForTests("foo", "")
 
@@ -186,12 +186,3 @@
 func (test *testDataTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
 	test.data = ctx.ExpandSources(test.Properties.Data, nil)
 }
-
-func fail(t *testing.T, errs []error) {
-	if len(errs) > 0 {
-		for _, err := range errs {
-			t.Error(err)
-		}
-		t.FailNow()
-	}
-}
diff --git a/java/java_test.go b/java/java_test.go
index 5d6a6e0..6ef406f 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -190,9 +190,9 @@
 func run(t *testing.T, ctx *android.TestContext, config android.Config) {
 	t.Helper()
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
-	fail(t, errs)
+	android.FailIfErrored(t, errs)
 	_, errs = ctx.PrepareBuildActions(config)
-	fail(t, errs)
+	android.FailIfErrored(t, errs)
 }
 
 func testJava(t *testing.T, bp string) *android.TestContext {
@@ -977,13 +977,3 @@
 		t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs)
 	}
 }
-
-func fail(t *testing.T, errs []error) {
-	t.Helper()
-	if len(errs) > 0 {
-		for _, err := range errs {
-			t.Error(err)
-		}
-		t.FailNow()
-	}
-}
diff --git a/python/python_test.go b/python/python_test.go
index 67b1982..9ef6cb0 100644
--- a/python/python_test.go
+++ b/python/python_test.go
@@ -342,7 +342,7 @@
 			ctx.Register()
 			ctx.MockFileSystem(d.mockFiles)
 			_, testErrs := ctx.ParseBlueprintsFiles(bpFile)
-			fail(t, testErrs)
+			android.FailIfErrored(t, testErrs)
 			_, actErrs := ctx.PrepareBuildActions(config)
 			if len(actErrs) > 0 {
 				testErrs = append(testErrs, expectErrors(t, actErrs, d.errors)...)
@@ -356,7 +356,7 @@
 							e.depsSrcsZips)...)
 				}
 			}
-			fail(t, testErrs)
+			android.FailIfErrored(t, testErrs)
 		})
 	}
 }
@@ -442,12 +442,3 @@
 func tearDownBuildEnv(buildDir string) {
 	os.RemoveAll(buildDir)
 }
-
-func fail(t *testing.T, errs []error) {
-	if len(errs) > 0 {
-		for _, err := range errs {
-			t.Error(err)
-		}
-		t.FailNow()
-	}
-}