From 588075e659832f8685d0c9dc9c75c461e023e77f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 21 Dec 2018 10:16:58 +0100 Subject: pkg/report: split overly complex function gometalinter points to testParseImpl cyclomatic complexity. --- pkg/report/report_test.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'pkg') 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) } -- cgit mrf-deployment