blob: 5e7bcd440b03ac6555550993caa8551077922abc [file] [log] [blame]
Liz Kammer45faf8f2022-06-02 16:00:54 -04001// 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
Sam Delmerico3177a6e2022-06-21 19:28:33 +000024func runLinkerConfigTestCase(t *testing.T, tc Bp2buildTestCase) {
Liz Kammer45faf8f2022-06-02 16:00:54 -040025 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000026 (&tc).ModuleTypeUnderTest = "linker_config"
27 (&tc).ModuleTypeUnderTestFactory = linkerconfig.LinkerConfigFactory
Trevor Radcliffe1b4b2d92022-09-01 18:57:01 +000028 RunBp2BuildTestCaseSimple(t, tc)
Liz Kammer45faf8f2022-06-02 16:00:54 -040029}
30
31func TestLinkerConfigConvertsSrc(t *testing.T) {
32 runLinkerConfigTestCase(t,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000033 Bp2buildTestCase{
34 Blueprint: `
Liz Kammer45faf8f2022-06-02 16:00:54 -040035linker_config {
36 name: "foo",
37 src: "a.json",
38}
39`,
Alixe06d75b2022-08-31 18:28:19 +000040 ExpectedBazelTargets: []string{MakeBazelTarget("linker_config", "foo", AttrNameToString{
Liz Kammer45faf8f2022-06-02 16:00:54 -040041 "src": `"a.json"`,
42 })},
43 })
44
45}
46
47func TestLinkerConfigNoSrc(t *testing.T) {
48 runLinkerConfigTestCase(t,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000049 Bp2buildTestCase{
50 Blueprint: `
Liz Kammer45faf8f2022-06-02 16:00:54 -040051linker_config {
52 name: "foo",
53}
54`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000055 ExpectedBazelTargets: []string{},
56 ExpectedErr: fmt.Errorf("Android.bp:2:1: module \"foo\": src: empty src is not supported"),
Liz Kammer45faf8f2022-06-02 16:00:54 -040057 })
58
59}