diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-12-21 10:16:58 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-12-21 10:16:58 +0100 |
| commit | 588075e659832f8685d0c9dc9c75c461e023e77f (patch) | |
| tree | ebe57e3f8565493a6a77e79a323a0b2c4eaf7fa0 /pkg | |
| parent | 2b4970017d38fd9b148939c7acdbf704c232f1dc (diff) | |
pkg/report: split overly complex function
gometalinter points to testParseImpl cyclomatic complexity.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/report/report_test.go | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go index 9943add00..398222cea 100644 --- a/pkg/report/report_test.go +++ b/pkg/report/report_test.go @@ -144,21 +144,7 @@ func testParseImpl(t *testing.T, reporter Reporter, test *ParseTest) { } if title != test.Title || corrupted != test.Corrupted || suppressed != test.Suppressed { if *flagUpdate && test.StartLine == "" && test.EndLine == "" { - buf := new(bytes.Buffer) - fmt.Fprintf(buf, "TITLE: %v\n", title) - if corrupted { - fmt.Fprintf(buf, "CORRUPTED: Y\n") - } - if suppressed { - fmt.Fprintf(buf, "SUPPRESSED: Y\n") - } - fmt.Fprintf(buf, "\n%s", test.Log) - if test.HasReport { - fmt.Fprintf(buf, "REPORT:\n%s", test.Report) - } - if err := ioutil.WriteFile(test.FileName, buf.Bytes(), 0640); err != nil { - t.Logf("failed to update test file: %v", err) - } + updateReportTest(t, test, title, corrupted, suppressed) } t.Fatalf("want:\nTITLE: %s\nCORRUPTED: %v\nSUPPRESSED: %v\n"+ "got:\nTITLE: %s\nCORRUPTED: %v (%v)\nSUPPRESSED: %v\n", @@ -213,6 +199,24 @@ func checkReport(t *testing.T, rep *Report, test *ParseTest) { } } +func updateReportTest(t *testing.T, test *ParseTest, title string, corrupted, suppressed bool) { + buf := new(bytes.Buffer) + fmt.Fprintf(buf, "TITLE: %v\n", title) + if corrupted { + fmt.Fprintf(buf, "CORRUPTED: Y\n") + } + if suppressed { + fmt.Fprintf(buf, "SUPPRESSED: Y\n") + } + fmt.Fprintf(buf, "\n%s", test.Log) + if test.HasReport { + fmt.Fprintf(buf, "REPORT:\n%s", test.Report) + } + if err := ioutil.WriteFile(test.FileName, buf.Bytes(), 0640); err != nil { + t.Logf("failed to update test file: %v", err) + } +} + func TestGuiltyFile(t *testing.T) { forEachFile(t, "guilty", testGuiltyFile) } |
