Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run tests for all go modules in subfolders

Tags:

go

I've created the following directory tree with utilities to work with git.

./git-logbranch/git-logbranch_test.go
./git-logbranch/git-logbranch.go
./git-logbranch/go.mod
./git-issue/git-issue_test.go
./git-issue/go.mod
./git-issue/git-issue.go
./main.go
./go.mod

I've read several posts that say './...' will automatically run tests in all sub-folders, but it in fact does not do so. This is what I'm running and the output I get:

$ go test ./...
?       main    [no test files]

Here's some example output from the subfolders. As you can see, the individual tests work:

$ go test ./...
ok      git_logbranch   0.001s

$ go test ./...
ok      git_issue   (cached)

Any ideas on how to run all these tests at once?

like image 434
Trenton D. Adams Avatar asked Sep 06 '25 03:09

Trenton D. Adams


1 Answers

https://github.com/golang/go/wiki/Modules#how-to-define-a-module

When executed from the root directory of a module, the ./... pattern matches all the packages within the current module.

(note: it does not say "within the current directory")

https://golang.org/cmd/go/#hdr-Defining_a_module

The module is the set of all Go packages in the module root and its subdirectories, but excluding subtrees with their own go.mod files.

like image 51
mkopriva Avatar answered Sep 08 '25 00:09

mkopriva