To use package properly, how to arrange directory, file name, unit test file?
Posted
by Stephen Hsu
on Stack Overflow
See other posts from Stack Overflow
or by Stephen Hsu
Published on 2010-02-02T07:32:59Z
Indexed on
2010/03/19
16:01 UTC
Read the original article
Hit count: 189
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 and foo_test.go in the same package?
- In the foo_test.go, as it's in the same package as foo.go, I didn't import foo. But when I compile foo_test.go with 6g, it says bar() is undefined. What should I do?
© Stack Overflow or respective owner