blob: 3bd30cc930a1d0ab3d99a96bbcc71b3f77dd9635 [file] [log] [blame]
Paul Duffine2453c72019-05-31 14:00:04 +01001package android
2
3import (
Paul Duffine2453c72019-05-31 14:00:04 +01004 "testing"
5)
6
7var packageTests = []struct {
8 name string
Paul Duffina9237b62021-03-16 23:45:22 +00009 fs MockFS
Paul Duffine2453c72019-05-31 14:00:04 +010010 expectedErrors []string
11}{
12 // Package default_visibility handling is tested in visibility_test.go
13 {
14 name: "package must not accept visibility and name properties",
15 fs: map[string][]byte{
16 "top/Blueprints": []byte(`
17 package {
18 name: "package",
19 visibility: ["//visibility:private"],
Bob Badour37af0462021-01-07 03:34:31 +000020 licenses: ["license"],
Paul Duffine2453c72019-05-31 14:00:04 +010021 }`),
22 },
23 expectedErrors: []string{
Bob Badour37af0462021-01-07 03:34:31 +000024 `top/Blueprints:5:14: unrecognized property "licenses"`,
Paul Duffincdfcec92020-05-01 11:57:12 +010025 `top/Blueprints:3:10: unrecognized property "name"`,
Paul Duffine2453c72019-05-31 14:00:04 +010026 `top/Blueprints:4:16: unrecognized property "visibility"`,
27 },
28 },
29 {
30 name: "multiple packages in separate directories",
31 fs: map[string][]byte{
32 "top/Blueprints": []byte(`
33 package {
34 }`),
35 "other/Blueprints": []byte(`
36 package {
37 }`),
38 "other/nested/Blueprints": []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/Blueprints": []byte(`
47 package {
48 default_visibility: ["//visibility:private"],
Bob Badour37af0462021-01-07 03:34:31 +000049 default_applicable_licenses: ["license"],
Paul Duffine2453c72019-05-31 14:00:04 +010050 }
51
Bob Badour37af0462021-01-07 03:34:31 +000052 package {
Paul Duffine2453c72019-05-31 14:00:04 +010053 }`),
54 },
55 expectedErrors: []string{
Paul Duffincdfcec92020-05-01 11:57:12 +010056 `module "//top" already defined`,
Paul Duffine2453c72019-05-31 14:00:04 +010057 },
58 },
59}
60
61func TestPackage(t *testing.T) {
Paul Duffine2453c72019-05-31 14:00:04 +010062 for _, test := range packageTests {
63 t.Run(test.name, func(t *testing.T) {
Paul Duffin30ac3e72021-03-20 00:36:14 +000064 GroupFixturePreparers(
65 PrepareForTestWithArchMutator,
66 PrepareForTestWithPackageModule,
67 test.fs.AddToFixture(),
68 ).
Paul Duffina9237b62021-03-16 23:45:22 +000069 ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
Paul Duffin30ac3e72021-03-20 00:36:14 +000070 RunTest(t)
Paul Duffine2453c72019-05-31 14:00:04 +010071 })
72 }
73}