From c2a412ba18b0e9299f1d69f1a83a8f40f11a823a Mon Sep 17 00:00:00 2001 From: Neal Date: Fri, 31 Jul 2026 10:14:17 +0800 Subject: [PATCH 1/2] fix(junit): count generated test cases --- CHANGELOG.rst | 1 + cpplint.py | 4 ++-- cpplint_unittest.py | 4 ++-- samples/silly-sample/junit.def | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4127d4e..9bf4c14 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Changelog TBA === +* Fixed JUnit XML test and failure counts to match the generated test cases. (#431) * Fixed a whitespace/newline false positive for control conditions containing lambdas. (#410) 2.0.2 (2025-04-08) diff --git a/cpplint.py b/cpplint.py index 07687d2..919ed88 100755 --- a/cpplint.py +++ b/cpplint.py @@ -1546,8 +1546,8 @@ def AddJUnitFailure(self, filename, linenum, message, category, confidence): self._junit_failures.append((filename, linenum, message, category, confidence)) def FormatJUnitXML(self): - num_errors = len(self._junit_errors) - num_failures = len(self._junit_failures) + num_errors = int(bool(self._junit_errors)) + num_failures = len({failure[0] for failure in self._junit_failures}) testsuite = xml.etree.ElementTree.Element("testsuite") testsuite.attrib["errors"] = str(num_errors) diff --git a/cpplint_unittest.py b/cpplint_unittest.py index d568251..35405dd 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -5044,7 +5044,7 @@ def testJUnitXML(self): cpplint._cpplint_state._junit_failures = [] expected = ( '\n' - '' + '' 'ErrMsg1\nErrMsg2' "" ) @@ -5071,7 +5071,7 @@ def testJUnitXML(self): ] expected = ( '\n' - '' + '' '5: FailMsg1 [category/subcategory]' " [3]\n19: FailMsg3 [category/subcategory] [3]" '99: FailMsg2 ' diff --git a/samples/silly-sample/junit.def b/samples/silly-sample/junit.def index c4dce11..30bca44 100644 --- a/samples/silly-sample/junit.def +++ b/samples/silly-sample/junit.def @@ -3,7 +3,7 @@ 1 -0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5] +0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5] 1: Include the directory when naming header files [build/include_subdir] [4] 3: At least two spaces is best between code and comments [whitespace/comments] [2] 3: Should have a space between // and comment [whitespace/comments] [4] From b4371d21885b2dc2e4d6e07ca3fbcff8eb718ed6 Mon Sep 17 00:00:00 2001 From: xu Date: Sun, 2 Aug 2026 00:08:07 +0800 Subject: [PATCH 2/2] fix(junit): narrow count correction --- CHANGELOG.rst | 2 +- cpplint.py | 2 +- cpplint_unittest.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9bf4c14..3190c97 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ Changelog TBA === -* Fixed JUnit XML test and failure counts to match the generated test cases. (#431) +* To match how we group test cases, JUnit output ``failures`` count is now the amount of files with errors. (#431) * Fixed a whitespace/newline false positive for control conditions containing lambdas. (#410) 2.0.2 (2025-04-08) diff --git a/cpplint.py b/cpplint.py index 919ed88..e02c614 100755 --- a/cpplint.py +++ b/cpplint.py @@ -1546,7 +1546,7 @@ def AddJUnitFailure(self, filename, linenum, message, category, confidence): self._junit_failures.append((filename, linenum, message, category, confidence)) def FormatJUnitXML(self): - num_errors = int(bool(self._junit_errors)) + num_errors = len(self._junit_errors) num_failures = len({failure[0] for failure in self._junit_failures}) testsuite = xml.etree.ElementTree.Element("testsuite") diff --git a/cpplint_unittest.py b/cpplint_unittest.py index 35405dd..d189a3d 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -5044,7 +5044,7 @@ def testJUnitXML(self): cpplint._cpplint_state._junit_failures = [] expected = ( '\n' - '' + '' 'ErrMsg1\nErrMsg2' "" )