Skip to content

Commit b3eb50b

Browse files
authored
test: fix cgo tests (#159)
1 parent 52299dc commit b3eb50b

File tree

8 files changed

+17
-51
lines changed

8 files changed

+17
-51
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ linters:
6060
- prealloc
6161
- rowserrcheck
6262
- testpackage
63+
- tparallel
6364
- varnamelen
6465
- wastedassign
6566

analyzer.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,17 @@ func (wa *wslAnalyzer) flags() flag.FlagSet {
7979

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

86-
filename := getFilename(pass.Fset, file)
87-
if !strings.HasSuffix(filename, ".go") {
87+
// if the file is related to cgo the filename of the unadjusted position is a not a '.go' file.
88+
fn := pass.Fset.PositionFor(file.Pos(), false).Filename
89+
90+
// The file is skipped if the "unadjusted" file is a Go file, and it's a generated file (ex: "_test.go" file).
91+
// The other non-Go files are skipped by the first 'if' with the adjusted position.
92+
if !wa.config.IncludeGenerated && ast.IsGenerated(file) && strings.HasSuffix(fn, ".go") {
8893
continue
8994
}
9095

testdata/src/default_config/cgo.go.golden

Lines changed: 0 additions & 46 deletions
This file was deleted.

wsl_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ func TestWIP(t *testing.T) {
1515
}
1616

1717
func TestDefaultConfig(t *testing.T) {
18-
t.Parallel()
19-
2018
testdata := analysistest.TestData()
2119

2220
testCases := []struct {
@@ -32,6 +30,7 @@ func TestDefaultConfig(t *testing.T) {
3230
{dir: "generic_handling"},
3331
{dir: "multiline_case"},
3432
{dir: "remove_whitespace"},
33+
{dir: "line_directive"},
3534
}
3635

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

46+
func TestCGo(t *testing.T) {
47+
testdata := analysistest.TestData()
48+
49+
analyzer := NewAnalyzer(nil)
50+
analysistest.Run(t, testdata, analyzer, filepath.Join("default_config", "cgo"))
51+
}
52+
4753
func TestWithConfig(t *testing.T) {
4854
testdata := analysistest.TestData()
4955

0 commit comments

Comments
 (0)