英文:
how to run go-unit-tests pre-commit hook to run with option -p
问题
我正在研究这个 golang-precommit hooks 仓库:https://github.com/dnephin/pre-commit-golang
go-unit-tests
钩子运行的命令是 go test -tags=unit -timeout 30s -short -v
,但如果我想让 go 钩子运行带有 -p=1
选项的命令,有没有办法实现呢?
这是我 .pre-commit-config.yaml
文件中的内容:
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: go-fmt
- id: go-unit-tests
英文:
I was looking into this golang-precommit hooks repository: https://github.com/dnephin/pre-commit-golang
go-unit-tests
hook runs the command go test -tags=unit -timeout 30s -short -v
but what if I want go hook to run command with
-p=1
option. Is there any way to achieve this?
Here's the content from my .pre-commit-config.yaml
file
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: go-fmt
- id: go-unit-tests
答案1
得分: 0
这里没有直接提供那个钩子,但是那个仓库并没有添加太多东西,你可以通过一个repo: local
钩子来复制你想要的功能(未经测试):
- repo: local
hooks:
- id: go-unit-tests
name: go单元测试
entry: go test -p=1 ./...
pass_filenames: false
types: [go]
language: system
免责声明:我编写了pre-commit。
英文:
there isn't given that hook directly, but that repo isn't really adding too terribly much, you could replicate what you want via a repo: local
hook (untested):
- repo: local
hooks:
- id: go-unit-tests
name: go unit tests
entry: go test -p=1 ./...
pass_filenames: false
types: [go]
language: system
disclaimer: I wrote pre-commit
答案2
得分: 0
我邀请你来看看我的golang pre-commit hooks项目:
该项目包含了用于"go test"的内置hooks:
这些hooks专门设计用于允许你向go工具传递额外的参数。
只需使用pre-commit的内置args机制:
此外,每个hook都有一个针对不同范围运行的版本:
- 单个修改的.go文件
- 仓库中的所有.go文件
- 包含修改的.go|go.mod文件的完整模块
- 仓库中的所有模块
- 包含修改的.go文件的完整包(已弃用)
- 仓库中的所有包(已弃用)
注意:可用的范围取决于每个工具实际支持的内容。
最后,还有一种机制可以调用尚未(或不再)具有内置hooks的通用go工具(很难跟上所有工具的更新)。
根据你的原始问题,这是一个使用-p=1
运行go test的示例:
- repo: https://github.com/tekwizely/pre-commit-golang rev: master hooks: - id: go-test-mod args: ['-p=1']
希望你能尝试一下我的项目。我认为你会发现它提供了最好的golang pre-commit hooks。
(请随时提出任何澄清问题,但请不要在这里寻求过多支持-项目页面上的问题和讨论跟踪器是更好的地方)
[编辑:语法]
英文:
/blatant self-promotion
I invite you to have a look at my golang pre-commit hooks project:
The project includes built-in hooks for "go test":
These hooks were specifically designed to enable you to pass extra arguments to the go tools.
Just use pre-commit's built-in args mechanism:
Additionally, each hook has a version to run against different scopes:
- Individually Modified .go Files
- All .go Files in Repository
- Full Module Containing Modified .go|go.mod Files
- All Modules In Repository
- Full Package Containing Modified .go Files (deprecated)
- All Packages in Repository (deprecated)
note: Available scopes are dependent on what each tool actually supports.
Finally, there's a mechanism to invoke general go tools that do not
(yet) have built-in hooks (its hard to keep up with them all).
Per your original question, here's an example of running go test with -p=1
:
<pre>
- repo: https://github.com/tekwizely/pre-commit-golang
rev: master
hooks:
- id: go-test-mod
args: ['-p=1']
</pre>
I hope you'll give my project a try. I think you'll find it offers the best available pre-commit hooks for golang.
(feel free to ask any clarifying questions, but please don't ask for too much support here - the issue and discussion trackers on the project page are a better place for such things)
[edit: grammar]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论