My source files tree is like this:
/src
/pkg
/foo
foo.go
foo_test.go
Inside foo.go
:
package foo
func bar(n int) {
...
}
inside foo_test.go
:
package foo
func testBar(t *testing.T) {
bar(10)
...
}
My questions are:
- Does package name relates to directory name, source file name?
- If there is only one source file for a package, need I put it in a directory?
- Should I put
foo.go
andfoo_test.go
in the same package? - In the
foo_test.go
, as it's in the same package asfoo.go
, I didn't importfoo
. But when I compilefoo_test.go
with 6g, it saysbar() is undefined
. What should I do?