Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 4 additions & 1 deletion src/api/errmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/libzxbc/zxbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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}'")
Expand Down
3 changes: 3 additions & 0 deletions src/libzxbpp/zxbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")
Expand Down
3 changes: 3 additions & 0 deletions tests/api/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -58,6 +60,7 @@ def test_initted_values(self):
'case_insensitive',
'emitBackend',
'enableBreak',
'expect_warnings',
'explicit',
'include_path',
'inputFileName',
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_cmdline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions tests/functional/test_errmsg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'])