Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-unit-test script falsely succeeding if go list ./... fails #94

Closed
jjaxu opened this issue Sep 28, 2022 · 1 comment
Closed

go-unit-test script falsely succeeding if go list ./... fails #94

jjaxu opened this issue Sep 28, 2022 · 1 comment

Comments

@jjaxu
Copy link
Contributor

jjaxu commented Sep 28, 2022

Hello! I recently encountered an edge case that causes the go-unit-tests hook to falsely succeed when it's supposed to fail. If the go list ./... command fails, the main script doesn't terminate as it directly stores the output in FILE. This causes no tests to run in the next step and hence always succeeds.

Minimum working example

One example where this can occur is if two files in the same folder have different package names, and there aren't any unit tests added yet. This example will pass the hook but will fail the go test ./... command with error found packages badname (bar.go) and lib (foo.go) in <your_dir>/lib

Here's the file structure

// main.go
package main
// go.mod
module myapp

go 1.18
# .pre-commit-config.yaml
repos:
- repo: https://github.com/dnephin/pre-commit-golang
  rev: v0.5.0
  hooks:
      - id: go-unit-tests
        always_run: true
// lib/foo.go
package lib
// lib/bar.go
package wrongname
@dnephin
Copy link
Owner

dnephin commented Sep 29, 2022

Fixed by #95

@dnephin dnephin closed this as completed Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants