Skip to content

Commit 3410d1b

Browse files
authored
refs #12834 - add Python tests which show missing de-duplication of input files (#6518)
1 parent 181207c commit 3410d1b

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

Diff for: test/cli/more-projects_test.py

+116
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import pytest
5+
import sys
56
from testutils import cppcheck, assert_cppcheck
67

78

@@ -510,6 +511,121 @@ def test_project_file_duplicate_2(tmpdir):
510511
assert stderr == ''
511512

512513

514+
def test_project_file_duplicate_3(tmpdir):
515+
test_file_a = os.path.join(tmpdir, 'a.c')
516+
with open(test_file_a, 'wt'):
517+
pass
518+
519+
# multiple ways to specify the same file
520+
in_file_a = 'a.c'
521+
in_file_b = os.path.join('.', 'a.c')
522+
in_file_c = os.path.join('dummy', '..', 'a.c')
523+
in_file_d = os.path.join(tmpdir, 'a.c')
524+
in_file_e = os.path.join(tmpdir, '.', 'a.c')
525+
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')
526+
527+
project_file = os.path.join(tmpdir, 'test.cppcheck')
528+
with open(project_file, 'wt') as f:
529+
f.write(
530+
"""<?xml version="1.0" encoding="UTF-8"?>
531+
<project>
532+
<paths>
533+
<dir name="{}"/>
534+
<dir name="{}"/>
535+
<dir name="{}"/>
536+
<dir name="{}"/>
537+
<dir name="{}"/>
538+
<dir name="{}"/>
539+
<dir name="{}"/>
540+
</paths>
541+
</project>""".format(in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, tmpdir))
542+
543+
args = ['--project={}'.format(project_file)]
544+
args.append('-j1') # TODO: remove when fixed
545+
546+
exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
547+
assert exitcode == 0
548+
lines = stdout.splitlines()
549+
# TODO: only a single file should be checked
550+
if sys.platform == 'win32':
551+
assert lines == [
552+
'Checking {} ...'.format(test_file_a),
553+
'1/3 files checked 0% done',
554+
'Checking {} ...'.format(test_file_a),
555+
'2/3 files checked 0% done',
556+
'Checking {} ...'.format(test_file_a),
557+
'3/3 files checked 0% done'
558+
]
559+
else:
560+
assert lines == [
561+
'Checking {} ...'.format(test_file_a),
562+
'1/2 files checked 0% done',
563+
'Checking {} ...'.format(test_file_a),
564+
'2/2 files checked 0% done'
565+
]
566+
assert stderr == ''
567+
568+
569+
@pytest.mark.skipif(sys.platform != 'win32', reason="requires Windows")
570+
def test_project_file_duplicate_4(tmpdir):
571+
test_file_a = os.path.join(tmpdir, 'a.c')
572+
with open(test_file_a, 'wt'):
573+
pass
574+
575+
# multiple ways to specify the same file
576+
in_file_a = 'a.c'
577+
in_file_b = os.path.join('.', 'a.c')
578+
in_file_c = os.path.join('dummy', '..', 'a.c')
579+
in_file_d = os.path.join(tmpdir, 'a.c')
580+
in_file_e = os.path.join(tmpdir, '.', 'a.c')
581+
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')
582+
583+
args1 = [in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, str(tmpdir)]
584+
args2 = []
585+
for a in args1:
586+
args2.append(a.replace('\\', '/'))
587+
588+
project_file = os.path.join(tmpdir, 'test.cppcheck')
589+
with open(project_file, 'wt') as f:
590+
f.write(
591+
"""<?xml version="1.0" encoding="UTF-8"?>
592+
<project>
593+
<paths>
594+
<dir name="{}"/>
595+
<dir name="{}"/>
596+
<dir name="{}"/>
597+
<dir name="{}"/>
598+
<dir name="{}"/>
599+
<dir name="{}"/>
600+
<dir name="{}"/>
601+
<dir name="{}"/>
602+
<dir name="{}"/>
603+
<dir name="{}"/>
604+
<dir name="{}"/>
605+
<dir name="{}"/>
606+
<dir name="{}"/>
607+
<dir name="{}"/>
608+
</paths>
609+
</project>""".format(in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, tmpdir,
610+
args2[0], args2[1], args2[2], args2[3], args2[4], args2[5], args2[6]))
611+
612+
args = ['--project={}'.format(project_file)]
613+
args.append('-j1') # TODO: remove when fixed
614+
615+
exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
616+
assert exitcode == 0
617+
lines = stdout.splitlines()
618+
# TODO: only a single file should be checked
619+
assert lines == [
620+
'Checking {} ...'.format(test_file_a),
621+
'1/3 files checked 0% done',
622+
'Checking {} ...'.format(test_file_a),
623+
'2/3 files checked 0% done',
624+
'Checking {} ...'.format(test_file_a),
625+
'3/3 files checked 0% done'
626+
]
627+
assert stderr == ''
628+
513629
def test_project_file_ignore(tmpdir):
514630
test_file = os.path.join(tmpdir, 'test.cpp')
515631
with open(test_file, 'wt') as f:

Diff for: test/cli/other_test.py

+91
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,97 @@ def test_file_duplicate_2(tmpdir):
11381138
assert stderr == ''
11391139

11401140

1141+
def test_file_duplicate_3(tmpdir):
1142+
test_file_a = os.path.join(tmpdir, 'a.c')
1143+
with open(test_file_a, 'wt'):
1144+
pass
1145+
1146+
# multiple ways to specify the same file
1147+
in_file_a = 'a.c'
1148+
in_file_b = os.path.join('.', 'a.c')
1149+
in_file_c = os.path.join('dummy', '..', 'a.c')
1150+
in_file_d = os.path.join(tmpdir, 'a.c')
1151+
in_file_e = os.path.join(tmpdir, '.', 'a.c')
1152+
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')
1153+
1154+
args = [in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, str(tmpdir)]
1155+
args.append('-j1') # TODO: remove when fixed
1156+
1157+
exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
1158+
assert exitcode == 0
1159+
lines = stdout.splitlines()
1160+
# TODO: only a single file should be checked
1161+
if sys.platform == 'win32':
1162+
assert lines == [
1163+
'Checking {} ...'.format('a.c'),
1164+
'1/6 files checked 0% done',
1165+
'Checking {} ...'.format('a.c'),
1166+
'2/6 files checked 0% done',
1167+
'Checking {} ...'.format('a.c'),
1168+
'3/6 files checked 0% done',
1169+
'Checking {} ...'.format(test_file_a),
1170+
'4/6 files checked 0% done',
1171+
'Checking {} ...'.format(test_file_a),
1172+
'5/6 files checked 0% done',
1173+
'Checking {} ...'.format(test_file_a),
1174+
'6/6 files checked 0% done'
1175+
]
1176+
else:
1177+
assert lines == [
1178+
'Checking {} ...'.format('a.c'),
1179+
'1/4 files checked 0% done',
1180+
'Checking {} ...'.format('a.c'),
1181+
'2/4 files checked 0% done',
1182+
'Checking {} ...'.format(test_file_a),
1183+
'3/4 files checked 0% done',
1184+
'Checking {} ...'.format(test_file_a),
1185+
'4/4 files checked 0% done'
1186+
]
1187+
assert stderr == ''
1188+
1189+
1190+
@pytest.mark.skipif(sys.platform != 'win32', reason="requires Windows")
1191+
def test_file_duplicate_4(tmpdir):
1192+
test_file_a = os.path.join(tmpdir, 'a.c')
1193+
with open(test_file_a, 'wt'):
1194+
pass
1195+
1196+
# multiple ways to specify the same file
1197+
in_file_a = 'a.c'
1198+
in_file_b = os.path.join('.', 'a.c')
1199+
in_file_c = os.path.join('dummy', '..', 'a.c')
1200+
in_file_d = os.path.join(tmpdir, 'a.c')
1201+
in_file_e = os.path.join(tmpdir, '.', 'a.c')
1202+
in_file_f = os.path.join(tmpdir, 'dummy', '..', 'a.c')
1203+
1204+
args1 = [in_file_a, in_file_b, in_file_c, in_file_d, in_file_e, in_file_f, str(tmpdir)]
1205+
args2 = []
1206+
for a in args1:
1207+
args2.append(a.replace('\\', '/'))
1208+
args = args1 + args2
1209+
args.append('-j1') # TODO: remove when fixed
1210+
1211+
exitcode, stdout, stderr = cppcheck(args, cwd=tmpdir)
1212+
assert exitcode == 0
1213+
lines = stdout.splitlines()
1214+
# TODO: only a single file should be checked
1215+
assert lines == [
1216+
'Checking {} ...'.format('a.c'),
1217+
'1/6 files checked 0% done',
1218+
'Checking {} ...'.format('a.c'),
1219+
'2/6 files checked 0% done',
1220+
'Checking {} ...'.format('a.c'),
1221+
'3/6 files checked 0% done',
1222+
'Checking {} ...'.format(test_file_a),
1223+
'4/6 files checked 0% done',
1224+
'Checking {} ...'.format(test_file_a),
1225+
'5/6 files checked 0% done',
1226+
'Checking {} ...'.format(test_file_a),
1227+
'6/6 files checked 0% done'
1228+
]
1229+
assert stderr == ''
1230+
1231+
11411232
def test_file_ignore(tmpdir):
11421233
test_file = os.path.join(tmpdir, 'test.cpp')
11431234
with open(test_file, 'wt'):

0 commit comments

Comments
 (0)