move golang tests to its own directory
this prepares for more test binaries.
This commit is contained in:
23
test/go/BUILD
Normal file
23
test/go/BUILD
Normal 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
14
test/go/hello.go
Normal 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
13
test/go/hello_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user