blob: 65c424013b823bade58796725a423aa69805886d [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 {
Ustaeabf0f32021-12-06 15:17:23 -050014 name: "package must not accept visibility, name or licenses properties",
Paul Duffine2453c72019-05-31 14:00:04 +010015 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020016 "top/Android.bp": []byte(`
Paul Duffine2453c72019-05-31 14:00:04 +010017 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{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020024 `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 Duffine2453c72019-05-31 14:00:04 +010027 },
28 },
29 {
30 name: "multiple packages in separate directories",
31 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020032 "top/Android.bp": []byte(`
Paul Duffine2453c72019-05-31 14:00:04 +010033 package {
34 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020035 "other/Android.bp": []byte(`
Paul Duffine2453c72019-05-31 14:00:04 +010036 package {
37 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020038 "other/nested/Android.bp": []byte(`
Paul Duffine2453c72019-05-31 14:00:04 +010039 package {
40 }`),
41 },
42 },
43 {
44 name: "package must not be specified more than once per package",
45 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020046 "top/Android.bp": []byte(`
Paul Duffine2453c72019-05-31 14:00:04 +010047 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 }
Ustaeabf0f32021-12-06 15:17:23 -050051 package {
Paul Duffine2453c72019-05-31 14:00:04 +010052 }`),
53 },
54 expectedErrors: []string{
Paul Duffincdfcec92020-05-01 11:57:12 +010055 `module "//top" already defined`,
Paul Duffine2453c72019-05-31 14:00:04 +010056 },
57 },
58}
59
60func TestPackage(t *testing.T) {
Paul Duffine2453c72019-05-31 14:00:04 +010061 for _, test := range packageTests {
62 t.Run(test.name, func(t *testing.T) {
Paul Duffin30ac3e72021-03-20 00:36:14 +000063 GroupFixturePreparers(
64 PrepareForTestWithArchMutator,
65 PrepareForTestWithPackageModule,
66 test.fs.AddToFixture(),
67 ).
Paul Duffina9237b62021-03-16 23:45:22 +000068 ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
Paul Duffin30ac3e72021-03-20 00:36:14 +000069 RunTest(t)
Paul Duffine2453c72019-05-31 14:00:04 +010070 })
71 }
72}