Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Lib/test/test_tools/test_check_warnings.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``Tools/build/check_warnings.py`` to accept GCC diagnostics that
omit the warning-option suffix.
4 changes: 3 additions & 1 deletion Tools/build/check_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading