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/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/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', 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..997f509dd 100644 --- a/tests/functional/test_errmsg.txt +++ b/tests/functional/test_errmsg.txt @@ -176,3 +176,8 @@ 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. +>>> process_file('prepro77.bi', ['-S', '-q', '-O --expect-warnings=1'])