summaryrefslogtreecommitdiff
path: root/android/filegroup_test.go
blob: a7ea8054c906659d2eea7f7c79311844e82a321c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package android

import (
	"path/filepath"
	"testing"
)

func TestFileGroupWithPathProp(t *testing.T) {
	outBaseDir := "outputbase"
	pathPrefix := outBaseDir + "/execroot/__main__"
	expectedOutputfile := filepath.Join(pathPrefix, "a/b/c/d/test.aidl")

	testCases := []struct {
		bp  string
		rel string
	}{
		{
			bp: `
	filegroup {
		name: "baz",
		srcs: ["a/b/c/d/test.aidl"],
		path: "a/b",
		bazel_module: { label: "//:baz" },
	}
`,
			rel: "c/d/test.aidl",
		},
		{
			bp: `
	filegroup {
		name: "baz",
		srcs: ["a/b/c/d/test.aidl"],
		bazel_module: { label: "//:baz" },
	}
`,
			rel: "a/b/c/d/test.aidl",
		},
	}

	for _, testCase := range testCases {
		outBaseDir := "outputbase"
		result := GroupFixturePreparers(
			PrepareForTestWithFilegroup,
			FixtureModifyConfig(func(config Config) {
				config.BazelContext = MockBazelContext{
					OutputBaseDir: outBaseDir,
					LabelToOutputFiles: map[string][]string{
						"//:baz": []string{"a/b/c/d/test.aidl"},
					},
				}
			}),
		).RunTestWithBp(t, testCase.bp)

		fg := result.Module("baz", "").(*fileGroup)
		AssertStringEquals(t, "src relativeRoot", testCase.rel, fg.srcs[0].Rel())
		AssertStringEquals(t, "src full path", expectedOutputfile, fg.srcs[0].String())
	}
}