Liz Kammer | 45faf8f | 2022-06-02 16:00:54 -0400 | [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 | "fmt" |
| 19 | "testing" |
| 20 | |
| 21 | "android/soong/linkerconfig" |
| 22 | ) |
| 23 | |
| 24 | func runLinkerConfigTestCase(t *testing.T, tc bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | (&tc).moduleTypeUnderTest = "linker_config" |
| 27 | (&tc).moduleTypeUnderTestFactory = linkerconfig.LinkerConfigFactory |
| 28 | runBp2BuildTestCaseSimple(t, tc) |
| 29 | } |
| 30 | |
| 31 | func TestLinkerConfigConvertsSrc(t *testing.T) { |
| 32 | runLinkerConfigTestCase(t, |
| 33 | bp2buildTestCase{ |
| 34 | blueprint: ` |
| 35 | linker_config { |
| 36 | name: "foo", |
| 37 | src: "a.json", |
| 38 | } |
| 39 | `, |
| 40 | expectedBazelTargets: []string{makeBazelTarget("linker_config", "foo", attrNameToString{ |
| 41 | "src": `"a.json"`, |
| 42 | })}, |
| 43 | }) |
| 44 | |
| 45 | } |
| 46 | |
| 47 | func TestLinkerConfigNoSrc(t *testing.T) { |
| 48 | runLinkerConfigTestCase(t, |
| 49 | bp2buildTestCase{ |
| 50 | blueprint: ` |
| 51 | linker_config { |
| 52 | name: "foo", |
| 53 | } |
| 54 | `, |
| 55 | expectedBazelTargets: []string{}, |
| 56 | expectedErr: fmt.Errorf("Android.bp:2:1: module \"foo\": src: empty src is not supported"), |
| 57 | }) |
| 58 | |
| 59 | } |