Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame^] | 1 | package android |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestFileGroupWithPathProp(t *testing.T) { |
| 9 | outBaseDir := "outputbase" |
| 10 | pathPrefix := outBaseDir + "/execroot/__main__" |
| 11 | expectedOutputfile := filepath.Join(pathPrefix, "a/b/c/d/test.aidl") |
| 12 | |
| 13 | testCases := []struct { |
| 14 | bp string |
| 15 | rel string |
| 16 | }{ |
| 17 | { |
| 18 | bp: ` |
| 19 | filegroup { |
| 20 | name: "baz", |
| 21 | srcs: ["a/b/c/d/test.aidl"], |
| 22 | path: "a/b", |
| 23 | bazel_module: { label: "//:baz" }, |
| 24 | } |
| 25 | `, |
| 26 | rel: "c/d/test.aidl", |
| 27 | }, |
| 28 | { |
| 29 | bp: ` |
| 30 | filegroup { |
| 31 | name: "baz", |
| 32 | srcs: ["a/b/c/d/test.aidl"], |
| 33 | bazel_module: { label: "//:baz" }, |
| 34 | } |
| 35 | `, |
| 36 | rel: "a/b/c/d/test.aidl", |
| 37 | }, |
| 38 | } |
| 39 | |
| 40 | for _, testCase := range testCases { |
| 41 | outBaseDir := "outputbase" |
| 42 | result := GroupFixturePreparers( |
| 43 | PrepareForTestWithFilegroup, |
| 44 | FixtureModifyConfig(func(config Config) { |
| 45 | config.BazelContext = MockBazelContext{ |
| 46 | OutputBaseDir: outBaseDir, |
| 47 | LabelToOutputFiles: map[string][]string{ |
| 48 | "//:baz": []string{"a/b/c/d/test.aidl"}, |
| 49 | }, |
| 50 | } |
| 51 | }), |
| 52 | ).RunTestWithBp(t, testCase.bp) |
| 53 | |
| 54 | fg := result.Module("baz", "").(*fileGroup) |
| 55 | AssertStringEquals(t, "src relativeRoot", testCase.rel, fg.srcs[0].Rel()) |
| 56 | AssertStringEquals(t, "src full path", expectedOutputfile, fg.srcs[0].String()) |
| 57 | } |
| 58 | } |