| 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 |  | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 24 | func runLinkerConfigTestCase(t *testing.T, tc Bp2buildTestCase) { | 
| Liz Kammer | 45faf8f | 2022-06-02 16:00:54 -0400 | [diff] [blame] | 25 | t.Helper() | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 26 | (&tc).ModuleTypeUnderTest = "linker_config" | 
|  | 27 | (&tc).ModuleTypeUnderTestFactory = linkerconfig.LinkerConfigFactory | 
| Trevor Radcliffe | 1b4b2d9 | 2022-09-01 18:57:01 +0000 | [diff] [blame] | 28 | RunBp2BuildTestCaseSimple(t, tc) | 
| Liz Kammer | 45faf8f | 2022-06-02 16:00:54 -0400 | [diff] [blame] | 29 | } | 
|  | 30 |  | 
|  | 31 | func TestLinkerConfigConvertsSrc(t *testing.T) { | 
|  | 32 | runLinkerConfigTestCase(t, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 33 | Bp2buildTestCase{ | 
|  | 34 | Blueprint: ` | 
| Liz Kammer | 45faf8f | 2022-06-02 16:00:54 -0400 | [diff] [blame] | 35 | linker_config { | 
|  | 36 | name: "foo", | 
|  | 37 | src: "a.json", | 
|  | 38 | } | 
|  | 39 | `, | 
| Alix | e06d75b | 2022-08-31 18:28:19 +0000 | [diff] [blame] | 40 | ExpectedBazelTargets: []string{MakeBazelTarget("linker_config", "foo", AttrNameToString{ | 
| Liz Kammer | 45faf8f | 2022-06-02 16:00:54 -0400 | [diff] [blame] | 41 | "src": `"a.json"`, | 
|  | 42 | })}, | 
|  | 43 | }) | 
|  | 44 |  | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | func TestLinkerConfigNoSrc(t *testing.T) { | 
|  | 48 | runLinkerConfigTestCase(t, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 49 | Bp2buildTestCase{ | 
|  | 50 | Blueprint: ` | 
| Liz Kammer | 45faf8f | 2022-06-02 16:00:54 -0400 | [diff] [blame] | 51 | linker_config { | 
|  | 52 | name: "foo", | 
|  | 53 | } | 
|  | 54 | `, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 55 | ExpectedBazelTargets: []string{}, | 
|  | 56 | ExpectedErr:          fmt.Errorf("Android.bp:2:1: module \"foo\": src: empty src is not supported"), | 
| Liz Kammer | 45faf8f | 2022-06-02 16:00:54 -0400 | [diff] [blame] | 57 | }) | 
|  | 58 |  | 
|  | 59 | } |