Merge "Add test to show broken behavior of fully qualified name in path property"

This commit is contained in:
Paul Duffin 2021-07-13 13:30:44 +00:00 committed by Gerrit Code Review
commit fc78e2aad9

View file

@ -1125,6 +1125,12 @@ type pathForModuleSrcTestCase struct {
rels []string rels []string
src string src string
rel string rel string
// Make test specific preparations to the test fixture.
preparer FixturePreparer
// A test specific error handler.
errorHandler FixtureErrorHandler
} }
func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) { func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) {
@ -1157,14 +1163,23 @@ func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) {
"foo/src_special/$": nil, "foo/src_special/$": nil,
} }
errorHandler := test.errorHandler
if errorHandler == nil {
errorHandler = FixtureExpectsNoErrors
}
result := GroupFixturePreparers( result := GroupFixturePreparers(
FixtureRegisterWithContext(func(ctx RegistrationContext) { FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory) ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory)
ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory) ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory)
ctx.RegisterModuleType("filegroup", FileGroupFactory)
}), }),
PrepareForTestWithFilegroup,
PrepareForTestWithNamespace,
mockFS.AddToFixture(), mockFS.AddToFixture(),
).RunTest(t) OptionalFixturePreparer(test.preparer),
).
ExtendWithErrorHandler(errorHandler).
RunTest(t)
m := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule) m := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule)
@ -1333,6 +1348,85 @@ func TestPathForModuleSrc(t *testing.T) {
src: "foo/src_special/$", src: "foo/src_special/$",
rel: "src_special/$", rel: "src_special/$",
}, },
{
// This test makes sure that an unqualified module name cannot contain characters that make
// it appear as a qualified module name.
// TODO(b/193228441): Fix broken test.
name: "output file provider, invalid fully qualified name",
bp: `
test {
name: "foo",
src: "://other:b",
srcs: ["://other:c"],
}`,
preparer: FixtureAddTextFile("other/Android.bp", `
soong_namespace {}
output_file_provider {
name: "b",
outs: ["gen/b"],
}
output_file_provider {
name: "c",
outs: ["gen/c"],
}
`),
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
// The message is broken because PathForModuleSrc corrupts the name during validation.
`"foo": missing dependencies: /other:b, is the property annotated with android:"path"`,
`"foo": missing dependency on "//other:c", is the property annotated with android:"path"`,
}),
},
{
// TODO(b/193228441): Fix broken test.
name: "output file provider, missing fully qualified name",
bp: `
test {
name: "foo",
src: "//other:b",
srcs: ["//other:c"],
}`,
src: "foo",
rel: "foo",
srcs: []string{"foo"},
rels: []string{"foo"},
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
`"foo": Path is outside directory: /other:b`,
`"foo": Path is outside directory: /other:c`,
}),
},
{
// TODO(b/193228441): Fix broken test.
name: "output file provider, fully qualified name",
bp: `
test {
name: "foo",
src: "//other:b",
srcs: ["//other:c"],
}`,
preparer: FixtureAddTextFile("other/Android.bp", `
soong_namespace {}
output_file_provider {
name: "b",
outs: ["gen/b"],
}
output_file_provider {
name: "c",
outs: ["gen/c"],
}
`),
src: "foo",
rel: "foo",
srcs: []string{"foo"},
rels: []string{"foo"},
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
`"foo": Path is outside directory: /other:b`,
`"foo": Path is outside directory: /other:c`,
}),
},
} }
testPathForModuleSrc(t, tests) testPathForModuleSrc(t, tests)