I have a main.go
and main_test.go
, and go test
works fine:
$ cat main.go
package main
func main() {}
func F() int { return 1 }
$ cat main_test.go
package main
import "testing"
func TestF(t *testing.T) {
if F() != 1 {
t.Fatalf("error")
}
}
From link1 and link2, I could use package main_test
in main_test.go
. But go test
shows ./main_test.go:6:5: undefined: F
. How to fix the error?