Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix cgo tests #159

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ linters:
- prealloc
- rowserrcheck
- testpackage
- tparallel
- varnamelen
- wastedassign

Expand Down
11 changes: 8 additions & 3 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,17 @@ func (wa *wslAnalyzer) flags() flag.FlagSet {

func (wa *wslAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
for _, file := range pass.Files {
if !wa.config.IncludeGenerated && ast.IsGenerated(file) {
filename := getFilename(pass.Fset, file)
if !strings.HasSuffix(filename, ".go") {
continue
}

filename := getFilename(pass.Fset, file)
if !strings.HasSuffix(filename, ".go") {
// if the file is related to cgo the filename of the unadjusted position is a not a '.go' file.
fn := pass.Fset.PositionFor(file.Pos(), false).Filename

// The file is skipped if the "unadjusted" file is a Go file, and it's a generated file (ex: "_test.go" file).
// The other non-Go files are skipped by the first 'if' with the adjusted position.
if !wa.config.IncludeGenerated && ast.IsGenerated(file) && strings.HasSuffix(fn, ".go") {
continue
}

Expand Down
46 changes: 0 additions & 46 deletions testdata/src/default_config/cgo.go.golden

This file was deleted.

10 changes: 8 additions & 2 deletions wsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ func TestWIP(t *testing.T) {
}

func TestDefaultConfig(t *testing.T) {
t.Parallel()

testdata := analysistest.TestData()

testCases := []struct {
Expand All @@ -32,6 +30,7 @@ func TestDefaultConfig(t *testing.T) {
{dir: "generic_handling"},
{dir: "multiline_case"},
{dir: "remove_whitespace"},
{dir: "line_directive"},
}

for _, test := range testCases {
Expand All @@ -44,6 +43,13 @@ func TestDefaultConfig(t *testing.T) {
}
}

func TestCGo(t *testing.T) {
testdata := analysistest.TestData()

analyzer := NewAnalyzer(nil)
analysistest.Run(t, testdata, analyzer, filepath.Join("default_config", "cgo"))
}

func TestWithConfig(t *testing.T) {
testdata := analysistest.TestData()

Expand Down
Loading