Skip to content

Commit 3861d0b

Browse files
committed
Fixed #12771 (Progress value is not increased)
1 parent 61a9b2e commit 3861d0b

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

cli/processexecutor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ unsigned int ProcessExecutor::check()
407407
fileCount++;
408408
processedsize += size;
409409
if (!mSettings.quiet)
410-
Executor::reportStatus(fileCount, mFiles.size() + mFileSettings.size(), processedsize, totalfilesize);
410+
Executor::reportStatus(fileCount, mFiles.size() + mFileSettings.size(), //processedsize, totalfilesize);
411+
mFileSettings.empty() ? processedsize : fileCount,
412+
mFileSettings.empty() ? totalfilesize : mFileSettings.size());
411413

412414
close(*rp);
413415
rp = rpipes.erase(rp);

cli/threadexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class ThreadData
153153
mProcessedSize += fileSize;
154154
mProcessedFiles++;
155155
if (!mSettings.quiet)
156-
logForwarder.reportStatus(mProcessedFiles, mTotalFiles, mProcessedSize, mTotalFileSize);
156+
logForwarder.reportStatus(mProcessedFiles, mTotalFiles, mTotalFileSize>0 ? mProcessedSize : mProcessedFiles, mTotalFileSize>0 ? mTotalFileSize: mTotalFiles);
157157
}
158158

159159
private:

test/cli/more-projects_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,3 +1061,39 @@ def test_project_file_no_analyze_all_vs_configs(tmp_path):
10611061
ret, stdout, stderr = cppcheck(['--project=' + str(project_path)])
10621062
assert ret == 0, stdout
10631063
assert stderr == ''
1064+
1065+
1066+
@pytest.mark.parametrize("j,executor", [
1067+
(1, "thread"),
1068+
(2, "thread"),
1069+
(2, "process"),
1070+
])
1071+
def test_project_progress(tmp_path, j, executor):
1072+
if sys.platform == 'win32' and executor == "process":
1073+
pytest.skip("process executor not supported on Windows")
1074+
1075+
code = 'x = 1;'
1076+
with open(tmp_path / 'test1.c', 'wt') as f:
1077+
f.write(code)
1078+
with open(tmp_path / 'test2.c', 'wt') as f:
1079+
f.write(code)
1080+
1081+
compilation_db = [
1082+
{"directory": str(tmp_path),
1083+
"command": "gcc -c test1.c",
1084+
"file": "test1.c",
1085+
"output": "test1.o"},
1086+
{"directory": str(tmp_path),
1087+
"command": "gcc -c test2.c",
1088+
"file": "test2.c",
1089+
"output": "test2.o"},
1090+
]
1091+
1092+
project_file = tmp_path / 'compile_commands.json'
1093+
1094+
with open(project_file, 'wt') as f:
1095+
f.write(json.dumps(compilation_db))
1096+
1097+
_, stdout, _ = cppcheck([f'--project={project_file}', f'-j{j}', f'--executor={executor}'])
1098+
assert '1/2 files checked 50% done' in stdout
1099+
assert '2/2 files checked 100% done' in stdout

test/cli/other_test.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,22 +1076,20 @@ def test_markup_j(tmpdir):
10761076
assert exitcode == 0, stdout if stdout else stderr
10771077
lines = stdout.splitlines()
10781078
for i in range(1, 5):
1079-
lines.remove('{}/4 files checked 0% done'.format(i))
1080-
1081-
# this test started to fail in the -j2 injection run when using ThreadExecutor although it always specifies -j2.
1082-
# the order of the files in the output changed so just check for the file extentions
1083-
assert len(lines) == 4
1084-
assert lines[0].endswith('.cpp ...')
1085-
assert lines[1].endswith('.cpp ...')
1086-
assert lines[2].endswith('.qml ...')
1087-
assert lines[3].endswith('.qml ...')
1088-
1089-
#assert lines == [
1090-
# 'Checking {} ...'.format(test_file_2),
1091-
# 'Checking {} ...'.format(test_file_4),
1092-
# 'Checking {} ...'.format(test_file_1),
1093-
# 'Checking {} ...'.format(test_file_3)
1094-
#]
1079+
try:
1080+
if '{}/4 files checked 0% done'.format(i) in lines:
1081+
lines.remove('{}/4 files checked 0% done'.format(i))
1082+
else:
1083+
lines.remove('{}/4 files checked {}% done'.format(i, i * 25))
1084+
except ValueError as e:
1085+
assert False, f'failed {i}'
1086+
1087+
assert sorted(lines) == [
1088+
'Checking {} ...'.format(test_file_1),
1089+
'Checking {} ...'.format(test_file_2),
1090+
'Checking {} ...'.format(test_file_3),
1091+
'Checking {} ...'.format(test_file_4)
1092+
]
10951093
assert stderr == ''
10961094

10971095

0 commit comments

Comments
 (0)