Skip to content

Commit e00a762

Browse files
committed
Add test
1 parent 3bfe94d commit e00a762

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

test/cli/other_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,41 @@ def test_xml_output(tmp_path): # #13391 / #13485
24262426
'''.format(version_str, test_file_exp, test_file_exp, test_file_exp))
24272427

24282428

2429+
def test_outputfile(tmp_path): # #14051
2430+
test_file = tmp_path / 'test.cpp'
2431+
out_file = tmp_path / 'out.txt'
2432+
with open(test_file, 'wt') as f:
2433+
f.write(
2434+
"""
2435+
int main()
2436+
{
2437+
int x = 1 / 0;
2438+
}
2439+
""")
2440+
2441+
args = [
2442+
'-q',
2443+
'--output-file={}'.format(out_file),
2444+
str(test_file)
2445+
]
2446+
2447+
out_exp = [
2448+
'{}:4:15: error: Division by zero. [zerodiv]'.format(test_file),
2449+
' int x = 1 / 0;',
2450+
' ^',
2451+
]
2452+
2453+
exitcode, stdout, stderr = cppcheck(args)
2454+
assert exitcode == 0, stdout
2455+
assert stdout == ''
2456+
assert stderr == ''
2457+
2458+
with open(out_file, 'rt') as f:
2459+
out_text = f.read();
2460+
2461+
assert out_text.splitlines() == out_exp
2462+
2463+
24292464
def test_internal_error_loc_int(tmp_path):
24302465
test_file = tmp_path / 'test.c'
24312466
with open(test_file, 'wt') as f:

0 commit comments

Comments
 (0)