fix(task): lint step fails on findings instead of printing 'not installed' (#41)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ tasks:
|
|||||||
lint:
|
lint:
|
||||||
desc: golangci-lint (installed by CI; skipped locally if absent).
|
desc: golangci-lint (installed by CI; skipped locally if absent).
|
||||||
cmds:
|
cmds:
|
||||||
- 'command -v golangci-lint >/dev/null 2>&1 && golangci-lint run ./... || echo "golangci-lint not installed — skipping (CI installs it)"'
|
- 'if command -v golangci-lint >/dev/null 2>&1; then golangci-lint run ./...; else echo "golangci-lint not installed — skipping (CI installs it)"; fi'
|
||||||
|
|
||||||
test:
|
test:
|
||||||
desc: Run all tests. -p 1 serializes packages so the embedded-postgres tests
|
desc: Run all tests. -p 1 serializes packages so the embedded-postgres tests
|
||||||
|
|||||||
@@ -40,6 +40,17 @@ func scratchModule(t *testing.T) string {
|
|||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasSkipNotice reports whether the skip notice was printed as output. Task echoes the command
|
||||||
|
// line first, and that line contains the same words, so a substring match would be vacuous.
|
||||||
|
func hasSkipNotice(out string) bool {
|
||||||
|
for _, line := range strings.Split(out, "\n") {
|
||||||
|
if strings.HasPrefix(line, "golangci-lint not installed") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// runLint runs `task lint` in dir with the given PATH and returns its combined output and exit code.
|
// runLint runs `task lint` in dir with the given PATH and returns its combined output and exit code.
|
||||||
func runLint(t *testing.T, dir, path string) (string, int) {
|
func runLint(t *testing.T, dir, path string) (string, int) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -73,7 +84,7 @@ func TestTaskLint_ExitsNonZeroWhenGolangciLintReportsAFinding(t *testing.T) {
|
|||||||
if code == 0 {
|
if code == 0 {
|
||||||
t.Fatalf("task lint exited 0 on a module with an unchecked error; output:\n%s", out)
|
t.Fatalf("task lint exited 0 on a module with an unchecked error; output:\n%s", out)
|
||||||
}
|
}
|
||||||
if strings.Contains(out, "not installed") {
|
if hasSkipNotice(out) {
|
||||||
t.Fatalf("task lint blamed a missing binary for a lint failure; output:\n%s", out)
|
t.Fatalf("task lint blamed a missing binary for a lint failure; output:\n%s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,7 +102,7 @@ func TestTaskLint_SkipsWithANoticeWhenGolangciLintIsAbsent(t *testing.T) {
|
|||||||
if code != 0 {
|
if code != 0 {
|
||||||
t.Fatalf("task lint exited %d without golangci-lint on PATH; output:\n%s", code, out)
|
t.Fatalf("task lint exited %d without golangci-lint on PATH; output:\n%s", code, out)
|
||||||
}
|
}
|
||||||
if !strings.Contains(out, "not installed") {
|
if !hasSkipNotice(out) {
|
||||||
t.Fatalf("expected the skip notice; output:\n%s", out)
|
t.Fatalf("expected the skip notice; output:\n%s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user