Skip to content

Commit 07ec991

Browse files
authored
tests/legacy/build_constraints: Split Go asm test into own package (#3652)
The native "go build" tool compiles assembly in a Cgo package with the C compiler, and compiles assembly in a pure Go package with the Go assembler. The build_constraints test previously mixed Go assembler files with Cgo files. This caused the native go test to fail with: package using cgo has Go assembly file asm_linux_amd64.s Splitting this into two separate packages fixes this. This problem was reported in: #2006 This will fix failing tests in my attempt to fix that issue: #3648
1 parent 65ccde4 commit 07ec991

File tree

7 files changed

+43
-21
lines changed

7 files changed

+43
-21
lines changed

tests/legacy/build_constraints/BUILD.bazel

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ go_library(
1616
# Check that tags are observed.
1717
"tag_l.go",
1818
"tag_unknown.go",
19-
# Check that constraints apply to assembly files.
20-
"asm_arm64.s",
21-
"asm_linux_amd64.s",
22-
"asm_unknown.s",
2319
# Check that constraints apply to cgo files.
2420
"cgo_linux.go",
2521
"cgo_unknown.go",

tests/legacy/build_constraints/build_constraints_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,6 @@ func TestTag(t *testing.T) {
2525
check(tag, t)
2626
}
2727

28-
func asm() int
29-
30-
func TestAsm(t *testing.T) {
31-
got := asm()
32-
var want int
33-
if runtime.GOOS == "linux" {
34-
want = 12
35-
} else if runtime.GOARCH == "arm64" {
36-
want = 75
37-
} else {
38-
want = 34
39-
}
40-
if got != want {
41-
t.Errorf("got %d; want %d", got, want)
42-
}
43-
}
44-
4528
func TestCgoGo(t *testing.T) {
4629
check(cgoGo, t)
4730
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_test(
4+
name = "go_default_test",
5+
size = "small",
6+
srcs = ["build_constraints_go_asm_test.go"],
7+
embed = [":go_default_library"],
8+
)
9+
10+
go_library(
11+
name = "go_default_library",
12+
srcs = [
13+
# Check that constraints apply to assembly files.
14+
"asm_arm64.s",
15+
"asm_linux_amd64.s",
16+
"asm_unknown.s",
17+
],
18+
cgo = False,
19+
importpath = "github.com/bazelbuild/rules_go/tests/build_constraints_go_asm",
20+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package build_constraints_go_asm
2+
3+
import (
4+
"runtime"
5+
"testing"
6+
)
7+
8+
func asm() int
9+
10+
func TestAsm(t *testing.T) {
11+
got := asm()
12+
var want int
13+
if runtime.GOOS == "linux" {
14+
want = 12
15+
} else if runtime.GOARCH == "arm64" {
16+
want = 75
17+
} else {
18+
want = 34
19+
}
20+
if got != want {
21+
t.Errorf("got %d; want %d", got, want)
22+
}
23+
}

0 commit comments

Comments
 (0)