From 1851cda260a4920c9b36e01a389a11b5f8d4377d Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 17 Dec 2024 00:52:13 +0100 Subject: [PATCH] tests: add missing whitespace tests --- .../whitespace/testdata/whitespace.go | 18 ++++---- .../whitespace/testdata/whitespace_cgo.go | 44 ++++++------------- .../whitespace/whitespace_integration_test.go | 4 ++ 3 files changed, 27 insertions(+), 39 deletions(-) diff --git a/pkg/golinters/whitespace/testdata/whitespace.go b/pkg/golinters/whitespace/testdata/whitespace.go index 1c9da1edd6c96..c482c94f9e185 100644 --- a/pkg/golinters/whitespace/testdata/whitespace.go +++ b/pkg/golinters/whitespace/testdata/whitespace.go @@ -4,16 +4,16 @@ package testdata import "fmt" -func oneLeadingNewline() { +func oneLeadingNewline() { // want "unnecessary leading newline" fmt.Println("Hello world") } -func oneNewlineAtBothEnds() { +func oneNewlineAtBothEnds() { // want "unnecessary leading newline" fmt.Println("Hello world") -} +} // want "unnecessary trailing newline" func noNewlineFunc() { } @@ -41,20 +41,20 @@ func oneLeadingNewlineWithCommentFunc() { // some comment } -func twoLeadingNewlines() { +func twoLeadingNewlines() { // want "unnecessary leading newline" fmt.Println("Hello world") } func multiFuncFunc(a int, - b int) { + b int) { // want "multi-line statement should be followed by a newline" fmt.Println("Hello world") } func multiIfFunc() { if 1 == 1 && - 2 == 2 { + 2 == 2 { // want "multi-line statement should be followed by a newline" fmt.Println("Hello multi-line world") } @@ -62,7 +62,7 @@ func multiIfFunc() { if true { if true { if 1 == 1 && - 2 == 2 { + 2 == 2 { // want "multi-line statement should be followed by a newline" fmt.Println("Hello nested multi-line world") } } @@ -70,7 +70,7 @@ func multiIfFunc() { } } -func notGoFmted() { +func notGoFmted() { // want "unnecessary leading newline" @@ -79,4 +79,4 @@ func notGoFmted() { -} +} // want "unnecessary trailing newline" diff --git a/pkg/golinters/whitespace/testdata/whitespace_cgo.go b/pkg/golinters/whitespace/testdata/whitespace_cgo.go index 58305eee4697e..72c7e2c19035a 100644 --- a/pkg/golinters/whitespace/testdata/whitespace_cgo.go +++ b/pkg/golinters/whitespace/testdata/whitespace_cgo.go @@ -1,39 +1,23 @@ +//go:build ignore + +// TODO(ldez) the linter doesn't support cgo. + //golangcitest:args -Ewhitespace //golangcitest:config_path testdata/whitespace.yml package testdata -/* - #include - #include - - void myprint(char* s) { - printf("%d\n", s); - } -*/ -import "C" - -import ( - "fmt" - "strings" - "unsafe" -) - -func _() { - cs := C.CString("Hello from stdio\n") - C.myprint(cs) - C.free(unsafe.Pointer(cs)) -} +import "fmt" -func oneLeadingNewline() { +func oneLeadingNewline() { // want "unnecessary leading newline" fmt.Println("Hello world") } -func oneNewlineAtBothEnds() { +func oneNewlineAtBothEnds() { // want "unnecessary leading newline" fmt.Println("Hello world") -} +} // want "unnecessary trailing newline" func noNewlineFunc() { } @@ -61,20 +45,20 @@ func oneLeadingNewlineWithCommentFunc() { // some comment } -func twoLeadingNewlines() { +func twoLeadingNewlines() { // want "unnecessary leading newline" fmt.Println("Hello world") } func multiFuncFunc(a int, - b int) { + b int) { // want "multi-line statement should be followed by a newline" fmt.Println("Hello world") } func multiIfFunc() { if 1 == 1 && - 2 == 2 { + 2 == 2 { // want "multi-line statement should be followed by a newline" fmt.Println("Hello multi-line world") } @@ -82,7 +66,7 @@ func multiIfFunc() { if true { if true { if 1 == 1 && - 2 == 2 { + 2 == 2 { // want "multi-line statement should be followed by a newline" fmt.Println("Hello nested multi-line world") } } @@ -90,7 +74,7 @@ func multiIfFunc() { } } -func notGoFmted() { +func notGoFmted() { // want "unnecessary leading newline" @@ -99,4 +83,4 @@ func notGoFmted() { -} +} // want "unnecessary trailing newline" diff --git a/pkg/golinters/whitespace/whitespace_integration_test.go b/pkg/golinters/whitespace/whitespace_integration_test.go index fd80dafbb6514..015dee5e9d261 100644 --- a/pkg/golinters/whitespace/whitespace_integration_test.go +++ b/pkg/golinters/whitespace/whitespace_integration_test.go @@ -6,6 +6,10 @@ import ( "github.com/golangci/golangci-lint/test/testshared/integration" ) +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} + func TestFix(t *testing.T) { integration.RunFix(t) }