From f0317506c19cfd124ab52e8d059326e9f859ac0a Mon Sep 17 00:00:00 2001 From: Denis Krivak Date: Mon, 9 Sep 2024 19:23:09 +0200 Subject: [PATCH] Fix checking testing outputs. --- checks.go | 2 ++ getters.go | 6 +----- testdata/check/main.go | 7 +++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/checks.go b/checks.go index df5019f..d307663 100644 --- a/checks.go +++ b/checks.go @@ -230,6 +230,8 @@ func isSpecialBlock(comment string) bool { strings.Contains(comment, "#define")) { return true } + // This should only be skipped in test files, but we don't have this + // information here, so - always skip if strings.HasPrefix(comment, "// Output:") || strings.HasPrefix(comment, "// Unordered output:") { return true diff --git a/getters.go b/getters.go index 7d3d22f..de3d06e 100644 --- a/getters.go +++ b/getters.go @@ -209,12 +209,8 @@ func (pf *parsedFile) getAllComments(exclude []*regexp.Regexp) []comment { // special lines (e.g., tags or indented code examples), they are replaced // with `specialReplacer` to skip checks for them. // The result can be multiline. -// -//nolint:cyclop func getText(comment *ast.CommentGroup, exclude []*regexp.Regexp) (s string) { - if len(comment.List) == 1 && - strings.HasPrefix(comment.List[0].Text, "/*") && - isSpecialBlock(comment.List[0].Text) { + if len(comment.List) > 0 && isSpecialBlock(comment.List[0].Text) { return "" } diff --git a/testdata/check/main.go b/testdata/check/main.go index f2f51f7..001d323 100644 --- a/testdata/check/main.go +++ b/testdata/check/main.go @@ -161,6 +161,13 @@ func nonCapital() int { return x // non-capital-all [CAPITAL_ALL]. } +// ExamplePrintln is a function that you would normally see in tests. +func ExamplePrintln() { + fmt.Println("hello") + // Output: + // hello [PASS] +} + // Comment with a URL - http://example.com/[PASS] // Multiline comment with a URL