除了供应商软件包外,如何运行我项目中所有测试文件的测试



我的项目文件夹包含:

Makefile  README.md  component/  driver/  service/  vendor/  worker/

我想在所有测试文件上运行go test,例如foobar_test.go文件除了供应商软件包中的测试文件。我最接近成功的是go test ./...,但其中包括供应商测试文件。

我在文档中看到的是您可以将正则态度传递给-run选项,但是我很难完成此操作。例如,我尝试了go test ./*,但是我得到了一堆can't load package errors

最好的方法是什么?

-run模式仅与测试标识符(不是文件名(匹配;原则上,您可以这样做:

go test -run TestFoo

但是,当您必须将Foo添加到所有测试功能名称时,您可能不需要。

...通配符以来不包括./vendor目录,因此您现在可以运行go test ./...,并且不包括./vendor

cmd/go:排除供应商dir从匹配的 ...#19090

[GO] CMD/GO:将供应商包排除在...匹配中

By overwhelming popular demand, exclude vendored packages from ... matches,
by making ... never match the "vendor" element above a vendored package.
go help packages now reads:
    An import path is a pattern if it includes one or more "..." wildcards,
    each of which can match any string, including the empty string and
    strings containing slashes.  Such a pattern expands to all package
    directories found in the GOPATH trees with names matching the
    patterns.
    To make common patterns more convenient, there are two special cases.
    First, /... at the end of the pattern can match an empty string,
    so that net/... matches both net and packages in its subdirectories, like net/http.
    Second, any slash-separted pattern element containing a wildcard never
    participates in a match of the "vendor" element in the path of a vendored
    package, so that ./... does not match packages in subdirectories of
    ./vendor or ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do.
    Note, however, that a directory named vendor that itself contains code
    is not a vendored package: cmd/vendor would be a command named vendor,
    and the pattern cmd/... matches it.
Fixes #19090.

GO/GO/GO/FA1D54C2EDAD60786644577FE4949FBE55166E1

commit    fa1d54c2edad607866445577fe4949fbe55166e1
Wed Mar 29 18:51:44 2017 +0000

尝试在提示处运行go test ./...或等待GO1.9。

最新更新