-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80a5ff2
commit 0225bc0
Showing
5 changed files
with
145 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golangci/golangci-lint/pkg" | ||
"github.com/golangci/golangci-lint/pkg/astcache" | ||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/fsutils" | ||
"github.com/golangci/golangci-lint/pkg/golinters" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestASTCacheLoading(t *testing.T) { | ||
ctx := context.Background() | ||
linters := []pkg.Linter{golinters.Errcheck{}} | ||
|
||
inputPaths := []string{"./...", "./", "./run.go", "run.go"} | ||
for _, inputPath := range inputPaths { | ||
paths, err := fsutils.GetPathsForAnalysis(ctx, []string{inputPath}, true) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, paths.Files) | ||
|
||
prog, _, err := loadWholeAppIfNeeded(ctx, linters, &config.Run{ | ||
AnalyzeTests: true, | ||
}, paths) | ||
assert.NoError(t, err) | ||
|
||
astCacheFromProg, err := astcache.LoadFromProgram(prog) | ||
assert.NoError(t, err) | ||
|
||
astCacheFromFiles := astcache.LoadFromFiles(paths.Files) | ||
|
||
filesFromProg := astCacheFromProg.GetAllValidFiles() | ||
filesFromFiles := astCacheFromFiles.GetAllValidFiles() | ||
if len(filesFromProg) != len(filesFromFiles) { | ||
t.Logf("files: %s", paths.Files) | ||
t.Logf("from prog:") | ||
for _, f := range filesFromProg { | ||
t.Logf("%+v", *f) | ||
} | ||
t.Logf("from files:") | ||
for _, f := range filesFromFiles { | ||
t.Logf("%+v", *f) | ||
} | ||
t.Fatalf("lengths differ") | ||
} | ||
|
||
if len(filesFromProg) != len(paths.Files) { | ||
t.Fatalf("filesFromProg differ from path.Files") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters