diff options
author | 2019-05-31 14:00:04 +0100 | |
---|---|---|
committer | 2019-06-27 13:24:50 +0100 | |
commit | e2453c705f9f49b72d5bf1caded4b979a1bae00d (patch) | |
tree | 468e4d91ebb95661c01b60f87ef79f9b529455df /android/package_test.go | |
parent | bf46d96c609480d3c81dc4aae6a0c4fb26e90b01 (diff) |
Allow default visibility to be set per package
Adds a package module type with a default_visibility property. The
package module type can only be specified once per package.
Bug: 133290645
Test: m droid
Change-Id: Ibb2fb499c9ea88ecaa662d3cd2cbde478e4b9a4b
Diffstat (limited to 'android/package_test.go')
-rw-r--r-- | android/package_test.go | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/android/package_test.go b/android/package_test.go new file mode 100644 index 000000000..f1f47acb4 --- /dev/null +++ b/android/package_test.go @@ -0,0 +1,111 @@ +package android + +import ( + "io/ioutil" + "os" + "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: mutated field name cannot be set in a Blueprint file`, + `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": package {...} specified multiple times`, + }, + }, +} + +func TestPackage(t *testing.T) { + buildDir, err := ioutil.TempDir("", "soong_package_test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(buildDir) + + for _, test := range packageTests { + t.Run(test.name, func(t *testing.T) { + _, errs := testPackage(buildDir, 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(buildDir string, fs map[string][]byte) (*TestContext, []error) { + + // Create a new config per test as visibility information is stored in the config. + config := TestArchConfig(buildDir, nil) + + ctx := NewTestArchContext() + ctx.RegisterModuleType("package", ModuleFactoryAdaptor(PackageFactory)) + ctx.PreArchMutators(registerPackageRenamer) + ctx.Register() + + ctx.MockFileSystem(fs) + + _, errs := ctx.ParseBlueprintsFiles(".") + if len(errs) > 0 { + return ctx, errs + } + + _, errs = ctx.PrepareBuildActions(config) + return ctx, errs +} |