go test in complex folder structure

巧了我就是萌 提交于 2021-01-27 13:32:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/46263599/go-test-in-complex-folder-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!