- 0 Posts
- 8 Comments
This is a two for one deal then
Your specific question is answered here: https://www.sobyte.net/post/2023-04/go-test-path-main/.
Well, here’s the problem! This _testmain.go is the main package of the test executable generated by go test, and it now imports a “main” package, which is not allowed in Go.
Generally this is easily solved by moving the code you are testing to a package for example
pkg/todo.goandpkg/todo_test.goor utility or whatever.Finally if you look at that link i sent they recommend not testing main in exactly the way you are testing it. One negative of the way you are testing it is you aren’t really unit testing – every time you run main_test you compile main, this is a little unusual.
this might have some answers https://go-cloud-native.com/golang/test-the-main-function-in-go, hard to verify without a repo, also recommend you post the commands you run when seeking help.
how are you running tests (try
go test ./...)? Mostly basing this on https://stackoverflow.com/questions/31352239/how-to-test-the-main-package-functions
I don’t actually care, but when I have in the past (around 2006 era) it “just worked”, while other distros i was using required more hand holding (gentoo, redhat, slackware). I suspect most distros are just fine now a days (using debian now and it seems just fine).
I am not currently using it but it’s always been fine whenever I have. What’s broken?




How about “the mountain in the sea” by ray nayler? I actually have liked everything ive read by him. Not quite like anathem which really I should go back and reread- that book is fantastic