dnephin/pre-commit-golang

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

jjaxu opened this issue · 1 comments

jjaxu commented

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

Fixed by #95