Skip to content

Commit 85d63cb

Browse files
committed
Allow silencing N warnings
First N warnings will be silenced with --expect-warnings=N command line option.
1 parent 525a7d9 commit 85d63cb

5 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/api/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def init():
6969
OPTIONS.add_option('strict', bool, False) # True to force type checking
7070
OPTIONS.add_option('zxnext', bool, False) # True to enable ZX Next ASM opcodes
7171
OPTIONS.add_option('architecture', str, None) # Architecture
72+
OPTIONS.add_option('expect_warnings', int, 0) # Expected Warnings that will be silenced
7273

7374

7475
init()

src/api/errmsg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ def error(lineno: int, msg: str, fname: Optional[str] = None) -> None:
5454
def warning(lineno: int, msg: str, fname: Optional[str] = None) -> None:
5555
""" Generic warning error routine
5656
"""
57+
global_.has_warnings += 1
58+
if global_.has_warnings <= OPTIONS.expect_warnings:
59+
return
60+
5761
if fname is None:
5862
fname = global_.FILENAME
5963

6064
msg = "%s:%i: warning: %s" % (fname, lineno, msg)
6165
msg_output(msg)
62-
global_.has_warnings += 1
6366

6467

6568
def warning_implicit_type(lineno: int, id_: str, type_: str = None):

src/libzxbc/zxbc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def main(args=None, emitter=None):
151151
parser.add_argument('--arch', type=str, default=arch.AVAILABLE_ARCHITECTURES[0],
152152
help=f"Target architecture (defaults is'{arch.AVAILABLE_ARCHITECTURES[0]}'). "
153153
f"Available architectures: {','.join(arch.AVAILABLE_ARCHITECTURES)}")
154+
parser.add_argument('--expect-warnings', default=OPTIONS.expect_warnings, type=int,
155+
help='Expects N warnings: first N warnings will be silenced')
154156

155157
options = parser.parse_args(args=args)
156158

@@ -176,6 +178,7 @@ def main(args=None, emitter=None):
176178
OPTIONS.strict = options.strict
177179
OPTIONS.headerless = options.headerless
178180
OPTIONS.zxnext = options.zxnext
181+
OPTIONS.expect_warnings = gl.EXPECTED_WARNINGS = options.expect_warnings
179182

180183
if options.arch not in arch.AVAILABLE_ARCHITECTURES:
181184
parser.error(f"Invalid architecture '{options.arch}'")

tests/functional/test_cmdline.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ usage: zxbc.py [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-B] [-a]
1111
[-i] [-I INCLUDE_PATH] [--strict] [--headerless] [--version]
1212
[--parse-only] [--append-binary APPEND_BINARY]
1313
[--append-headless-binary APPEND_HEADLESS_BINARY] [-N]
14-
[--arch ARCH]
14+
[--arch ARCH] [--expect-warnings EXPECT_WARNINGS]
1515
PROGRAM
1616
zxbc.py: error: Option --asm and --mmap cannot be used together
1717

tests/functional/test_errmsg.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,7 @@ prepro76.bi:2: error: this is an intended error
176176
line_asm.bi:26: warning: this should be line 26
177177
>>> process_file('line_err.bas')
178178
line_err.bas:5: error: Variable 'q' already declared at line_err.bas:1
179+
180+
# Test warning silencing
181+
>>> process_file('mcleod3.bas', ['-S', '-q', '-O --expect-warnings=2'])
182+
mcleod3.bas:3: error: 'GenerateSpaces' is neither an array nor a function.

0 commit comments

Comments
 (0)