From 85d63cb69d105b86e65a52e6b414d78a083fd9b7 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 28 Dec 2020 20:41:53 +0100 Subject: [PATCH 1/3] Allow silencing N warnings First N warnings will be silenced with --expect-warnings=N command line option. --- src/api/config.py | 1 + src/api/errmsg.py | 5 ++++- src/libzxbc/zxbc.py | 3 +++ tests/functional/test_cmdline.txt | 2 +- tests/functional/test_errmsg.txt | 4 ++++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/config.py b/src/api/config.py index 53b8333f2..aa3e181d9 100644 --- a/src/api/config.py +++ b/src/api/config.py @@ -69,6 +69,7 @@ def init(): OPTIONS.add_option('strict', bool, False) # True to force type checking OPTIONS.add_option('zxnext', bool, False) # True to enable ZX Next ASM opcodes OPTIONS.add_option('architecture', str, None) # Architecture + OPTIONS.add_option('expect_warnings', int, 0) # Expected Warnings that will be silenced init() diff --git a/src/api/errmsg.py b/src/api/errmsg.py index 4020a1ce4..14aa1e1b3 100644 --- a/src/api/errmsg.py +++ b/src/api/errmsg.py @@ -54,12 +54,15 @@ def error(lineno: int, msg: str, fname: Optional[str] = None) -> None: def warning(lineno: int, msg: str, fname: Optional[str] = None) -> None: """ Generic warning error routine """ + global_.has_warnings += 1 + if global_.has_warnings <= OPTIONS.expect_warnings: + return + if fname is None: fname = global_.FILENAME msg = "%s:%i: warning: %s" % (fname, lineno, msg) msg_output(msg) - global_.has_warnings += 1 def warning_implicit_type(lineno: int, id_: str, type_: str = None): diff --git a/src/libzxbc/zxbc.py b/src/libzxbc/zxbc.py index 3aeec93b8..c19322ac5 100755 --- a/src/libzxbc/zxbc.py +++ b/src/libzxbc/zxbc.py @@ -151,6 +151,8 @@ def main(args=None, emitter=None): parser.add_argument('--arch', type=str, default=arch.AVAILABLE_ARCHITECTURES[0], help=f"Target architecture (defaults is'{arch.AVAILABLE_ARCHITECTURES[0]}'). " f"Available architectures: {','.join(arch.AVAILABLE_ARCHITECTURES)}") + parser.add_argument('--expect-warnings', default=OPTIONS.expect_warnings, type=int, + help='Expects N warnings: first N warnings will be silenced') options = parser.parse_args(args=args) @@ -176,6 +178,7 @@ def main(args=None, emitter=None): OPTIONS.strict = options.strict OPTIONS.headerless = options.headerless OPTIONS.zxnext = options.zxnext + OPTIONS.expect_warnings = gl.EXPECTED_WARNINGS = options.expect_warnings if options.arch not in arch.AVAILABLE_ARCHITECTURES: parser.error(f"Invalid architecture '{options.arch}'") diff --git a/tests/functional/test_cmdline.txt b/tests/functional/test_cmdline.txt index 0d251b23e..35267e046 100644 --- a/tests/functional/test_cmdline.txt +++ b/tests/functional/test_cmdline.txt @@ -11,7 +11,7 @@ usage: zxbc.py [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-B] [-a] [-i] [-I INCLUDE_PATH] [--strict] [--headerless] [--version] [--parse-only] [--append-binary APPEND_BINARY] [--append-headless-binary APPEND_HEADLESS_BINARY] [-N] - [--arch ARCH] + [--arch ARCH] [--expect-warnings EXPECT_WARNINGS] PROGRAM zxbc.py: error: Option --asm and --mmap cannot be used together diff --git a/tests/functional/test_errmsg.txt b/tests/functional/test_errmsg.txt index 6b21aa9b5..0134a629f 100644 --- a/tests/functional/test_errmsg.txt +++ b/tests/functional/test_errmsg.txt @@ -176,3 +176,7 @@ prepro76.bi:2: error: this is an intended error line_asm.bi:26: warning: this should be line 26 >>> process_file('line_err.bas') line_err.bas:5: error: Variable 'q' already declared at line_err.bas:1 + +# Test warning silencing +>>> process_file('mcleod3.bas', ['-S', '-q', '-O --expect-warnings=2']) +mcleod3.bas:3: error: 'GenerateSpaces' is neither an array nor a function. From 50075d1f87025e692564bab094bb1646721a7f78 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 28 Dec 2020 21:00:51 +0100 Subject: [PATCH 2/3] Add expect-warnings to zxbpp --- src/libzxbpp/zxbpp.py | 3 +++ tests/functional/test_errmsg.txt | 1 + 2 files changed, 4 insertions(+) diff --git a/src/libzxbpp/zxbpp.py b/src/libzxbpp/zxbpp.py index 63da279fc..d6d55abda 100755 --- a/src/libzxbpp/zxbpp.py +++ b/src/libzxbpp/zxbpp.py @@ -865,10 +865,13 @@ def entry_point(args=None): parser.add_argument('--arch', type=str, default=arch.AVAILABLE_ARCHITECTURES[0], help=f"Target architecture (defaults is'{arch.AVAILABLE_ARCHITECTURES[0]}'). " f"Available architectures: {','.join(arch.AVAILABLE_ARCHITECTURES)}") + parser.add_argument('--expect-warnings', default=OPTIONS.expect_warnings, type=int, + help='Expects N warnings: first N warnings will be silenced') options = parser.parse_args(args=args) OPTIONS.Debug = options.debug OPTIONS.debug_zxbpp = OPTIONS.Debug > 0 + OPTIONS.expect_warnings = options.expect_warnings if options.arch not in arch.AVAILABLE_ARCHITECTURES: parser.error(f"Invalid architecture '{options.arch}'") diff --git a/tests/functional/test_errmsg.txt b/tests/functional/test_errmsg.txt index 0134a629f..997f509dd 100644 --- a/tests/functional/test_errmsg.txt +++ b/tests/functional/test_errmsg.txt @@ -180,3 +180,4 @@ line_err.bas:5: error: Variable 'q' already declared at line_err.bas:1 # Test warning silencing >>> process_file('mcleod3.bas', ['-S', '-q', '-O --expect-warnings=2']) mcleod3.bas:3: error: 'GenerateSpaces' is neither an array nor a function. +>>> process_file('prepro77.bi', ['-S', '-q', '-O --expect-warnings=1']) From af5fa46c67cc54e30e1b0a9dca7dad0116640d54 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Mon, 28 Dec 2020 21:05:36 +0100 Subject: [PATCH 3/3] Fix (update) config test --- tests/api/test_config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/api/test_config.py b/tests/api/test_config.py index a62729add..44e728f8b 100644 --- a/tests/api/test_config.py +++ b/tests/api/test_config.py @@ -36,6 +36,8 @@ def test_init(self): self.assertEqual(config.OPTIONS.enableBreak, False) self.assertEqual(config.OPTIONS.emitBackend, False) self.assertIsNone(config.OPTIONS.architecture) + self.assertEqual(config.OPTIONS.expect_warnings, 0) + # private options that cannot be accessed with #pragma self.assertEqual(config.OPTIONS['__DEFINES'].value, {}) self.assertEqual(config.OPTIONS.explicit, False) @@ -58,6 +60,7 @@ def test_initted_values(self): 'case_insensitive', 'emitBackend', 'enableBreak', + 'expect_warnings', 'explicit', 'include_path', 'inputFileName',