Skip to content

Commit

Permalink
dev: fix: linter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Aug 22, 2022
1 parent f48530e commit 8a0f8da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/linters_test.go
Expand Up @@ -61,7 +61,7 @@ func testSourcesFromDir(t *testing.T, dir string) {
t.Run(filepath.Base(source), func(subTest *testing.T) {
subTest.Parallel()

rel, err := filepath.Rel(dir, sources[0])
rel, err := filepath.Rel(dir, source)
require.NoError(t, err)

testOneSource(subTest, log, binPath, rel)
Expand Down
7 changes: 7 additions & 0 deletions test/output_test.go
Expand Up @@ -96,3 +96,10 @@ func TestOutput_Multiple(t *testing.T) {
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`").
ExpectOutputContains(expectedJSONOutput)
}

func TestName(t *testing.T) {
// testdata/configs/cyclop.yml /home/ldez/sources/go/src/github.com/golangci/golangci-lint/test/testdata

fmt.Println(filepath.Base("testdata/configs/cyclop.yml"))
fmt.Println(filepath.Base("/home/ldez/sources/go/src/github.com/golangci/golangci-lint/test/testdata"))
}
12 changes: 11 additions & 1 deletion test/testshared/runner.go
Expand Up @@ -104,7 +104,17 @@ func (b *RunnerBuilder) WithRunContext(rc *RunContext) *RunnerBuilder {
return b
}

return b.WithConfigFile(rc.ConfigPath).WithArgs(rc.Args...)
dir, err := os.Getwd()
require.NoError(b.tb, err)

configPath := filepath.FromSlash(rc.ConfigPath)

base := filepath.Base(dir)
if strings.HasPrefix(configPath, base) {
configPath = strings.TrimPrefix(configPath, base+string(filepath.Separator))
}

return b.WithConfigFile(configPath).WithArgs(rc.Args...)
}

func (b *RunnerBuilder) WithDirectives(sourcePath string) *RunnerBuilder {
Expand Down

0 comments on commit 8a0f8da

Please sign in to comment.