~/scratch/boo$ cat boo.go
package main
/*
#include <stdio.h>
int boo_flag;
__attribute__((constructor)) static void init(void) {
printf("boo: %d\n", boo_flag);
}
*/
import "C"
func Helper() int {
return 33;
}
func main() {
}
~/scratch/boo$ cat boo_test.go
package main_test
import "fmt"
import "testing"
import boo "."
func TestBoo(_ *testing.T) {
fmt.Println("test", boo.Helper())
}
~/scratch/boo$ cat boo_1.go
// +build test
package main
// int boo_flag = 1;
import "C"
pedronis@ubuntu-64:~/scratch/boo$ go build .
pedronis@ubuntu-64:~/scratch/boo$ ./boo
boo: 0
pedronis@ubuntu-64:~/scratch/boo$ go test -tags test
boo: 1
test 33
PASS
ok _/home/pedronis/scratch/boo 0.003s