xref: /aosp_15_r20/build/soong/android/package_test.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1package android
2
3import (
4	"testing"
5)
6
7var packageTests = []struct {
8	name           string
9	fs             MockFS
10	expectedErrors []string
11}{
12	// Package default_visibility handling is tested in visibility_test.go
13	{
14		name: "package must not accept visibility, name or licenses properties",
15		fs: map[string][]byte{
16			"top/Android.bp": []byte(`
17				package {
18					name: "package",
19					visibility: ["//visibility:private"],
20					licenses: ["license"],
21				}`),
22		},
23		expectedErrors: []string{
24			`top/Android.bp:5:14: unrecognized property "licenses"`,
25			`top/Android.bp:3:10: unrecognized property "name"`,
26			`top/Android.bp:4:16: unrecognized property "visibility"`,
27		},
28	},
29	{
30		name: "multiple packages in separate directories",
31		fs: map[string][]byte{
32			"top/Android.bp": []byte(`
33				package {
34				}`),
35			"other/Android.bp": []byte(`
36				package {
37				}`),
38			"other/nested/Android.bp": []byte(`
39				package {
40				}`),
41		},
42	},
43	{
44		name: "package must not be specified more than once per package",
45		fs: map[string][]byte{
46			"top/Android.bp": []byte(`
47				package {
48					default_visibility: ["//visibility:private"],
49					default_applicable_licenses: ["license"],
50				}
51				package {
52				}`),
53		},
54		expectedErrors: []string{
55			`module "//top" already defined`,
56		},
57	},
58}
59
60func TestPackage(t *testing.T) {
61	for _, test := range packageTests {
62		t.Run(test.name, func(t *testing.T) {
63			GroupFixturePreparers(
64				PrepareForTestWithArchMutator,
65				PrepareForTestWithPackageModule,
66				test.fs.AddToFixture(),
67			).
68				ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
69				RunTest(t)
70		})
71	}
72}
73