Skip to content

go/analysis/analysistest: Ignore error if edited file can't be formatted #232

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion go/analysis/analysistest/analysistest.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var TestData = func() string {
// Testing is an abstraction of a *testing.T.
type Testing interface {
Errorf(format string, args ...interface{})
Skipf(format string, args ...interface{})
}

// RunWithSuggestedFixes behaves like Run, but additionally verifies suggested fixes.
Expand Down Expand Up @@ -183,7 +184,7 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
want := string(bytes.TrimRight(vf.Data, "\n")) + "\n"
formatted, err := format.Source([]byte(out))
if err != nil {
continue
t.Skipf("Could not format edited file %s. Error: %s. Continuing nevertheless\n", file.Name(), err)
}
if want != string(formatted) {
d := myers.ComputeEdits("", want, string(formatted))
Expand All @@ -209,6 +210,7 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns

formatted, err := format.Source([]byte(out))
if err != nil {
t.Errorf("Could not format edited file %s. Error: %s", file.Name(), err)
continue
}
if want != string(formatted) {
Expand Down
4 changes: 4 additions & 0 deletions go/analysis/analysistest/analysistest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ type errorfunc func(string)
func (f errorfunc) Errorf(format string, args ...interface{}) {
f(fmt.Sprintf(format, args...))
}

func (f errorfunc) Skipf(format string, args ...interface{}) {
f(fmt.Sprintf(format, args...))
}