Skip to content

Commit 3fa7da0

Browse files
authored
Merge pull request #433 from boriel/feature/allow_silencing_n_first_warnings
Allow silencing N warnings
2 parents 525a7d9 + af5fa46 commit 3fa7da0

7 files changed

Lines changed: 20 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}'")

src/libzxbpp/zxbpp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,13 @@ def entry_point(args=None):
865865
parser.add_argument('--arch', type=str, default=arch.AVAILABLE_ARCHITECTURES[0],
866866
help=f"Target architecture (defaults is'{arch.AVAILABLE_ARCHITECTURES[0]}'). "
867867
f"Available architectures: {','.join(arch.AVAILABLE_ARCHITECTURES)}")
868+
parser.add_argument('--expect-warnings', default=OPTIONS.expect_warnings, type=int,
869+
help='Expects N warnings: first N warnings will be silenced')
868870

869871
options = parser.parse_args(args=args)
870872
OPTIONS.Debug = options.debug
871873
OPTIONS.debug_zxbpp = OPTIONS.Debug > 0
874+
OPTIONS.expect_warnings = options.expect_warnings
872875

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

tests/api/test_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def test_init(self):
3636
self.assertEqual(config.OPTIONS.enableBreak, False)
3737
self.assertEqual(config.OPTIONS.emitBackend, False)
3838
self.assertIsNone(config.OPTIONS.architecture)
39+
self.assertEqual(config.OPTIONS.expect_warnings, 0)
40+
3941
# private options that cannot be accessed with #pragma
4042
self.assertEqual(config.OPTIONS['__DEFINES'].value, {})
4143
self.assertEqual(config.OPTIONS.explicit, False)
@@ -58,6 +60,7 @@ def test_initted_values(self):
5860
'case_insensitive',
5961
'emitBackend',
6062
'enableBreak',
63+
'expect_warnings',
6164
'explicit',
6265
'include_path',
6366
'inputFileName',

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,8 @@ 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.
183+
>>> process_file('prepro77.bi', ['-S', '-q', '-O --expect-warnings=1'])

0 commit comments

Comments
 (0)