@@ -28,23 +28,20 @@ LOCAL_DECLS = 'local_decls'
28
28
TOP_LEVEL_DECLS = 'top_level_decls'
29
29
30
30
31
- """The coverage we actually want .
31
+ """The lack of coverage we are willing to tolerate .
32
32
33
33
In a just world, this would be a separate config file, or command-line arguments.
34
34
35
- We round coverage ratios to three decimals before comparing,
36
- so there's no need to go more than that.
35
+ Each item represents the number of "things" we are OK with not being covered.
37
36
"""
38
- DESIRED_COVERAGE = {
39
- EXPRESSIONS : 0.571 ,
40
- BOOLEANS : 0.474 ,
41
- ALTERNATIVES : 0.454 ,
42
- LOCAL_DECLS : 0.814 ,
43
- TOP_LEVEL_DECLS : 0.325 ,
37
+ COVERAGE_TOLERANCE = {
38
+ ALTERNATIVES : 183 ,
39
+ BOOLEANS : 10 ,
40
+ EXPRESSIONS : 1619 ,
41
+ LOCAL_DECLS : 16 ,
42
+ TOP_LEVEL_DECLS : 725 ,
44
43
}
45
44
46
- DEFAULT_PRECISION = 3
47
-
48
45
49
46
def get_report_summary ():
50
47
"""Run ``stack hpc report --all`` and return the output.
@@ -136,58 +133,55 @@ def parse_report_summary(summary):
136
133
return report
137
134
138
135
139
- def compare_values ((covered , total ), target , precision = DEFAULT_PRECISION ):
140
- """Compare measured coverage values with desired ones .
136
+ def compare_values ((covered , total ), tolerance ):
137
+ """Compare measured coverage values with our tolerated lack of coverage .
141
138
142
- Compares ``covered / total`` to ``target``, up to ``precision`` places .
139
+ Return -1 if coverage has got worse, 0 if it is the same, 1 if it is better .
143
140
"""
144
- actual = covered / total
145
- scale = 10 ** precision
146
- rounded_actual = int (round (actual * scale ))
147
- rounded_target = int (round (target * scale ))
148
- return cmp (rounded_actual , rounded_target )
141
+ missing = total - covered
142
+ return cmp (tolerance , missing )
149
143
150
144
151
- def compare_coverage (report , desired , precision = DEFAULT_PRECISION ):
145
+ def compare_coverage (report , desired ):
152
146
comparison = {}
153
- for key , target in desired .items ():
147
+ # TODO: Iterate over report and default to 0 for missing keys in desired.
148
+ for key , tolerance in desired .items ():
154
149
actual = report .get (key , None )
155
150
if actual :
156
- comparison [key ] = compare_values (actual , target , precision = precision )
151
+ comparison [key ] = compare_values (actual , tolerance )
157
152
else :
158
153
comparison [key ] = None
159
154
return comparison
160
155
161
156
162
157
def format_result (result ):
163
158
if result < 0 :
164
- return 'DOWN '
159
+ return 'WORSE '
165
160
elif result == 0 :
166
161
return 'OK'
167
162
else :
168
- return 'UP '
163
+ return 'BETTER '
169
164
170
165
171
166
def format_entry (key , result , desired , actual ):
172
167
covered , total = actual
173
168
formatted_result = format_result (result )
174
169
if result :
175
- return '%s: %s (%2.1f%% => %2.1f%%)' % (
176
- key , formatted_result , desired * 100 ,
177
- 100 * covered / total ,
170
+ return '%s: %s (%d missing => %d missing)' % (
171
+ key , formatted_result , desired , total - covered ,
178
172
)
179
173
else :
180
174
return '%s: %s' % (key , formatted_result )
181
175
182
176
183
177
def main ():
184
178
report = parse_report_summary (get_report_summary ())
185
- comparison = compare_coverage (report , DESIRED_COVERAGE )
179
+ comparison = compare_coverage (report , COVERAGE_TOLERANCE )
186
180
all_same = True
187
181
for key , value in sorted (comparison .items ()):
188
182
if value != 0 :
189
183
all_same = False
190
- print format_entry (key , value , DESIRED_COVERAGE [key ], report [key ])
184
+ print format_entry (key , value , COVERAGE_TOLERANCE [key ], report [key ])
191
185
sys .exit (0 if all_same else 2 )
192
186
193
187
0 commit comments