I have following code under package pack1. Name of file is pack1.go
package pack1
var Pack1Int int = 42
var pack1Float = 3.14
func ReturnStr() string {
return "Hello world!"
}
And following code in main program. Name of file is package_test.go
package main
import (
"fmt"
"./pack1"
)
func main() {
var test1 string
test1 = pack1.ReturnStr()
fmt.Printf("Return string from pack1 : %s
", test1)
fmt.Printf("Integer from pack1 : %d
", pack1.Pack1Int)
}
When I try to run it with command go run package_test.go
I get following error:
go run: cannot run *_test.go files (package_test.go)
But if I rename file to abc.go
then I am getting proper output i.e.
Return string from pack1 : Hello world!
Integer from pack1 : 42
I am curious about what is wrong with using package_test.go
as file name.
For code with only main package this name is working fine.
Is this a bug in Go or I am doing something wrong ?