在运行"go test"时如何排除或跳过特定目录 [英] How to exclude or skip specific directory while running 'go test'

查看:1543
本文介绍了在运行"go test"时如何排除或跳过特定目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

go test $(go list ./... | grep -v /vendor/) -coverprofile .testCoverage.txt

我正在使用上面的命令来测试文件,但是我想从测试中排除1个名为"Store"的文件夹.怎么做?

I am using the above command to test the files but there is 1 folder with the name "Store" that I want to exclude from tests. How it can be done?

推荐答案

您已经在做

$(go list ./... | grep -v /vendor/)

grep -v /vendor/部分将排除/vendor/目录.因此,只需对您的Store目录执行相同操作:

The grep -v /vendor/ part is to exclude the /vendor/ directory. So just do the same for your Store directory:

go test $(go list ./... | grep -v /Store/) -coverprofile .testCoverage.txt

请注意,不必用这种方式排除/vendor/(除非您使用的是Go的真正旧版本).如果您使用的是旧版的Go,可以将它们组合在一起:

Note that excluding /vendor/ this way is not necessary (unless you're using a really old version of Go). If you are using an old version of Go, you can combine them:

go test $(go list ./... | grep -v /vendor/ | grep -v /Store/) -coverprofile .testCoverage.txt

这篇关于在运行"go test"时如何排除或跳过特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆