Sasha Smundak | 9d2f174 | 2022-08-04 13:28:38 -0700 | [diff] [blame] | 1 | // Copyright 2022 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func registerLicenseModuleTypes(_ android.RegistrationContext) {} |
| 23 | |
| 24 | func TestLicenseBp2Build(t *testing.T) { |
| 25 | tests := []struct { |
| 26 | description string |
| 27 | module string |
| 28 | expected ExpectedRuleTarget |
| 29 | }{ |
| 30 | { |
| 31 | description: "license kind and text notice", |
| 32 | module: ` |
| 33 | license { |
| 34 | name: "my_license", |
| 35 | license_kinds: [ "SPDX-license-identifier-Apache-2.0"], |
| 36 | license_text: [ "NOTICE"], |
| 37 | }`, |
| 38 | expected: ExpectedRuleTarget{ |
| 39 | "android_license", |
| 40 | "my_license", |
| 41 | AttrNameToString{ |
| 42 | "license_kinds": `["SPDX-license-identifier-Apache-2.0"]`, |
| 43 | "license_text": `"NOTICE"`, |
| 44 | }, |
| 45 | android.HostAndDeviceDefault, |
| 46 | }, |
| 47 | }, |
| 48 | { |
| 49 | description: "visibility, package_name, copyright_notice", |
| 50 | module: ` |
| 51 | license { |
| 52 | name: "my_license", |
| 53 | package_name: "my_package", |
| 54 | visibility: [":__subpackages__"], |
| 55 | copyright_notice: "Copyright © 2022", |
| 56 | }`, |
| 57 | expected: ExpectedRuleTarget{ |
| 58 | "android_license", |
| 59 | "my_license", |
| 60 | AttrNameToString{ |
| 61 | "copyright_notice": `"Copyright © 2022"`, |
| 62 | "package_name": `"my_package"`, |
| 63 | "visibility": `[":__subpackages__"]`, |
| 64 | }, |
| 65 | android.HostAndDeviceDefault, |
| 66 | }, |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | for _, test := range tests { |
| 71 | RunBp2BuildTestCase(t, |
| 72 | registerLicenseModuleTypes, |
| 73 | Bp2buildTestCase{ |
| 74 | Description: test.description, |
| 75 | ModuleTypeUnderTest: "license", |
| 76 | ModuleTypeUnderTestFactory: android.LicenseFactory, |
| 77 | Blueprint: test.module, |
| 78 | ExpectedBazelTargets: []string{test.expected.String()}, |
| 79 | }) |
| 80 | } |
| 81 | } |