在复杂的文件夹结构中进行测试

I am building a repository of design patterns in golang. To run all tests, I use this bash script. It works.

#!/bin/bash
go test creational/abstract_factory/*.go
go test creational/builder/*.go
go test creational/factory/*.go
go test creational/pool/*.go
go test creational/prototype/*.go
go test creational/singleton/*.go

It works fine:

prompt> ./runtests.sh
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.006s
ok      command-line-arguments  0.005s
ok      command-line-arguments  0.006s

But, ... If I try to send more directory to go test I receive this message "named files must all be in one directory; have creational/pool/ and creational/factory/". This is the reason I've created that bash script.

Is there the possibility to test all folder in one single command?

What's wrong with using the ...? Change directory to creational, then

go test ./...

This will recurse to all subfolders and execute tests of all packages found. For details, see Difference in output when calling go test with package; and How do you run `go test` when test files are within a module?

Note: starting with 1.9, packages in vendor subfolders are not matched if ./... is used. Source: Go 1.9 Release Notes - Vendor matching with ./.... Prior to Go 1.9, go test ./... also went into the vendor subfolder and ran tests of vendored packages.