英文:
go test in complex folder structure
问题
我正在使用golang构建一个设计模式的代码库。为了运行所有的测试,我使用了这个bash脚本。它可以正常工作。
#!/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
它可以正常工作:
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
但是,如果我尝试将更多的目录发送给go test
,我会收到这个消息:"named files must all be in one directory; have creational/pool/ and creational/factory/"。这就是我创建这个bash脚本的原因。
有没有可能用一个单一的命令测试所有的文件夹?
英文:
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
得分: 4
使用...
有什么问题?将目录更改为creational
,然后执行以下命令:
go test ./...
这将递归到所有子文件夹并执行找到的所有包的测试。有关详细信息,请参阅这里和这里。
注意:从1.9版本开始,如果使用./...
,则不会匹配vendor
子文件夹中的包。来源:Go 1.9发布说明-使用./...进行供应商匹配。在Go 1.9之前,go test ./...
也会进入vendor
子文件夹并运行供应商包的测试。
英文:
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 https://stackoverflow.com/questions/42972827/difference-in-output-when-calling-go-test-with-package/42973175#42973175; and https://stackoverflow.com/questions/39012108/how-do-you-run-go-test-when-test-files-are-within-a-module/39012546#39012546
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论