gotestsum icon indicating copy to clipboard operation
gotestsum copied to clipboard

How to auto install

Open onattech opened this issue 2 years ago • 3 comments

Hi, How can I get gotestsum to be a dependency in a project or get it auto installed. I don't want to tell the user to manually install it. Thank you

onattech avatar Jan 22 '23 13:01 onattech

Interesting question!

One option is something like this: https://play-with-go.dev/tools-as-dependencies_go119_en/. You can include it as an import in a project, but I guess that requires that someone run using go run gotest.tools/gotestsum, instead of simply gotestsum.

If you use a Makefile or some other tool for project tasks, you could include go install gotest.tools/gotestsum@latest to get it installed.

A third option, which is pretty unconventional, is something like #151, where you run go run ./test instead of go test, and that runs the tests with gotestsum.

dnephin avatar Jan 22 '23 17:01 dnephin

Thank you for your reply. It turns out I am familiar with the first option. Gqlgen for graphql uses it. I'll probably go with the second option since there is a Makefile to install other dependencies.

onattech avatar Jan 22 '23 18:01 onattech

I learned about another option which should work like "auto install". You can run go tools like this without then being in the go.mod file:

go run gotest.tools/gotestsum@latest [gotestsum flags]

If the module already exists in $GOPATH/pkg/mod/... it will run it. It the source isn't available locally it will download the source, compile, and run.

gotestsum has very few dependencies, so it doesn't take long to download and compile on the fly like this.

dnephin avatar Apr 19 '23 20:04 dnephin