blob: 91bba541d557d879280fbaff0f56de22999d4948 [file] [log] [blame]
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +00001// Copyright 2021 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 (
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020018 "testing"
19
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +000020 "android/soong/android"
21 "android/soong/sh"
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +000022)
23
24func TestShBinaryLoadStatement(t *testing.T) {
25 testCases := []struct {
26 bazelTargets BazelTargets
27 expectedLoadStatements string
28 }{
29 {
30 bazelTargets: BazelTargets{
31 BazelTarget{
32 name: "sh_binary_target",
33 ruleClass: "sh_binary",
34 // Note: no bzlLoadLocation for native rules
35 // TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules?
36 },
37 },
38 expectedLoadStatements: ``,
39 },
40 }
41
42 for _, testCase := range testCases {
43 actual := testCase.bazelTargets.LoadStatements()
44 expected := testCase.expectedLoadStatements
45 if actual != expected {
46 t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
47 }
48 }
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +000049}
50
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020051func runShBinaryTestCase(t *testing.T, tc bp2buildTestCase) {
52 runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
53}
54
55func TestShBinarySimple(t *testing.T) {
56 runShBinaryTestCase(t, bp2buildTestCase{
57 description: "sh_binary test",
58 moduleTypeUnderTest: "sh_binary",
59 moduleTypeUnderTestFactory: sh.ShBinaryFactory,
60 moduleTypeUnderTestBp2BuildMutator: sh.ShBinaryBp2Build,
61 blueprint: `sh_binary {
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +000062 name: "foo",
63 src: "foo.sh",
64 bazel_module: { bp2build_available: true },
65}`,
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020066 expectedBazelTargets: []string{`sh_binary(
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +000067 name = "foo",
Jingwen Chenb4628eb2021-04-08 14:40:57 +000068 srcs = ["foo.sh"],
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +000069)`},
Lukacs T. Berkic1cc3b92021-05-21 09:37:00 +020070 })
Rupert Shuttleworthfb97fde2021-02-11 03:40:05 +000071}