Sasha Smundak | a93c62b | 2022-09-14 13:40:03 -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 registerLicenseKindModuleTypes(_ android.RegistrationContext) {} |
| 23 | |
| 24 | func TestLicenseKindBp2Build(t *testing.T) { |
| 25 | tests := []struct { |
| 26 | description string |
| 27 | module string |
| 28 | expected ExpectedRuleTarget |
| 29 | }{ |
| 30 | { |
| 31 | description: "license_kind", |
| 32 | module: ` |
| 33 | license_kind { |
| 34 | name: "my_license", |
| 35 | conditions: [ |
| 36 | "by_exception_only", |
| 37 | "not_allowed", |
| 38 | ], |
| 39 | url: "https://spdx.org/licenses/0BSD", |
| 40 | visibility: ["//visibility:public"], |
| 41 | }`, |
| 42 | expected: ExpectedRuleTarget{ |
| 43 | "license_kind", |
| 44 | "my_license", |
| 45 | AttrNameToString{ |
| 46 | "conditions": `[ |
| 47 | "by_exception_only", |
| 48 | "not_allowed", |
| 49 | ]`, |
| 50 | "url": `"https://spdx.org/licenses/0BSD"`, |
| 51 | "visibility": `["//visibility:public"]`, |
| 52 | }, |
| 53 | android.HostAndDeviceDefault, |
| 54 | }, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | for _, test := range tests { |
| 59 | RunBp2BuildTestCase(t, |
| 60 | registerLicenseKindModuleTypes, |
| 61 | Bp2buildTestCase{ |
| 62 | Description: test.description, |
| 63 | ModuleTypeUnderTest: "license_kind", |
| 64 | ModuleTypeUnderTestFactory: android.LicenseKindFactory, |
| 65 | Blueprint: test.module, |
| 66 | ExpectedBazelTargets: []string{test.expected.String()}, |
| 67 | }) |
| 68 | } |
| 69 | } |