diff options
Diffstat (limited to 'java/java_test.go')
-rw-r--r-- | java/java_test.go | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/java/java_test.go b/java/java_test.go index 670eefc76..9ef23e9a9 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -65,6 +65,7 @@ var javaFixtureFactory = android.NewFixtureFactory( ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) }), javaMockFS().AddToFixture(), + PrepareForTestWithJavaSdkLibraryFiles, dexpreopt.PrepareForTestWithDexpreopt, ) @@ -147,7 +148,11 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) { // deprecated func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) { t.Helper() - return testJavaErrorWithConfig(t, pattern, testConfig(nil, bp, nil)) + result := javaFixtureFactory. + Extend(dexpreopt.PrepareForTestWithDexpreopt). + ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). + RunTestWithBp(t, bp) + return result.TestContext, result.Config } // testJavaErrorWithConfig is a legacy way of running tests of java modules that expect errors. @@ -895,7 +900,7 @@ func TestJavaSdkLibraryEnforce(t *testing.T) { allowList []string } - createTestConfig := func(info testConfigInfo) android.Config { + createPreparer := func(info testConfigInfo) android.FixturePreparer { bpFileTemplate := ` java_library { name: "foo", @@ -918,58 +923,68 @@ func TestJavaSdkLibraryEnforce(t *testing.T) { info.libraryType, partitionToBpOption(info.toPartition)) - config := testConfig(nil, bpFile, nil) - configVariables := config.TestProductVariables - - configVariables.EnforceProductPartitionInterface = proptools.BoolPtr(info.enforceProductInterface) - if info.enforceVendorInterface { - configVariables.DeviceVndkVersion = proptools.StringPtr("current") - } - configVariables.EnforceInterPartitionJavaSdkLibrary = proptools.BoolPtr(info.enforceJavaSdkLibraryCheck) - configVariables.InterPartitionJavaLibraryAllowList = info.allowList + return android.GroupFixturePreparers( + android.FixtureWithRootAndroidBp(bpFile), + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.EnforceProductPartitionInterface = proptools.BoolPtr(info.enforceProductInterface) + if info.enforceVendorInterface { + variables.DeviceVndkVersion = proptools.StringPtr("current") + } + variables.EnforceInterPartitionJavaSdkLibrary = proptools.BoolPtr(info.enforceJavaSdkLibraryCheck) + variables.InterPartitionJavaLibraryAllowList = info.allowList + }), + ) + } - return config + runTest := func(t *testing.T, info testConfigInfo, expectedErrorPattern string) { + t.Run(fmt.Sprintf("%#v", info), func(t *testing.T) { + errorHandler := android.FixtureExpectsNoErrors + if expectedErrorPattern != "" { + errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorPattern) + } + javaFixtureFactory.ExtendWithErrorHandler(errorHandler).RunTest(t, createPreparer(info)) + }) } errorMessage := "is not allowed across the partitions" - testJavaWithConfig(t, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_library", fromPartition: "product", toPartition: "system", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: false, - })) + }, "") - testJavaWithConfig(t, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_library", fromPartition: "product", toPartition: "system", enforceVendorInterface: true, enforceProductInterface: false, enforceJavaSdkLibraryCheck: true, - })) + }, "") - testJavaErrorWithConfig(t, errorMessage, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_library", fromPartition: "product", toPartition: "system", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, - })) + }, errorMessage) - testJavaErrorWithConfig(t, errorMessage, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_library", fromPartition: "vendor", toPartition: "system", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, - })) + }, errorMessage) - testJavaWithConfig(t, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_library", fromPartition: "vendor", toPartition: "system", @@ -977,43 +992,43 @@ func TestJavaSdkLibraryEnforce(t *testing.T) { enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, allowList: []string{"bar"}, - })) + }, "") - testJavaErrorWithConfig(t, errorMessage, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_library", fromPartition: "vendor", toPartition: "product", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, - })) + }, errorMessage) - testJavaWithConfig(t, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_sdk_library", fromPartition: "product", toPartition: "system", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, - })) + }, "") - testJavaWithConfig(t, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_sdk_library", fromPartition: "vendor", toPartition: "system", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, - })) + }, "") - testJavaWithConfig(t, createTestConfig(testConfigInfo{ + runTest(t, testConfigInfo{ libraryType: "java_sdk_library", fromPartition: "vendor", toPartition: "product", enforceVendorInterface: true, enforceProductInterface: true, enforceJavaSdkLibraryCheck: true, - })) + }, "") } func TestDefaults(t *testing.T) { |