Extract failIfErrored() to android/testing.go
Bug: 74506774 Test: lunch aosp_walleye-userdebug && make # runs unit tests Merged-In: I1c09412d5988dca2cc1c5f041893b313ab1c163a Change-Id: I1c09412d5988dca2cc1c5f041893b313ab1c163a
This commit is contained in:
@@ -628,7 +628,7 @@ func setupTestExpectErrs(bps map[string]string) (ctx *TestContext, errs []error)
|
||||
|
||||
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 @@ func newTestModule() Module {
|
||||
InitAndroidModule(m)
|
||||
return m
|
||||
}
|
||||
|
||||
func failIfErrored(t *testing.T, errs []error) {
|
||||
if len(errs) > 0 {
|
||||
for _, err := range errs {
|
||||
t.Error(err)
|
||||
}
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
@@ -138,9 +138,9 @@ func TestPrebuilts(t *testing.T) {
|
||||
})
|
||||
|
||||
_, 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) DepsMutator(ctx BottomUpMutatorContext) {
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
@@ -152,3 +153,13 @@ func (m TestingModule) Output(file string) BuildParams {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@@ -147,9 +147,9 @@ func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.T
|
||||
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 TestLinkReordering(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@@ -135,9 +135,9 @@ func TestDataTests(t *testing.T) {
|
||||
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) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@@ -190,9 +190,9 @@ func testContext(config android.Config, bp string,
|
||||
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 @@ func TestExcludeFileGroupInSrcs(t *testing.T) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@@ -347,7 +347,7 @@ func TestPythonModule(t *testing.T) {
|
||||
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)...)
|
||||
@@ -360,7 +360,7 @@ func TestPythonModule(t *testing.T) {
|
||||
e.parSpec, e.depsParSpecs)...)
|
||||
}
|
||||
}
|
||||
fail(t, testErrs)
|
||||
android.FailIfErrored(t, testErrs)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -458,12 +458,3 @@ func setupBuildEnv(t *testing.T) (config android.Config, buildDir string) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user