mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-23 03:27:02 +09:00
Pass the changed-coverage gate when no files of the language changed (#8399)
report_changed_coverage.py failed closed on an empty report: a pull request
that changes no files of the gated language produced {} and the redundant
'report and all(...)' guard made that falsy, so the gate returned 1. This
failed the chromium 'changed CSS lines' step (and the equivalent PHP/JS
gates) for any PR that does not touch that language.
Drop the 'report and' guard. all() over no rows is already True, so an empty
report is complete and passes via the existing total == 0 clause, while a
genuinely changed but uninstrumented file still fails closed through all().
This commit is contained in:
1 parent
433af99661
commit
aee10ba74e
2 files changed
+13
-1
No files matched your search
@@ -128,7 +128,10 @@ def main():
|
||||
print(json.dumps(report, indent=2))
|
||||
covered = sum(row['covered'] for row in report.values())
|
||||
total = sum(row['executable'] for row in report.values())
|
||||
complete = report and all(row['instrumented'] for row in report.values())
|
||||
# An empty report means the PR changed no files of this language, so there
|
||||
# is nothing to gate; all() over no rows is already True, so only the
|
||||
# redundant "report and" guard turned that into a failure.
|
||||
complete = all(row['instrumented'] for row in report.values())
|
||||
return 0 if complete and (total == 0 or covered * 100 >= args.minimum * total) else 1
|
||||
|
||||
|
||||
|
||||
@@ -61,6 +61,15 @@ class CoverageEvidenceTest(unittest.TestCase):
|
||||
def test_lower_threshold_does_not_allow_missing_evidence(self):
|
||||
self.assertEqual(self.evaluate(None, minimum=80), 1)
|
||||
|
||||
def test_no_changed_lines_of_the_language_passes(self):
|
||||
# A PR that changes nothing in the gated language has nothing to cover,
|
||||
# so the gate must pass rather than fail closed on an empty report.
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = Path(temporary)
|
||||
arguments = ['gate', '--base', 'HEAD']
|
||||
with patch.object(GATE.Path, 'cwd', return_value=root), patch.object(GATE, 'added_lines', return_value={}), patch('sys.argv', arguments), redirect_stdout(io.StringIO()):
|
||||
self.assertEqual(GATE.main(), 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user