diff --git a/android/paths_test.go b/android/paths_test.go index 6f5d79e7e..c0667dce2 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -1125,6 +1125,12 @@ type pathForModuleSrcTestCase struct { rels []string src 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) { @@ -1157,14 +1163,23 @@ func testPathForModuleSrc(t *testing.T, tests []pathForModuleSrcTestCase) { "foo/src_special/$": nil, } + errorHandler := test.errorHandler + if errorHandler == nil { + errorHandler = FixtureExpectsNoErrors + } + result := GroupFixturePreparers( FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory) ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory) - ctx.RegisterModuleType("filegroup", FileGroupFactory) }), + PrepareForTestWithFilegroup, + PrepareForTestWithNamespace, mockFS.AddToFixture(), - ).RunTest(t) + OptionalFixturePreparer(test.preparer), + ). + ExtendWithErrorHandler(errorHandler). + RunTest(t) m := result.ModuleForTests("foo", "").Module().(*pathForModuleSrcTestModule) @@ -1333,6 +1348,85 @@ func TestPathForModuleSrc(t *testing.T) { src: "foo/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)