Skip to content

Commit 85338f8

Browse files
committed
test/cli/other_test.py: added some tests for preprocessor errors
1 parent 76db5ec commit 85338f8

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

test/cli/other_test.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,3 +3853,100 @@ def test_unmatched_file(tmp_path): # #14248 / #14249
38533853
f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
38543854
]
38553855
assert ret == 0, stdout
3856+
3857+
3858+
def test_simplecpp_warning(tmp_path):
3859+
test_file = tmp_path / 'test.c'
3860+
with open(test_file, "w") as f:
3861+
f.write(
3862+
"""
3863+
#define warning "warn msg"
3864+
""")
3865+
3866+
args = [
3867+
'-q',
3868+
'--template=simple',
3869+
str(test_file)
3870+
]
3871+
3872+
exitcode, stdout, stderr = cppcheck(args)
3873+
assert exitcode == 0, stdout
3874+
assert stdout.splitlines() == []
3875+
assert stderr.splitlines() == []
3876+
3877+
3878+
def test_simplecpp_unhandled_char(tmp_path):
3879+
test_file = tmp_path / 'test.c'
3880+
with open(test_file, "w") as f:
3881+
f.write(
3882+
"""
3883+
int 你=0;
3884+
""")
3885+
3886+
args = [
3887+
'-q',
3888+
'--template=simple',
3889+
str(test_file)
3890+
]
3891+
3892+
exitcode, stdout, stderr = cppcheck(args)
3893+
assert exitcode == 0, stdout
3894+
assert stdout.splitlines() == []
3895+
assert stderr.splitlines() == [
3896+
# TODO: should report another ID
3897+
'{}:2:5: error: The code contains unhandled character(s) (character code=228). Neither unicode nor extended ascii is supported. [syntaxError]'.format(test_file)
3898+
]
3899+
3900+
3901+
def test_simplecpp_include_nested_too_deeply(tmp_path):
3902+
test_file = tmp_path / 'test.c'
3903+
with open(test_file, "w") as f:
3904+
f.write('#include "test.h"')
3905+
3906+
test_h = tmp_path / 'test.h'
3907+
with open(test_h, "w") as f:
3908+
f.write('#include "test_0.h"')
3909+
3910+
for i in range(400):
3911+
test_h = tmp_path / f'test_{i}.h'
3912+
with open(test_h, "w") as f:
3913+
f.write('#include "test_{}.h"'.format(i+1))
3914+
3915+
args = [
3916+
'-q',
3917+
'--template=simple',
3918+
str(test_file)
3919+
]
3920+
3921+
exitcode, stdout, stderr = cppcheck(args)
3922+
assert exitcode == 0, stdout
3923+
assert stdout.splitlines() == []
3924+
test_h = tmp_path / 'test_398.h'
3925+
assert stderr.splitlines() == [
3926+
# TODO: should only report the error once
3927+
# TODO: should report another ID
3928+
'{}:1:0: error: #include nested too deeply [preprocessorErrorDirective]'.format(test_h),
3929+
'{}:1:2: error: #include nested too deeply [preprocessorErrorDirective]'.format(test_h)
3930+
]
3931+
3932+
3933+
def test_simplecpp_syntax_error(tmp_path):
3934+
test_file = tmp_path / 'test.c'
3935+
with open(test_file, "w") as f:
3936+
f.write('#include ""')
3937+
3938+
args = [
3939+
'-q',
3940+
'--template=simple',
3941+
str(test_file)
3942+
]
3943+
3944+
exitcode, stdout, stderr = cppcheck(args)
3945+
assert exitcode == 0, stdout
3946+
assert stdout.splitlines() == []
3947+
assert stderr.splitlines() == [
3948+
# TODO: should only report the error once
3949+
# TODO: should report another ID
3950+
'{}:1:0: error: No header in #include [preprocessorErrorDirective]'.format(test_file),
3951+
'{}:1:2: error: No header in #include [preprocessorErrorDirective]'.format(test_file)
3952+
]

0 commit comments

Comments
 (0)