dqjo4340 2018-05-28 21:37
浏览 38
已采纳

查找Go程序的测试依赖项

I am currently using vendor/ directory to locally vendor my dependencies.

go list -f '{{join .Deps "
"}}' ./...  |grep -Eo 'vendor/.*'

This shows me all "build dependencies" used in my build, (that are used from vendor/). This feature is documented here: https://golang.org/cmd/go/#hdr-List_packages

But it doesn't include your "test dependencies"!

So to find my "test dependencies", I run this command:

$ go list -f '{{join .TestImports "
"}}' ./...  |grep -Eo 'vendor/.*'
vendor/github.com/stretchr/testify/assert
...

It correctly list the "test imports", but it doesn't list the "dependencies" of those test imports.

For example, the vendor/github.com/stretchr/testify/assert directory listed above actually depends on vendor/github.com/pmezard/go-difflib/difflib (and a few other packages). This is not shown in the output above!

But if I run this command, it shows the dependencies of testify/assert:

$ go list -f '{{join .Deps "
"}}' ./vendor/github.com/stretchr/testify/assert | grep -Eo 'vendor/.*'
vendor/github.com/davecgh/go-spew/spew
vendor/github.com/pmezard/go-difflib/difflib
...

So it appears like I need to call go list -f '{{join .Deps " "}}' on all "test imports" to find "all test dependencies"?

Is there a more efficient way of doing this, ideally with a single go list call and some templating?

  • 写回答

1条回答 默认 最新

  • dongluedeng1524 2018-05-30 13:01
    关注

    I am afraid there is no way to show all the recursive test dependencies using just one "go list".

    You will need to use at least two:

    go list -f '{{join .Deps "
    "}}' `go list -f '{{join .TestImports " "}}' ./...`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?