Compare commits
2
Commits
4ef446548d
...
5baffd0189
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5baffd0189 | ||
|
|
228bcc77da |
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -40,10 +41,13 @@ func scratchModule(t *testing.T) string {
|
||||
return dir
|
||||
}
|
||||
|
||||
// ansi matches the colour escape sequences task prints when it thinks it has a terminal.
|
||||
var ansi = regexp.MustCompile("\x1b\\[[0-9;]*m")
|
||||
|
||||
// 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") {
|
||||
for _, line := range strings.Split(ansi.ReplaceAllString(out, ""), "\n") {
|
||||
if strings.HasPrefix(line, "golangci-lint not installed") {
|
||||
return true
|
||||
}
|
||||
@@ -125,3 +129,15 @@ func TestTaskLint_SkipsWithANoticeWhenGolangciLintIsAbsent(t *testing.T) {
|
||||
t.Fatalf("expected the skip notice; output:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// CI runs task with colour on, so the notice line starts with an escape sequence; a bare
|
||||
// prefix match missed it there while passing on a terminal-less local run.
|
||||
func TestHasSkipNotice_SeesTheNoticeBehindColourCodes(t *testing.T) {
|
||||
out := "\x1b[32mtask: [lint] ...\n\x1b[0mgolangci-lint not installed — skipping (CI installs it)\n"
|
||||
if !hasSkipNotice(out) {
|
||||
t.Fatalf("notice not found in coloured output: %q", out)
|
||||
}
|
||||
if hasSkipNotice("\x1b[32mtask: [lint] if command -v golangci-lint ...; echo \"golangci-lint not installed\"\n") {
|
||||
t.Fatal("the echoed command line must not count as the notice")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user