Skip to content

Commit

Permalink
refs #12918 - added test showing -D being lost when specified befor…
Browse files Browse the repository at this point in the history
…e cppcheck GUI project on command-line (#6578)
  • Loading branch information
firewave authored Jul 10, 2024
1 parent 73682da commit ef5439e
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion test/cli/more-projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,94 @@ def test_json_file_ignore_2(tmpdir):
'cppcheck: all paths were ignored'
]

assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)


@pytest.mark.xfail(strict=True)
def test_project_D(tmpdir):
test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
f.write("""
#ifndef __GNUC__
#error "requirement not met"
#endif
""")

project_file = os.path.join(tmpdir, 'test.cppcheck')
with open(project_file, 'wt') as f:
f.write(
"""
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<paths>
<dir name="{}"/>
</paths>
</project>
""".format(test_file))

args = [
'--project=' + project_file,
'--template=simple',
]
arg_D = ['-D__GNUC__']

out_expected = [
'Checking {} ...'.format(test_file),
'Checking {}: __GNUC__=1...'.format(test_file)
]

args1 = args + arg_D
ret, stdout, stderr = cppcheck(args1)
assert stdout.splitlines() == out_expected
assert stderr.splitlines() == []
assert ret == 0, stdout

# TODO: -D__GNUC__ is lost
args2 = arg_D + args
ret, stdout, stderr = cppcheck(args2)
assert stdout.splitlines() == out_expected
assert stderr.splitlines() == []
assert ret == 0, stdout


def test_compdb_D(tmpdir):
test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
f.write("""
#ifndef __GNUC__
#error "requirement not met"
#endif
""")

compile_commands = os.path.join(tmpdir, 'compile_commands.json')
compilation_db = [
{"directory": str(tmpdir),
"command": "c++ -o test.o -c test.cpp",
"file": "test.cpp",
"output": "test.o"}
]
with open(compile_commands, 'wt') as f:
f.write(json.dumps(compilation_db))

args = [
'--project=' + compile_commands,
'--template=simple',
]
arg_D = ['-D__GNUC__']

out_expected = [
'Checking {} ...'.format(test_file),
'Checking {}: __GNUC__=1;...'.format(test_file) # TODO: get rid of extra ;
]

args1 = args + arg_D
ret, stdout, stderr = cppcheck(args1)
assert stdout.splitlines() == out_expected
assert stderr.splitlines() == []
assert ret == 0, stdout

args2 = arg_D + args
ret, stdout, stderr = cppcheck(args2)
assert stdout.splitlines() == out_expected
assert stderr.splitlines() == []
assert ret == 0, stdout

0 comments on commit ef5439e

Please sign in to comment.