Skip to content

Commit

Permalink
pkg/cover: reduce generateReport cyclo
Browse files Browse the repository at this point in the history
This function reached the cyclo complexity limit 24
  • Loading branch information
tarasmadan committed Feb 27, 2025
1 parent 5810ffa commit 113390f
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions pkg/cover/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ func testReportGenerator(t *testing.T, target *targets.Target, test Test) {
if test.Result != "" {
t.Fatalf("got no error, but expected %q", test.Result)
}
checkCSVReport(t, reps.csv)
checkJSONLReport(t, reps.jsonl, sampleCoverJSON)
checkJSONLReport(t, reps.jsonlPrograms, sampleJSONLlProgs)
checkCSVReport(t, reps.csv.Bytes())
checkJSONLReport(t, reps.jsonl.Bytes(), sampleCoverJSON)
checkJSONLReport(t, reps.jsonlPrograms.Bytes(), sampleJSONLlProgs)
}

const kcovCode = `
Expand Down Expand Up @@ -292,9 +292,9 @@ func buildTestBinary(t *testing.T, target *targets.Target, test *Test, dir strin
}

type reports struct {
csv []byte
jsonl []byte
jsonlPrograms []byte
csv *bytes.Buffer
jsonl *bytes.Buffer
jsonlPrograms *bytes.Buffer
}

func generateReport(t *testing.T, target *targets.Target, test *Test) (*reports, error) {
Expand Down Expand Up @@ -387,29 +387,17 @@ func generateReport(t *testing.T, target *targets.Target, test *Test) (*reports,
if err := rg.DoHTML(new(bytes.Buffer), params); err != nil {
return nil, err
}
if err := rg.DoSubsystemCover(new(bytes.Buffer), params); err != nil {
return nil, err
}
csv := new(bytes.Buffer)
if err := rg.DoFuncCover(csv, params); err != nil {
return nil, err
}
if err := rg.DoFileCover(new(bytes.Buffer), params); err != nil {
return nil, err
}
jsonl := new(bytes.Buffer)
if err := rg.DoCoverJSONL(jsonl, params); err != nil {
return nil, err
}
jsonlProgs := new(bytes.Buffer)
if err := rg.DoCoverPrograms(jsonlProgs, params); err != nil {
return nil, err
}
return &reports{
csv: csv.Bytes(),
jsonl: jsonl.Bytes(),
jsonlPrograms: jsonlProgs.Bytes(),
}, nil
assert.NoError(t, rg.DoSubsystemCover(new(bytes.Buffer), params))
assert.NoError(t, rg.DoFileCover(new(bytes.Buffer), params))
res := &reports{
csv: new(bytes.Buffer),
jsonl: new(bytes.Buffer),
jsonlPrograms: new(bytes.Buffer),
}
assert.NoError(t, rg.DoFuncCover(res.csv, params))
assert.NoError(t, rg.DoCoverJSONL(res.jsonl, params))
assert.NoError(t, rg.DoCoverPrograms(res.jsonlPrograms, params))
return res, nil
}

func checkCSVReport(t *testing.T, CSVReport []byte) {
Expand Down

0 comments on commit 113390f

Please sign in to comment.