Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #12834 - add Python tests which show missing de-duplication of input files #6518

Merged
merged 1 commit into from
Jun 20, 2024
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
116 changes: 116 additions & 0 deletions test/cli/more-projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import pytest
import sys
from testutils import cppcheck, assert_cppcheck


Expand Down Expand Up @@ -510,6 +511,121 @@ def test_project_file_duplicate_2(tmpdir):
assert stderr == ''


def test_project_file_duplicate_3(tmpdir):
test_file_a = os.path.join(tmpdir, 'a.c')
with open(test_file_a, 'wt'):
pass

# multiple ways to specify the same file
in_file_a = 'a.c'
in_file_b = os.path.join('.', 'a.c')
in_file_c = os.path.join('dummy', '..', 'a.c')
in_file_d = os.path.join(tmpdir, 'a.c')
in_file_e = os.path.join(tmpdir, '.', 'a.c')
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')

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>
<paths>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
</paths>
</project>""".format(in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, tmpdir))

args = ['--project={}'.format(project_file)]
args.append('-j1') # TODO: remove when fixed

exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
assert exitcode == 0
lines = stdout.splitlines()
# TODO: only a single file should be checked
if sys.platform == 'win32':
assert lines == [
'Checking {} ...'.format(test_file_a),
'1/3 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'2/3 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'3/3 files checked 0% done'
]
else:
assert lines == [
'Checking {} ...'.format(test_file_a),
'1/2 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'2/2 files checked 0% done'
]
assert stderr == ''


@pytest.mark.skipif(sys.platform != 'win32', reason="requires Windows")
def test_project_file_duplicate_4(tmpdir):
test_file_a = os.path.join(tmpdir, 'a.c')
with open(test_file_a, 'wt'):
pass

# multiple ways to specify the same file
in_file_a = 'a.c'
in_file_b = os.path.join('.', 'a.c')
in_file_c = os.path.join('dummy', '..', 'a.c')
in_file_d = os.path.join(tmpdir, 'a.c')
in_file_e = os.path.join(tmpdir, '.', 'a.c')
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')

args1 = [in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, str(tmpdir)]
args2 = []
for a in args1:
args2.append(a.replace('\\', '/'))

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>
<paths>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
<dir name="{}"/>
</paths>
</project>""".format(in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, tmpdir,
args2[0], args2[1], args2[2], args2[3], args2[4], args2[5], args2[6]))

args = ['--project={}'.format(project_file)]
args.append('-j1') # TODO: remove when fixed

exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
assert exitcode == 0
lines = stdout.splitlines()
# TODO: only a single file should be checked
assert lines == [
'Checking {} ...'.format(test_file_a),
'1/3 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'2/3 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'3/3 files checked 0% done'
]
assert stderr == ''

def test_project_file_ignore(tmpdir):
test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
Expand Down
91 changes: 91 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,97 @@ def test_file_duplicate_2(tmpdir):
assert stderr == ''


def test_file_duplicate_3(tmpdir):
test_file_a = os.path.join(tmpdir, 'a.c')
with open(test_file_a, 'wt'):
pass

# multiple ways to specify the same file
in_file_a = 'a.c'
in_file_b = os.path.join('.', 'a.c')
in_file_c = os.path.join('dummy', '..', 'a.c')
in_file_d = os.path.join(tmpdir, 'a.c')
in_file_e = os.path.join(tmpdir, '.', 'a.c')
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')

args = [in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, str(tmpdir)]
args.append('-j1') # TODO: remove when fixed

exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
assert exitcode == 0
lines = stdout.splitlines()
# TODO: only a single file should be checked
if sys.platform == 'win32':
assert lines == [
'Checking {} ...'.format('a.c'),
'1/6 files checked 0% done',
'Checking {} ...'.format('a.c'),
'2/6 files checked 0% done',
'Checking {} ...'.format('a.c'),
'3/6 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'4/6 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'5/6 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'6/6 files checked 0% done'
]
else:
assert lines == [
'Checking {} ...'.format('a.c'),
'1/4 files checked 0% done',
'Checking {} ...'.format('a.c'),
'2/4 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'3/4 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'4/4 files checked 0% done'
]
assert stderr == ''


@pytest.mark.skipif(sys.platform != 'win32', reason="requires Windows")
def test_file_duplicate_4(tmpdir):
test_file_a = os.path.join(tmpdir, 'a.c')
with open(test_file_a, 'wt'):
pass

# multiple ways to specify the same file
in_file_a = 'a.c'
in_file_b = os.path.join('.', 'a.c')
in_file_c = os.path.join('dummy', '..', 'a.c')
in_file_d = os.path.join(tmpdir, 'a.c')
in_file_e = os.path.join(tmpdir, '.', 'a.c')
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')

args1 = [in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, str(tmpdir)]
args2 = []
for a in args1:
args2.append(a.replace('\\', '/'))
args = args1 + args2
args.append('-j1') # TODO: remove when fixed

exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
assert exitcode == 0
lines = stdout.splitlines()
# TODO: only a single file should be checked
assert lines == [
'Checking {} ...'.format('a.c'),
'1/6 files checked 0% done',
'Checking {} ...'.format('a.c'),
'2/6 files checked 0% done',
'Checking {} ...'.format('a.c'),
'3/6 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'4/6 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'5/6 files checked 0% done',
'Checking {} ...'.format(test_file_a),
'6/6 files checked 0% done'
]
assert stderr == ''


def test_file_ignore(tmpdir):
test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt'):
Expand Down
Loading