Skip to content

Commit

Permalink
tests: add missing whitespace tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Dec 16, 2024
1 parent 3763e1a commit ca51724
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 39 deletions.
18 changes: 9 additions & 9 deletions pkg/golinters/whitespace/testdata/whitespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down Expand Up @@ -41,36 +41,36 @@ 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")
}

if true {
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")
}
}
}
}
}

func notGoFmted() {
func notGoFmted() { // want "unnecessary leading newline"



Expand All @@ -79,4 +79,4 @@ func notGoFmted() {



}
} // want "unnecessary trailing newline"
43 changes: 13 additions & 30 deletions pkg/golinters/whitespace/testdata/whitespace_cgo.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
//go:build ignore

// TODO(ldez) the linter doesn't support cgo.
//golangcitest:args -Ewhitespace
//golangcitest:config_path testdata/whitespace.yml
package testdata

/*
#include <stdio.h>
#include <stdlib.h>
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() {
}
Expand Down Expand Up @@ -61,36 +44,36 @@ 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")
}

if true {
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")
}
}
}
}
}

func notGoFmted() {
func notGoFmted() { // want "unnecessary leading newline"



Expand All @@ -99,4 +82,4 @@ func notGoFmted() {



}
} // want "unnecessary trailing newline"
4 changes: 4 additions & 0 deletions pkg/golinters/whitespace/whitespace_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ca51724

Please sign in to comment.