2019-05-31 15:00:04 +02:00
|
|
|
package android
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var packageTests = []struct {
|
|
|
|
name string
|
|
|
|
fs map[string][]byte
|
|
|
|
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{
|
|
|
|
"top/Blueprints": []byte(`
|
|
|
|
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-01-07 04:34:31 +01:00
|
|
|
`top/Blueprints:5:14: unrecognized property "licenses"`,
|
2020-05-01 12:57:12 +02:00
|
|
|
`top/Blueprints:3:10: unrecognized property "name"`,
|
2019-05-31 15:00:04 +02:00
|
|
|
`top/Blueprints:4:16: unrecognized property "visibility"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple packages in separate directories",
|
|
|
|
fs: map[string][]byte{
|
|
|
|
"top/Blueprints": []byte(`
|
|
|
|
package {
|
|
|
|
}`),
|
|
|
|
"other/Blueprints": []byte(`
|
|
|
|
package {
|
|
|
|
}`),
|
|
|
|
"other/nested/Blueprints": []byte(`
|
|
|
|
package {
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "package must not be specified more than once per package",
|
|
|
|
fs: map[string][]byte{
|
|
|
|
"top/Blueprints": []byte(`
|
|
|
|
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) {
|
2019-07-02 20:31:37 +02:00
|
|
|
_, errs := testPackage(test.fs)
|
2019-05-31 15:00:04 +02:00
|
|
|
|
|
|
|
expectedErrors := test.expectedErrors
|
|
|
|
if expectedErrors == nil {
|
|
|
|
FailIfErrored(t, errs)
|
|
|
|
} else {
|
|
|
|
for _, expectedError := range expectedErrors {
|
|
|
|
FailIfNoMatchingErrors(t, expectedError, errs)
|
|
|
|
}
|
|
|
|
if len(errs) > len(expectedErrors) {
|
|
|
|
t.Errorf("additional errors found, expected %d, found %d", len(expectedErrors), len(errs))
|
|
|
|
for i, expectedError := range expectedErrors {
|
|
|
|
t.Errorf("expectedErrors[%d] = %s", i, expectedError)
|
|
|
|
}
|
|
|
|
for i, err := range errs {
|
|
|
|
t.Errorf("errs[%d] = %s", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 20:31:37 +02:00
|
|
|
func testPackage(fs map[string][]byte) (*TestContext, []error) {
|
2019-05-31 15:00:04 +02:00
|
|
|
|
|
|
|
// Create a new config per test as visibility information is stored in the config.
|
2019-12-14 05:41:13 +01:00
|
|
|
config := TestArchConfig(buildDir, nil, "", fs)
|
2019-05-31 15:00:04 +02:00
|
|
|
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx := NewTestArchContext(config)
|
2020-01-14 13:15:29 +01:00
|
|
|
RegisterPackageBuildComponents(ctx)
|
2020-10-30 01:09:13 +01:00
|
|
|
ctx.Register()
|
2019-05-31 15:00:04 +02:00
|
|
|
|
|
|
|
_, errs := ctx.ParseBlueprintsFiles(".")
|
|
|
|
if len(errs) > 0 {
|
|
|
|
return ctx, errs
|
|
|
|
}
|
|
|
|
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
return ctx, errs
|
|
|
|
}
|