Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 1 | package android |
| 2 | |
| 3 | import ( |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | var packageTests = []struct { |
| 8 | name string |
Paul Duffin | a9237b6 | 2021-03-16 23:45:22 +0000 | [diff] [blame] | 9 | fs MockFS |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 10 | 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 Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 20 | licenses: ["license"], |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 21 | }`), |
| 22 | }, |
| 23 | expectedErrors: []string{ |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 24 | `top/Blueprints:5:14: unrecognized property "licenses"`, |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 25 | `top/Blueprints:3:10: unrecognized property "name"`, |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 26 | `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 Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 49 | default_applicable_licenses: ["license"], |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 52 | package { |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 53 | }`), |
| 54 | }, |
| 55 | expectedErrors: []string{ |
Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 56 | `module "//top" already defined`, |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 57 | }, |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | func TestPackage(t *testing.T) { |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 62 | for _, test := range packageTests { |
| 63 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame^] | 64 | GroupFixturePreparers( |
| 65 | PrepareForTestWithArchMutator, |
| 66 | PrepareForTestWithPackageModule, |
| 67 | test.fs.AddToFixture(), |
| 68 | ). |
Paul Duffin | a9237b6 | 2021-03-16 23:45:22 +0000 | [diff] [blame] | 69 | ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)). |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame^] | 70 | RunTest(t) |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 71 | }) |
| 72 | } |
| 73 | } |