1

move golang tests to its own directory

this prepares for more test binaries.
This commit is contained in:
Motiejus Jakštys
2022-02-03 14:58:05 +02:00
parent 5631c7e2b6
commit ebbf499208
5 changed files with 18 additions and 18 deletions

23
test/go/BUILD Normal file
View File

@@ -0,0 +1,23 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//rules:rules_go.bzl", "go_binary")
go_library(
name = "go_lib",
srcs = ["hello.go"],
cgo = True,
importpath = "git.sr.ht/~motiejus/bazel-zig-cc/test/go",
visibility = ["//visibility:private"],
)
go_binary(
name = "go",
embed = [":go_lib"],
static = "on",
visibility = ["//visibility:public"],
)
go_test(
name = "go_test",
srcs = ["hello_test.go"],
embed = [":go_lib"],
)

14
test/go/hello.go Normal file
View File

@@ -0,0 +1,14 @@
package main
// #include <stdio.h>
// char* hello() { return "hello, world"; }
// void printhello() { printf("%s\n", hello()); }
import "C"
func main() {
C.printhello()
}
func Chello() string {
return C.GoString(C.hello())
}

13
test/go/hello_test.go Normal file
View File

@@ -0,0 +1,13 @@
package main
import (
"testing"
)
func TestHello(t *testing.T) {
want := "hello, world"
got := Chello()
if got != want {
t.Errorf("expected %q, got %q", want, got)
}
}