2019-05-31 15:00:04 +02:00
|
|
|
package android
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var packageTests = []struct {
|
|
|
|
name string
|
2021-03-17 00:45:22 +01:00
|
|
|
fs MockFS
|
2019-05-31 15:00:04 +02:00
|
|
|
expectedErrors []string
|
|
|
|
}{
|
|
|
|
// Package default_visibility handling is tested in visibility_test.go
|
|
|
|
{
|
|
|
|
name: "package must not accept visibility and name properties",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2019-05-31 15:00:04 +02:00
|
|
|
package {
|
|
|
|
name: "package",
|
|
|
|
visibility: ["//visibility:private"],
|
2021-01-07 04:34:31 +01:00
|
|
|
licenses: ["license"],
|
2019-05-31 15:00:04 +02:00
|
|
|
}`),
|
|
|
|
},
|
|
|
|
expectedErrors: []string{
|
2021-09-02 11:46:24 +02:00
|
|
|
`top/Android.bp:5:14: unrecognized property "licenses"`,
|
|
|
|
`top/Android.bp:3:10: unrecognized property "name"`,
|
|
|
|
`top/Android.bp:4:16: unrecognized property "visibility"`,
|
2019-05-31 15:00:04 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple packages in separate directories",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2019-05-31 15:00:04 +02:00
|
|
|
package {
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"other/Android.bp": []byte(`
|
2019-05-31 15:00:04 +02:00
|
|
|
package {
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"other/nested/Android.bp": []byte(`
|
2019-05-31 15:00:04 +02:00
|
|
|
package {
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "package must not be specified more than once per package",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2019-05-31 15:00:04 +02:00
|
|
|
package {
|
|
|
|
default_visibility: ["//visibility:private"],
|
2021-01-07 04:34:31 +01:00
|
|
|
default_applicable_licenses: ["license"],
|
2019-05-31 15:00:04 +02:00
|
|
|
}
|
|
|
|
|
2021-01-07 04:34:31 +01:00
|
|
|
package {
|
2019-05-31 15:00:04 +02:00
|
|
|
}`),
|
|
|
|
},
|
|
|
|
expectedErrors: []string{
|
2020-05-01 12:57:12 +02:00
|
|
|
`module "//top" already defined`,
|
2019-05-31 15:00:04 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPackage(t *testing.T) {
|
|
|
|
for _, test := range packageTests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2021-03-20 01:36:14 +01:00
|
|
|
GroupFixturePreparers(
|
|
|
|
PrepareForTestWithArchMutator,
|
|
|
|
PrepareForTestWithPackageModule,
|
|
|
|
test.fs.AddToFixture(),
|
|
|
|
).
|
2021-03-17 00:45:22 +01:00
|
|
|
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
|
2021-03-20 01:36:14 +01:00
|
|
|
RunTest(t)
|
2019-05-31 15:00:04 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|