+1
-1
@@ -34,7 +34,7 @@ tasks:
|
||||
lint:
|
||||
desc: golangci-lint (installed by CI; skipped locally if absent).
|
||||
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:
|
||||
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
|
||||
}
|
||||
|
||||
// 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.
|
||||
func runLint(t *testing.T, dir, path string) (string, int) {
|
||||
t.Helper()
|
||||
@@ -73,7 +84,7 @@ func TestTaskLint_ExitsNonZeroWhenGolangciLintReportsAFinding(t *testing.T) {
|
||||
if code == 0 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -91,7 +102,7 @@ func TestTaskLint_SkipsWithANoticeWhenGolangciLintIsAbsent(t *testing.T) {
|
||||
if code != 0 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user