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 15package bp2build 16 17import ( 18 "fmt" 19 "testing" 20 21 "android/soong/linkerconfig" 22) 23 24func 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 31func TestLinkerConfigConvertsSrc(t *testing.T) { 32 runLinkerConfigTestCase(t, 33 Bp2buildTestCase{ 34 Blueprint: ` 35linker_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 47func TestLinkerConfigNoSrc(t *testing.T) { 48 runLinkerConfigTestCase(t, 49 Bp2buildTestCase{ 50 Blueprint: ` 51linker_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} 60