@@ -14,46 +14,43 @@ func ReportForHuman(w io.Writer, result AnalyzeResult, thr Threshold) {
14
14
out := bufio .NewWriter (w )
15
15
defer out .Flush ()
16
16
17
- {
18
- fmt .Fprintf (out , "Files meeting coverage threshold of (%d%%):\t " , thr .File )
19
- if len (result .FilesBelowThreshold ) > 0 {
20
- fmt .Fprintf (out , "FAIL" )
21
- reportIssuesForHuman (out , result .FilesBelowThreshold )
22
- } else {
23
- fmt .Fprintf (out , "PASS" )
17
+ statusStr := func (passing bool ) string {
18
+ if passing {
19
+ return "PASS"
24
20
}
25
- }
26
21
27
- {
28
- fmt .Fprintf (out , "\n Packages meeting coverage threshold of (%d%%):\t " , thr .Package )
29
- if len (result .PackagesBelowThreshold ) > 0 {
30
- fmt .Fprintf (out , "FAIL" )
31
- reportIssuesForHuman (out , result .PackagesBelowThreshold )
32
- } else {
33
- fmt .Fprintf (out , "PASS" )
34
- }
22
+ return "FAIL"
35
23
}
36
24
37
- {
38
- fmt .Fprintf (out , "\n Total coverage meeting the threshold of (%d%%):\t " , thr .Total )
39
- if ! result .MeetsTotalCoverage {
40
- fmt .Fprintf (out , "FAIL" )
41
- } else {
42
- fmt .Fprintf (out , "PASS" )
43
- }
44
- }
25
+ // File threshold report
26
+ fmt .Fprintf (out , "File coverage threshold (%d%%) satisfied:\t " , thr .File )
27
+ fmt .Fprint (out , statusStr (len (result .FilesBelowThreshold ) == 0 ))
28
+ reportIssuesForHuman (out , result .FilesBelowThreshold )
29
+
30
+ // Package threshold report
31
+ fmt .Fprintf (out , "\n Package coverage threshold (%d%%) satisfied:\t " , thr .Package )
32
+ fmt .Fprint (out , statusStr (len (result .PackagesBelowThreshold ) == 0 ))
33
+ reportIssuesForHuman (out , result .PackagesBelowThreshold )
34
+
35
+ // Total threshold report
36
+ fmt .Fprintf (out , "\n Total coverage threshold (%d%%) satisfied:\t " , thr .Total )
37
+ fmt .Fprint (out , statusStr (result .MeetsTotalCoverage ))
45
38
46
39
fmt .Fprintf (out , "\n Total test coverage: %d%%\n " , result .TotalCoverage )
47
40
}
48
41
49
42
func reportIssuesForHuman (w io.Writer , coverageStats []CoverageStats ) {
50
- tabber := tabwriter .NewWriter (w , 1 , 8 , 1 , '\t' , 0 ) //nolint:gomnd // relax
43
+ if len (coverageStats ) == 0 {
44
+ return
45
+ }
46
+
47
+ tabber := tabwriter .NewWriter (w , 1 , 8 , 2 , '\t' , 0 ) //nolint:gomnd // relax
51
48
defer tabber .Flush ()
52
49
53
- fmt .Fprintf (tabber , "\n \n Issues with :" )
50
+ fmt .Fprintf (tabber , "\n below threshold: \t coverage :" )
54
51
55
52
for _ , stats := range coverageStats {
56
- fmt .Fprintf (tabber , "\n %s\t %d%%" , stats .Name , stats .CoveredPercentage ())
53
+ fmt .Fprintf (tabber , "\n %s\t %d%%" , stats .Name , stats .CoveredPercentage ())
57
54
}
58
55
59
56
fmt .Fprintf (tabber , "\n " )
@@ -72,25 +69,28 @@ func ReportForGithubAction(w io.Writer, result AnalyzeResult, thr Threshold) {
72
69
73
70
for _ , stats := range result .FilesBelowThreshold {
74
71
title := "File test coverage below threshold"
75
- c := stats .CoveredPercentage ()
76
- t := thr .File
77
- msg := fmt .Sprintf ("coverage: %d%%; threshold: %d%%" , c , t )
72
+ msg := fmt .Sprintf (
73
+ "%s: coverage: %d%%; threshold: %d%%" ,
74
+ title , stats .CoveredPercentage (), thr .File ,
75
+ )
78
76
reportLineError (stats .Name , title , msg )
79
77
}
80
78
81
79
for _ , stats := range result .PackagesBelowThreshold {
82
80
title := "Package test coverage below threshold"
83
- c := stats .CoveredPercentage ()
84
- t := thr .Package
85
- msg := fmt .Sprintf ("package: %s; coverage: %d%%; threshold: %d%%" , stats .Name , c , t )
81
+ msg := fmt .Sprintf (
82
+ "%s: package: %s; coverage: %d%%; threshold: %d%%" ,
83
+ title , stats .Name , stats .CoveredPercentage (), thr .Package ,
84
+ )
86
85
reportError (title , msg )
87
86
}
88
87
89
88
if ! result .MeetsTotalCoverage {
90
89
title := "Total test coverage below threshold"
91
- c := result .TotalCoverage
92
- t := thr .Total
93
- msg := fmt .Sprintf ("coverage: %d%%; threshold: %d%%" , c , t )
90
+ msg := fmt .Sprintf (
91
+ "%s: coverage: %d%%; threshold: %d%%" ,
92
+ title , result .TotalCoverage , thr .Total ,
93
+ )
94
94
reportError (title , msg )
95
95
}
96
96
}
0 commit comments