-
-
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
Showing
11 changed files
with
143 additions
and
66 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
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,7 @@ | ||
//go:build !windows | ||
|
||
package processors | ||
|
||
func normalizePathInRegex(path string) string { | ||
return path | ||
} |
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,21 @@ | ||
//go:build windows | ||
|
||
package processors | ||
|
||
import ( | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var separatorToReplace = regexp.QuoteMeta(string(filepath.Separator)) | ||
|
||
func normalizePathInRegex(path string) string { | ||
if filepath.Separator == '/' { | ||
return path | ||
} | ||
|
||
// This replacing should be safe because "/" are disallowed in Windows | ||
// https://docs.microsoft.com/ru-ru/windows/win32/fileio/naming-a-file | ||
return strings.ReplaceAll(path, "/", separatorToReplace) | ||
} |
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
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,31 @@ | ||
//go:build !windows | ||
|
||
package testshared | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func SkipOnWindows(_ testing.TB) {} | ||
|
||
func NormalizeFilePathInJSON(in string) string { | ||
return in | ||
} | ||
|
||
// NormalizeFileInString normalizes in quoted string. | ||
func NormalizeFileInString(in string) string { | ||
return in | ||
} | ||
|
||
func defaultBinaryName() string { | ||
return filepath.Join("..", "golangci-lint") | ||
} | ||
|
||
func normalizeFilePath(in string) string { | ||
return in | ||
} | ||
|
||
func normalizeFilePathInRegex(path string) string { | ||
return path | ||
} |
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,48 @@ | ||
//go:build windows | ||
|
||
package testshared | ||
|
||
import ( | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func SkipOnWindows(tb testing.TB) { | ||
tb.Skip("not supported on Windows") | ||
} | ||
|
||
func NormalizeFilePathInJSON(in string) string { | ||
exp := regexp.MustCompile(`(?:^|\b)[\w-/.]+\.go`) | ||
|
||
return exp.ReplaceAllStringFunc(in, func(s string) string { | ||
return strings.ReplaceAll(s, "/", "\\\\") | ||
}) | ||
} | ||
|
||
func defaultBinaryName() string { | ||
return filepath.Join("..", "golangci-lint.exe") | ||
} | ||
|
||
// NormalizeFileInString normalizes in quoted string, ie. `\\\\`. | ||
func NormalizeFileInString(in string) string { | ||
return strings.ReplaceAll(filepath.FromSlash(in), "\\", "\\\\") | ||
} | ||
|
||
func normalizeFilePath(in string) string { | ||
exp := regexp.MustCompile(`(?:^|\b)[\w-/.]+\.go`) | ||
|
||
return exp.ReplaceAllStringFunc(in, func(s string) string { | ||
return strings.ReplaceAll(s, "/", "\\") | ||
}) | ||
} | ||
|
||
// normalizeFilePathInRegex normalizes path in regular expressions. | ||
// FIXME(ldez) see utils.normalizeFilePathInRegex(...) and maybe move into RunnerResult.ExpectOutputRegexp(...) | ||
// FIXME(ldez) use the same approach as normalizeFilePath and NormalizeFilePathInJSON. | ||
func normalizeFilePathInRegex(path string) string { | ||
// This replacing should be safe because "/" are disallowed in Windows | ||
// https://docs.microsoft.com/windows/win32/fileio/naming-a-file | ||
return strings.ReplaceAll(path, "/", regexp.QuoteMeta(string(filepath.Separator))) | ||
} |