Merge "Convert test that disallows non existent paths to use fixtures"

This commit is contained in:
Paul Duffin
2021-03-25 09:16:20 +00:00
committed by Gerrit Code Review
5 changed files with 53 additions and 35 deletions

View File

@@ -117,6 +117,11 @@ var PrepareForTestWithAllowMissingDependencies = GroupFixturePreparers(
}), }),
) )
// Prepares a test that disallows non-existent paths.
var PrepareForTestDisallowNonExistentPaths = FixtureModifyConfig(func(config Config) {
config.TestAllowNonExistentPaths = false
})
func NewTestArchContext(config Config) *TestContext { func NewTestArchContext(config Config) *TestContext {
ctx := NewTestContext(config) ctx := NewTestContext(config)
ctx.preDeps = append(ctx.preDeps, registerArchMutator) ctx.preDeps = append(ctx.preDeps, registerArchMutator)

View File

@@ -141,13 +141,12 @@ var apexFixtureFactory = android.NewFixtureFactory(
} }
`), `),
android.FixtureMergeMockFs(android.MockFS{ android.FixtureMergeMockFs(android.MockFS{
"a.java": nil, "a.java": nil,
"PrebuiltAppFoo.apk": nil, "PrebuiltAppFoo.apk": nil,
"PrebuiltAppFooPriv.apk": nil, "PrebuiltAppFooPriv.apk": nil,
"build/make/target/product/security": nil, "apex_manifest.json": nil,
"apex_manifest.json": nil, "AndroidManifest.xml": nil,
"AndroidManifest.xml": nil, "system/sepolicy/apex/myapex-file_contexts": nil,
"system/sepolicy/apex/myapex-file_contexts": nil,
"system/sepolicy/apex/myapex.updatable-file_contexts": nil, "system/sepolicy/apex/myapex.updatable-file_contexts": nil,
"system/sepolicy/apex/myapex2-file_contexts": nil, "system/sepolicy/apex/myapex2-file_contexts": nil,
"system/sepolicy/apex/otherapex-file_contexts": nil, "system/sepolicy/apex/otherapex-file_contexts": nil,

View File

@@ -133,6 +133,15 @@ func defaultModuleToPath(name string) string {
} }
} }
// Test that the PrepareForTestWithJavaDefaultModules provides all the files that it uses by
// running it in a fixture that requires all source files to exist.
func TestPrepareForTestWithJavaDefaultModules(t *testing.T) {
android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.PrepareForTestDisallowNonExistentPaths,
).RunTest(t)
}
func TestJavaLinkType(t *testing.T) { func TestJavaLinkType(t *testing.T) {
testJava(t, ` testJava(t, `
java_library { java_library {
@@ -1220,33 +1229,22 @@ func TestJavaLintWithoutBaseline(t *testing.T) {
} }
func TestJavaLintRequiresCustomLintFileToExist(t *testing.T) { func TestJavaLintRequiresCustomLintFileToExist(t *testing.T) {
config := TestConfig(t.TempDir(), android.GroupFixturePreparers(
nil, PrepareForTestWithJavaDefaultModules,
` android.PrepareForTestDisallowNonExistentPaths,
java_library { ).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern([]string{`source path "mybaseline.xml" does not exist`})).
name: "foo", RunTestWithBp(t, `
srcs: [ java_library {
], name: "foo",
min_sdk_version: "29", srcs: [
sdk_version: "system_current", ],
lint: { min_sdk_version: "29",
baseline_filename: "mybaseline.xml", sdk_version: "system_current",
}, lint: {
} baseline_filename: "mybaseline.xml",
`, map[string][]byte{ },
"build/soong/java/lint_defaults.txt": nil, }
"prebuilts/cmdline-tools/tools/bin/lint": nil, `)
"prebuilts/cmdline-tools/tools/lib/lint-classpath.jar": nil,
"framework/aidl": nil,
"a.java": nil,
"AndroidManifest.xml": nil,
"build/make/target/product/security": nil,
})
config.TestAllowNonExistentPaths = false
testJavaErrorWithConfig(t,
"source path \"mybaseline.xml\" does not exist",
config,
)
} }
func TestJavaLintUsesCorrectBpConfig(t *testing.T) { func TestJavaLintUsesCorrectBpConfig(t *testing.T) {

View File

@@ -45,12 +45,29 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers(
// Make java build components available to the test. // Make java build components available to the test.
android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest), android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
android.FixtureRegisterWithContext(registerJavaPluginBuildComponents), android.FixtureRegisterWithContext(registerJavaPluginBuildComponents),
// Additional files needed in tests that disallow non-existent source files.
// This includes files that are needed by all, or at least most, instances of a java module type.
android.MockFS{
// Needed for linter used by java_library.
"build/soong/java/lint_defaults.txt": nil,
// Needed for apps that do not provide their own.
"build/make/target/product/security": nil,
}.AddToFixture(),
) )
// Test fixture preparer that will define default java modules, e.g. standard prebuilt modules. // Test fixture preparer that will define default java modules, e.g. standard prebuilt modules.
var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers( var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers(
// Make sure that all the module types used in the defaults are registered. // Make sure that all the module types used in the defaults are registered.
PrepareForTestWithJavaBuildComponents, PrepareForTestWithJavaBuildComponents,
// Additional files needed when test disallows non-existent source.
android.MockFS{
// Needed for framework-res
defaultJavaDir + "/AndroidManifest.xml": nil,
// Needed for framework
defaultJavaDir + "/framework/aidl": nil,
// Needed for various deps defined in GatherRequiredDepsForTest()
defaultJavaDir + "/a.java": nil,
}.AddToFixture(),
// The java default module definitions. // The java default module definitions.
android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", gatherRequiredDepsForTest()), android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", gatherRequiredDepsForTest()),
// Add dexpreopt compat libs (android.test.base, etc.) and a fake dex2oatd module. // Add dexpreopt compat libs (android.test.base, etc.) and a fake dex2oatd module.

View File

@@ -44,7 +44,6 @@ var prepareForSdkTestWithApex = android.GroupFixturePreparers(
`), `),
android.FixtureMergeMockFs(map[string][]byte{ android.FixtureMergeMockFs(map[string][]byte{
"build/make/target/product/security": nil,
"apex_manifest.json": nil, "apex_manifest.json": nil,
"system/sepolicy/apex/myapex-file_contexts": nil, "system/sepolicy/apex/myapex-file_contexts": nil,
"system/sepolicy/apex/myapex2-file_contexts": nil, "system/sepolicy/apex/myapex2-file_contexts": nil,