| 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 | { | 
| Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 14 | name: "package must not accept visibility, name or licenses properties", | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 15 | fs: map[string][]byte{ | 
| Lukacs T. Berki | b838b0a | 2021-09-02 11:46:24 +0200 | [diff] [blame] | 16 | "top/Android.bp": []byte(` | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 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{ | 
| Lukacs T. Berki | b838b0a | 2021-09-02 11:46:24 +0200 | [diff] [blame] | 24 | `top/Android.bp:5:14: unrecognized property "licenses"`, | 
|  | 25 | `top/Android.bp:3:10: unrecognized property "name"`, | 
|  | 26 | `top/Android.bp:4:16: unrecognized property "visibility"`, | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 27 | }, | 
|  | 28 | }, | 
|  | 29 | { | 
|  | 30 | name: "multiple packages in separate directories", | 
|  | 31 | fs: map[string][]byte{ | 
| Lukacs T. Berki | b838b0a | 2021-09-02 11:46:24 +0200 | [diff] [blame] | 32 | "top/Android.bp": []byte(` | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 33 | package { | 
|  | 34 | }`), | 
| Lukacs T. Berki | b838b0a | 2021-09-02 11:46:24 +0200 | [diff] [blame] | 35 | "other/Android.bp": []byte(` | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 36 | package { | 
|  | 37 | }`), | 
| Lukacs T. Berki | b838b0a | 2021-09-02 11:46:24 +0200 | [diff] [blame] | 38 | "other/nested/Android.bp": []byte(` | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 39 | package { | 
|  | 40 | }`), | 
|  | 41 | }, | 
|  | 42 | }, | 
|  | 43 | { | 
|  | 44 | name: "package must not be specified more than once per package", | 
|  | 45 | fs: map[string][]byte{ | 
| Lukacs T. Berki | b838b0a | 2021-09-02 11:46:24 +0200 | [diff] [blame] | 46 | "top/Android.bp": []byte(` | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 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 | } | 
| Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 51 | package { | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 52 | }`), | 
|  | 53 | }, | 
|  | 54 | expectedErrors: []string{ | 
| Paul Duffin | cdfcec9 | 2020-05-01 11:57:12 +0100 | [diff] [blame] | 55 | `module "//top" already defined`, | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 56 | }, | 
|  | 57 | }, | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | func TestPackage(t *testing.T) { | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 61 | for _, test := range packageTests { | 
|  | 62 | t.Run(test.name, func(t *testing.T) { | 
| Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 63 | GroupFixturePreparers( | 
|  | 64 | PrepareForTestWithArchMutator, | 
|  | 65 | PrepareForTestWithPackageModule, | 
|  | 66 | test.fs.AddToFixture(), | 
|  | 67 | ). | 
| Paul Duffin | a9237b6 | 2021-03-16 23:45:22 +0000 | [diff] [blame] | 68 | ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)). | 
| Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 69 | RunTest(t) | 
| Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 70 | }) | 
|  | 71 | } | 
|  | 72 | } |