Skip to content
Open
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
17 changes: 17 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3739,6 +3739,23 @@ def test_no_change(self):
# if the content does not change
self.assertEqual(pre_mtime, post_mtime)

def test_warning_is_failure(self):
code = dedent("""
/*[clinic input]
@permit_long_summary
fn

Short summary.
[clinic start generated code]*/
""")
with os_helper.temp_dir() as tmp_dir:
fn = os.path.join(tmp_dir, "test.c")
with open(fn, "w", encoding="utf-8") as f:
f.write(code)
out, err = self.expect_failure(fn)
self.assertIn("Remove the @permit_long_summary decorator from 'fn'!", out)
self.assertEqual(err, "1 warning emitted\n")

TOUCH_CODE = dedent("""
/*[clinic input]
module m
Expand Down
11 changes: 8 additions & 3 deletions Tools/clinic/libclinic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Local imports.
import libclinic
import libclinic.cpp
import libclinic.errors
from libclinic import ClinicError
from libclinic.language import Language, PythonLanguage
from libclinic.block_parser import BlockParser
Expand Down Expand Up @@ -340,10 +340,15 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
def main(argv: list[str] | None = None) -> NoReturn:
parser = create_cli()
args = parser.parse_args(argv)
libclinic.errors.reset_warning_count()
try:
run_clinic(parser, args)
except ClinicError as exc:
sys.stderr.write(exc.report())
sys.exit(1)
else:
sys.exit(0)
count = libclinic.errors.warning_count
if count:
noun = "warning" if count == 1 else "warnings"
sys.stderr.write(f"{count} {noun} emitted\n")
sys.exit(1)
sys.exit(0)
10 changes: 10 additions & 0 deletions Tools/clinic/libclinic/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class ParseError(ClinicError):
pass


warning_count = 0


def reset_warning_count() -> None:
global warning_count
warning_count = 0


@overload
def warn_or_fail(
*args: object,
Expand Down Expand Up @@ -54,6 +62,8 @@ def warn_or_fail(
if fail:
raise error
else:
global warning_count
warning_count += 1
print(error.report(warn_only=True))


Expand Down
Loading