Skip to content

Commit 1093382

Browse files
authored
fail some build steps if changed or unversioned files exist at the end / several related cleanups and adjustments (danmar#6787)
1 parent 35a8a4e commit 1093382

File tree

8 files changed

+85
-22
lines changed

8 files changed

+85
-22
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,22 +398,27 @@ jobs:
398398
run: |
399399
# this is only to test the "install" target - since we did not build with FILESDIR it would not work as intended
400400
make DESTDIR=cppcheck-make-install FILESDIR=/share/Cppcheck install
401+
rm -rf cppcheck-make-install
401402
402403
- name: Test Signalhandler
403404
run: |
404-
cmake -S . -B cmake.output.signal -G "Unix Makefiles" -DBUILD_TESTS=On
405-
cmake --build cmake.output.signal --target test-signalhandler -- -j$(nproc)
406-
cp cmake.output.signal/bin/test-s* .
405+
cmake -S . -B build.cmake.signal -G "Unix Makefiles" -DBUILD_TESTS=On
406+
cmake --build build.cmake.signal --target test-signalhandler -- -j$(nproc)
407+
# TODO: how to run this without copying the file?
408+
cp build.cmake.signal/bin/test-s* .
407409
python3 -m pytest -Werror --strict-markers -vv test/signal/test-signalhandler.py
410+
rm test-signalhandler
408411
409412
# no unix backtrace support on MacOs
410413
- name: Test Stacktrace
411414
if: contains(matrix.os, 'ubuntu')
412415
run: |
413-
cmake -S . -B cmake.output.signal -G "Unix Makefiles" -DBUILD_TESTS=On
414-
cmake --build cmake.output.signal --target test-stacktrace -- -j$(nproc)
415-
cp cmake.output.signal/bin/test-s* .
416+
cmake -S . -B build.cmake.stack -G "Unix Makefiles" -DBUILD_TESTS=On
417+
cmake --build build.cmake.stack --target test-stacktrace -- -j$(nproc)
418+
# TODO: how to run this without copying the file?
419+
cp build.cmake.stack/bin/test-s* .
416420
python3 -m pytest -Werror --strict-markers -vv test/signal/test-stacktrace.py
421+
rm test-stacktrace
417422
418423
# TODO: move to scriptcheck.yml so these are tested with all Python versions?
419424
- name: Test addons
@@ -469,6 +474,17 @@ jobs:
469474
warnings="-pedantic -Wall -Wextra -Wcast-qual -Wno-deprecated-declarations -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar"
470475
g++ $warnings -c -Ilib -Iexternals/tinyxml2 democlient/democlient.cpp
471476
477+
- name: Show all ignored files
478+
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
479+
run: |
480+
git ls-files --others --ignored --exclude-standard
481+
482+
- name: Check for changed and unversioned files
483+
run: |
484+
# TODO: how to do this with a single command?
485+
git status --ignored=no
486+
git status --ignored=no | grep -q 'working tree clean'
487+
472488
selfcheck:
473489
needs: build # wait for all tests to be successful first
474490

.github/workflows/CI-windows.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,15 @@ jobs:
251251
cd test\cfg
252252
cl.exe windows.cpp -DUNICODE=1 -D_UNICODE=1 /Zs || exit /b !errorlevel!
253253
cl.exe mfc.cpp /EHsc /Zs || exit /b !errorlevel!
254+
255+
- name: Show all ignored files
256+
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
257+
run: |
258+
git ls-files --others --ignored --exclude-standard || exit /b !errorlevel!
259+
260+
- name: Check for changed and unversioned files
261+
run: |
262+
:: TODO: how to do this with a single command?
263+
git status --ignored=no
264+
:: TODO: make this work
265+
:: git status --ignored=no | grep -q 'working tree clean'

.github/workflows/scriptcheck.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,22 @@ jobs:
187187
- name: test donate_cpu_server
188188
run: |
189189
python -m pytest -Werror --strict-markers -vv tools/donate_cpu_server_test.py
190+
# TODO: why is this file generated? also should be in a temporary folder if possible
191+
rm -f tools/donate-cpu-server.log
190192
env:
191193
PYTHONPATH: ./tools
192194

195+
- name: Show all ignored files
196+
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
197+
run: |
198+
git ls-files --others --ignored --exclude-standard
199+
200+
- name: Check for changed and unversioned files
201+
run: |
202+
# TODO: how to do this with a single command?
203+
git status --ignored=no
204+
git status --ignored=no | grep -q 'working tree clean'
205+
193206
dmake:
194207
strategy:
195208
matrix:

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,10 @@ compile_commands.json
119119
/addons/misra.spec
120120
/htmlreport/cppcheck-htmlreport.spec
121121
/htmlreport/dist
122+
123+
# ccache folder in CI
124+
/.ccache
125+
126+
# PCRE Windows files
127+
/externals/pcre.h
128+
/externals/pcre64.lib

test/cli/clang-import_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def __check_symbol_database(tmpdir, code):
4949
f.write(code)
5050
ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile])
5151
ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile])
52-
os.remove(testfile)
5352
assert 0 == ret1, stdout1
5453
assert 0 == ret2, stdout2
5554
assert __get_debug_section('### Symbol database', stdout1) == __get_debug_section('### Symbol database', stdout2)
@@ -61,7 +60,6 @@ def __check_ast(tmpdir, code):
6160
f.write(code)
6261
ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile])
6362
ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile])
64-
os.remove(testfile)
6563
assert 0 == ret1, stdout1
6664
assert 0 == ret2, stdout1
6765
assert __get_debug_section('##AST', stdout1) == __get_debug_section('##AST', stdout2)

test/cli/helloworld_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ def test_addon_relative_path():
110110

111111
def test_addon_with_gui_project():
112112
project_file = os.path.join('helloworld', 'test.cppcheck')
113+
# TODO: generate in temporary folder
113114
create_gui_project_file(os.path.join(__script_dir, project_file), paths=['.'], addon='misra')
114115
args = [
115116
'--template=cppcheck1',
116117
'--enable=style',
117118
'--project=' + project_file
118119
]
119120
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
121+
os.remove(os.path.join(__script_dir, project_file)) # TODO: do not remove explicitly
120122
filename = os.path.join('helloworld', 'main.c')
121123
assert ret == 0, stdout
122124
assert stdout == 'Checking %s ...\n' % filename
@@ -230,6 +232,7 @@ def test_suppress_command_line_absolute():
230232

231233
def test_suppress_project_relative():
232234
project_file = os.path.join('helloworld', 'test.cppcheck')
235+
# TODO: generate in temporary folder
233236
create_gui_project_file(os.path.join(__script_dir, project_file),
234237
paths=['.'],
235238
suppressions=[{'fileName':'main.c', 'id':'zerodiv'}])
@@ -239,12 +242,14 @@ def test_suppress_project_relative():
239242
]
240243

241244
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
245+
os.remove(os.path.join(__script_dir, project_file)) # TODO: do not remove explicitly
242246
assert ret == 0, stdout
243247
assert stderr == ''
244248

245249

246250
def test_suppress_project_absolute():
247251
project_file = os.path.join('helloworld', 'test.cppcheck')
252+
# TODO: generate in temporary folder
248253
create_gui_project_file(os.path.join(__script_dir, project_file),
249254
paths=['.'],
250255
suppressions=[{'fileName':'main.c', 'id':'zerodiv'}])
@@ -254,6 +259,7 @@ def test_suppress_project_absolute():
254259
]
255260

256261
ret, stdout, stderr = cppcheck(args)
262+
os.remove(os.path.join(__script_dir, project_file)) # TODO: do not remove explicitly
257263
assert ret == 0, stdout
258264
assert stderr == ''
259265

test/cli/proj2_test.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ def test_gui_project_loads_compile_commands_1():
8585
def test_gui_project_loads_compile_commands_2():
8686
__create_compile_commands()
8787
exclude_path_1 = 'proj2/b'
88+
# TODO: generate in temporary folder
8889
create_gui_project_file(os.path.join(__proj_dir, 'test.cppcheck'),
8990
import_project='compile_commands.json',
9091
exclude_paths=[exclude_path_1])
9192
ret, stdout, _ = cppcheck(['--project=' + os.path.join('proj2','test.cppcheck')], cwd=__script_dir)
93+
os.remove(os.path.join(__proj_dir, 'test.cppcheck')) # TODO: do not remove explicitly
9294
file1 = os.path.join('proj2', 'a', 'a.c')
9395
file2 = os.path.join('proj2', 'b', 'b.c') # Excluded by test.cppcheck
9496
assert ret == 0, stdout
@@ -97,8 +99,9 @@ def test_gui_project_loads_compile_commands_2():
9799

98100

99101
def test_gui_project_loads_relative_vs_solution():
100-
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project='proj2/proj2.sln')
102+
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project='proj2/proj2.sln') # TODO: generate in temporary folder
101103
ret, stdout, _ = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
104+
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
102105
file1 = os.path.join('proj2', 'a', 'a.c')
103106
file2 = os.path.join('proj2', 'b', 'b.c')
104107
assert ret == 0, stdout
@@ -112,8 +115,9 @@ def test_gui_project_loads_relative_vs_solution():
112115
assert stdout.find('Checking %s Release|x64...' % file2) >= 0
113116

114117
def test_gui_project_loads_absolute_vs_solution():
115-
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project=os.path.join(__proj_dir, 'proj2.sln'))
118+
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project=os.path.join(__proj_dir, 'proj2.sln')) # TODO: generate in temporary folder
116119
ret, stdout, _ = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
120+
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
117121
file1 = os.path.join(__proj_dir, 'a', 'a.c')
118122
file2 = os.path.join(__proj_dir, 'b', 'b.c')
119123
assert ret == 0, stdout
@@ -127,21 +131,25 @@ def test_gui_project_loads_absolute_vs_solution():
127131
assert stdout.find('Checking %s Release|x64...' % file2) >= 0
128132

129133
def test_gui_project_loads_relative_vs_solution_2():
130-
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln')
134+
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln') # TODO: generate in temporary folder
131135
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
136+
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
132137
assert ret == 0, stdout
133138
assert stderr == __ERR_A + __ERR_B
134139

135140
def test_gui_project_loads_relative_vs_solution_with_exclude():
136-
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln', exclude_paths=['b'])
141+
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln', exclude_paths=['b']) # TODO: generate in temporary folder
137142
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
143+
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
138144
assert ret == 0, stdout
139145
assert stderr == __ERR_A
140146

141147
def test_gui_project_loads_absolute_vs_solution_2():
148+
# TODO: generate in temporary folder
142149
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'),
143150
root_path=__proj_dir,
144151
import_project=os.path.join(__proj_dir, 'proj2.sln'))
145152
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
153+
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
146154
assert ret == 0, stdout
147155
assert stderr == __ERR_A + __ERR_B

test/tools/htmlreport/test_htmlreport.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import os
55
import contextlib
6-
import shutil
76
import subprocess
87
import sys
98
import tempfile
@@ -37,7 +36,7 @@ def checkReportError(self, xml_version):
3736
self.assertIn('Memory leak:', report)
3837
self.assertIn('bad.c', report)
3938

40-
detail_filename = os.path.join(output_directory, '0.html')
39+
detail_filename = os.path.join(output_directory.name, '0.html')
4140
self.assertTrue(
4241
os.path.exists(detail_filename))
4342

@@ -46,6 +45,8 @@ def checkReportError(self, xml_version):
4645
self.assertIn('<html', detail_contents)
4746
self.assertIn('Memory leak:', detail_contents)
4847

48+
output_directory.cleanup()
49+
4950
def testReportNoError(self):
5051
for xml_version in ['2']:
5152
self.checkReportNoError(xml_version)
@@ -61,7 +62,9 @@ def checkReportNoError(self, xml_version):
6162
self.assertNotIn('good.c', report)
6263

6364
self.assertFalse(
64-
os.path.exists(os.path.join(output_directory, '0.html')))
65+
os.path.exists(os.path.join(output_directory.name, '0.html')))
66+
67+
output_directory.cleanup()
6568

6669
def testMissingInclude(self):
6770
with runCheck(
@@ -73,7 +76,9 @@ def testMissingInclude(self):
7376
self.assertIn('example.cc', report)
7477

7578
self.assertTrue(
76-
os.path.exists(os.path.join(output_directory, '0.html')))
79+
os.path.exists(os.path.join(output_directory.name, '0.html')))
80+
81+
output_directory.cleanup()
7782

7883

7984
@contextlib.contextmanager
@@ -84,10 +89,10 @@ def runCheck(source_filename=None, xml_version='1', xml_filename=None):
8489
path.
8590
8691
"""
87-
output_directory = tempfile.mkdtemp(dir='.')
92+
output_directory = tempfile.TemporaryDirectory(dir='.')
8893
if xml_filename is None:
8994
assert source_filename
90-
xml_filename = os.path.join(output_directory, 'output.xml')
95+
xml_filename = os.path.join(output_directory.name, 'output.xml')
9196

9297
with open(xml_filename, 'w') as output_file:
9398
subprocess.check_call(
@@ -100,16 +105,14 @@ def runCheck(source_filename=None, xml_version='1', xml_filename=None):
100105
subprocess.check_call(
101106
[*HTML_REPORT_BIN,
102107
'--file=' + os.path.realpath(xml_filename),
103-
'--report-dir=' + os.path.realpath(output_directory)],
108+
'--report-dir=' + os.path.realpath(output_directory.name)],
104109
cwd=TEST_TOOLS_DIR)
105110

106-
with open(os.path.join(output_directory, 'index.html')) as index_file:
111+
with open(os.path.join(output_directory.name, 'index.html')) as index_file:
107112
index_contents = index_file.read()
108113

109114
yield index_contents, output_directory
110115

111-
shutil.rmtree(output_directory)
112-
113116

114117
if __name__ == '__main__':
115118
unittest.main()

0 commit comments

Comments
 (0)