diff --git a/Lib/test/test_tools/test_check_warnings.py b/Lib/test/test_tools/test_check_warnings.py new file mode 100644 index 000000000000000..3dee4c8880d8ea9 --- /dev/null +++ b/Lib/test/test_tools/test_check_warnings.py @@ -0,0 +1,29 @@ +import importlib +import unittest + +from test.test_tools import imports_under_tool, skip_if_missing + + +skip_if_missing("build") +with imports_under_tool("build"): + check_warnings = importlib.import_module("check_warnings") + + +class CheckWarningsTests(unittest.TestCase): + def test_warning_options(self): + for compiler, suffix, option in ( + ("gcc", "", ""), + ("gcc", " [-Wunused-variable]", "-Wunused-variable"), + ("clang", " [-Wunused-variable]", "-Wunused-variable"), + ): + with self.subTest(compiler=compiler, suffix=suffix): + warnings = check_warnings.extract_warnings_from_compiler_output( + "source.c:1:2: warning: example" + suffix, compiler) + self.assertEqual(warnings, [{ + "file": "source.c", "line": "1", "column": "2", + "message": "example", "option": option, + }]) + + +if __name__ == "__main__": + unittest.main() diff --git a/Misc/NEWS.d/next/Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst b/Misc/NEWS.d/next/Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst new file mode 100644 index 000000000000000..072bd6eb0f75c6f --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2026-10-13-20-08-28.gh-issue-159336.wGccOp.rst @@ -0,0 +1,2 @@ +Fix ``Tools/build/check_warnings.py`` to accept GCC diagnostics that +omit the warning-option suffix. diff --git a/Tools/build/check_warnings.py b/Tools/build/check_warnings.py index 44ccf9708ad72f0..5041641ff2a4171 100644 --- a/Tools/build/check_warnings.py +++ b/Tools/build/check_warnings.py @@ -100,7 +100,9 @@ def extract_warnings_from_compiler_output( "line": match.group("line"), "column": match.group("column"), "message": match.group("message"), - "option": match.group("option").lstrip("[").rstrip("]"), + "option": (match.group("option") or "") + .lstrip("[") + .rstrip("]"), }) except AttributeError: print(