blob: 14e9368ca874af3c134c0c626f484ed20b76f282 [file] [log] [blame]
Vinh Tran16fe8e12022-08-16 16:45:44 -04001package android
2
3import (
4 "path/filepath"
5 "testing"
6)
7
8func TestFileGroupWithPathProp(t *testing.T) {
Liz Kammer748209c2022-10-24 10:43:27 -04009 // TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups
10 t.Skip("Re-enable once filegroups are corrected for mixed builds")
Vinh Tran16fe8e12022-08-16 16:45:44 -040011 outBaseDir := "outputbase"
12 pathPrefix := outBaseDir + "/execroot/__main__"
13 expectedOutputfile := filepath.Join(pathPrefix, "a/b/c/d/test.aidl")
14
15 testCases := []struct {
16 bp string
17 rel string
18 }{
19 {
20 bp: `
21 filegroup {
22 name: "baz",
23 srcs: ["a/b/c/d/test.aidl"],
24 path: "a/b",
25 bazel_module: { label: "//:baz" },
26 }
27`,
28 rel: "c/d/test.aidl",
29 },
30 {
31 bp: `
32 filegroup {
33 name: "baz",
34 srcs: ["a/b/c/d/test.aidl"],
35 bazel_module: { label: "//:baz" },
36 }
37`,
38 rel: "a/b/c/d/test.aidl",
39 },
40 }
41
42 for _, testCase := range testCases {
Vinh Tran16fe8e12022-08-16 16:45:44 -040043 result := GroupFixturePreparers(
44 PrepareForTestWithFilegroup,
Vinh Tran16fe8e12022-08-16 16:45:44 -040045 ).RunTestWithBp(t, testCase.bp)
46
47 fg := result.Module("baz", "").(*fileGroup)
48 AssertStringEquals(t, "src relativeRoot", testCase.rel, fg.srcs[0].Rel())
49 AssertStringEquals(t, "src full path", expectedOutputfile, fg.srcs[0].String())
50 }
51}
Anton Hansson7d6dd8b2023-03-06 11:26:17 +000052
53func TestFilegroupDefaults(t *testing.T) {
54 bp := FixtureAddTextFile("p/Android.bp", `
55 filegroup_defaults {
56 name: "defaults",
57 visibility: ["//x"],
58 }
59 filegroup {
60 name: "foo",
61 defaults: ["defaults"],
62 visibility: ["//y"],
63 }
64 `)
65 result := GroupFixturePreparers(
66 PrepareForTestWithFilegroup,
67 PrepareForTestWithDefaults,
68 PrepareForTestWithVisibility,
69 bp).RunTest(t)
70 rules := effectiveVisibilityRules(result.Config, qualifiedModuleName{pkg: "p", name: "foo"})
71 AssertDeepEquals(t, "visibility", []string{"//x", "//y"}, rules.Strings())
72}