blob: 9c5b809c193b72f21c5a6d51a2f9edd6ccd472b6 [file] [log] [blame]
Colin Cross1496fb12024-09-09 16:44:10 -07001// Copyright 2024 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 golang
16
17import (
18 "android/soong/android"
Cole Faustd1d08ab2024-10-04 15:29:20 -070019 "regexp"
Colin Cross1496fb12024-09-09 16:44:10 -070020 "testing"
Cole Faustd1d08ab2024-10-04 15:29:20 -070021
22 "github.com/google/blueprint/bootstrap"
Colin Cross1496fb12024-09-09 16:44:10 -070023)
24
25func TestGolang(t *testing.T) {
26 bp := `
27 bootstrap_go_package {
28 name: "gopkg",
29 pkgPath: "test/pkg",
30 }
31
32 blueprint_go_binary {
33 name: "gobin",
34 deps: ["gopkg"],
35 }
36 `
37
38 result := android.GroupFixturePreparers(
39 android.PrepareForTestWithArchMutator,
40 android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
41 RegisterGoModuleTypes(ctx)
42 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
43 ctx.BottomUpBlueprint("bootstrap_deps", bootstrap.BootstrapDeps)
44 })
45 }),
46 ).RunTestWithBp(t, bp)
47
48 bin := result.ModuleForTests("gobin", result.Config.BuildOSTarget.String())
49
Cole Faustd1d08ab2024-10-04 15:29:20 -070050 expected := "^out/soong/host/" + result.Config.PrebuiltOS() + "/bin/go/gobin/?[^/]*/obj/gobin$"
51 actual := android.PathsRelativeToTop(bin.OutputFiles(result.TestContext, t, ""))
52 if len(actual) != 1 {
53 t.Fatalf("Expected 1 output file, got %v", actual)
54 }
55 if match, err := regexp.Match(expected, []byte(actual[0])); err != nil || !match {
56 t.Fatalf("Expected output file to match %q, but got %q", expected, actual[0])
57 }
Colin Cross1496fb12024-09-09 16:44:10 -070058}