platform_build_soong/android/package_test.go
Jerome Gaillard df98d3e4a5 Revert "Add ability to declare licenses in soong."
Revert submission 1377717-metalics

Reason for revert: This has broken renderscript_mac target for aosp-master, see b/176909442

Reverted Changes:
I26ac54ca9:Define the standard license_kind rules.
I656486070:Export soong license data to make.
If9d661dfc:Export soong license data to make.
I97943de53:Add ability to declare licenses in soong.
Icaff40171:Rough-in license metadata support to make.
Ib8e538bd0:Add variables for notice deps, license kinds etc.

Change-Id: Iddf5468e0175831ddb642011f2768f87a5e4fcf2
2021-01-06 19:00:05 +00:00

100 lines
2.3 KiB
Go

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"],
}`),
},
expectedErrors: []string{
`top/Blueprints:3:10: unrecognized property "name"`,
`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"],
}
package {
}`),
},
expectedErrors: []string{
`module "//top" already defined`,
},
},
}
func TestPackage(t *testing.T) {
for _, test := range packageTests {
t.Run(test.name, func(t *testing.T) {
_, errs := testPackage(test.fs)
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)
}
}
}
})
}
}
func testPackage(fs map[string][]byte) (*TestContext, []error) {
// Create a new config per test as visibility information is stored in the config.
config := TestArchConfig(buildDir, nil, "", fs)
ctx := NewTestArchContext(config)
RegisterPackageBuildComponents(ctx)
ctx.Register()
_, errs := ctx.ParseBlueprintsFiles(".")
if len(errs) > 0 {
return ctx, errs
}
_, errs = ctx.PrepareBuildActions(config)
return ctx, errs
}