Skip to content

Commit

Permalink
fail some build steps if changed or unversioned files exist at the en…
Browse files Browse the repository at this point in the history
…d / several related cleanups and adjustments (#6787)
  • Loading branch information
firewave authored Dec 15, 2024
1 parent 35a8a4e commit 1093382
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 22 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,22 +398,27 @@ jobs:
run: |
# this is only to test the "install" target - since we did not build with FILESDIR it would not work as intended
make DESTDIR=cppcheck-make-install FILESDIR=/share/Cppcheck install
rm -rf cppcheck-make-install
- name: Test Signalhandler
run: |
cmake -S . -B cmake.output.signal -G "Unix Makefiles" -DBUILD_TESTS=On
cmake --build cmake.output.signal --target test-signalhandler -- -j$(nproc)
cp cmake.output.signal/bin/test-s* .
cmake -S . -B build.cmake.signal -G "Unix Makefiles" -DBUILD_TESTS=On
cmake --build build.cmake.signal --target test-signalhandler -- -j$(nproc)
# TODO: how to run this without copying the file?
cp build.cmake.signal/bin/test-s* .
python3 -m pytest -Werror --strict-markers -vv test/signal/test-signalhandler.py
rm test-signalhandler
# no unix backtrace support on MacOs
- name: Test Stacktrace
if: contains(matrix.os, 'ubuntu')
run: |
cmake -S . -B cmake.output.signal -G "Unix Makefiles" -DBUILD_TESTS=On
cmake --build cmake.output.signal --target test-stacktrace -- -j$(nproc)
cp cmake.output.signal/bin/test-s* .
cmake -S . -B build.cmake.stack -G "Unix Makefiles" -DBUILD_TESTS=On
cmake --build build.cmake.stack --target test-stacktrace -- -j$(nproc)
# TODO: how to run this without copying the file?
cp build.cmake.stack/bin/test-s* .
python3 -m pytest -Werror --strict-markers -vv test/signal/test-stacktrace.py
rm test-stacktrace
# TODO: move to scriptcheck.yml so these are tested with all Python versions?
- name: Test addons
Expand Down Expand Up @@ -469,6 +474,17 @@ jobs:
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"
g++ $warnings -c -Ilib -Iexternals/tinyxml2 democlient/democlient.cpp
- name: Show all ignored files
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
run: |
git ls-files --others --ignored --exclude-standard
- name: Check for changed and unversioned files
run: |
# TODO: how to do this with a single command?
git status --ignored=no
git status --ignored=no | grep -q 'working tree clean'
selfcheck:
needs: build # wait for all tests to be successful first

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,15 @@ jobs:
cd test\cfg
cl.exe windows.cpp -DUNICODE=1 -D_UNICODE=1 /Zs || exit /b !errorlevel!
cl.exe mfc.cpp /EHsc /Zs || exit /b !errorlevel!
- name: Show all ignored files
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
run: |
git ls-files --others --ignored --exclude-standard || exit /b !errorlevel!
- name: Check for changed and unversioned files
run: |
:: TODO: how to do this with a single command?
git status --ignored=no
:: TODO: make this work
:: git status --ignored=no | grep -q 'working tree clean'
13 changes: 13 additions & 0 deletions .github/workflows/scriptcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,22 @@ jobs:
- name: test donate_cpu_server
run: |
python -m pytest -Werror --strict-markers -vv tools/donate_cpu_server_test.py
# TODO: why is this file generated? also should be in a temporary folder if possible
rm -f tools/donate-cpu-server.log
env:
PYTHONPATH: ./tools

- name: Show all ignored files
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
run: |
git ls-files --others --ignored --exclude-standard
- name: Check for changed and unversioned files
run: |
# TODO: how to do this with a single command?
git status --ignored=no
git status --ignored=no | grep -q 'working tree clean'
dmake:
strategy:
matrix:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,10 @@ compile_commands.json
/addons/misra.spec
/htmlreport/cppcheck-htmlreport.spec
/htmlreport/dist

# ccache folder in CI
/.ccache

# PCRE Windows files
/externals/pcre.h
/externals/pcre64.lib
2 changes: 0 additions & 2 deletions test/cli/clang-import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __check_symbol_database(tmpdir, code):
f.write(code)
ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile])
ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile])
os.remove(testfile)
assert 0 == ret1, stdout1
assert 0 == ret2, stdout2
assert __get_debug_section('### Symbol database', stdout1) == __get_debug_section('### Symbol database', stdout2)
Expand All @@ -61,7 +60,6 @@ def __check_ast(tmpdir, code):
f.write(code)
ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile])
ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile])
os.remove(testfile)
assert 0 == ret1, stdout1
assert 0 == ret2, stdout1
assert __get_debug_section('##AST', stdout1) == __get_debug_section('##AST', stdout2)
Expand Down
6 changes: 6 additions & 0 deletions test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ def test_addon_relative_path():

def test_addon_with_gui_project():
project_file = os.path.join('helloworld', 'test.cppcheck')
# TODO: generate in temporary folder
create_gui_project_file(os.path.join(__script_dir, project_file), paths=['.'], addon='misra')
args = [
'--template=cppcheck1',
'--enable=style',
'--project=' + project_file
]
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
os.remove(os.path.join(__script_dir, project_file)) # TODO: do not remove explicitly
filename = os.path.join('helloworld', 'main.c')
assert ret == 0, stdout
assert stdout == 'Checking %s ...\n' % filename
Expand Down Expand Up @@ -230,6 +232,7 @@ def test_suppress_command_line_absolute():

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

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


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

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

Expand Down
16 changes: 12 additions & 4 deletions test/cli/proj2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ def test_gui_project_loads_compile_commands_1():
def test_gui_project_loads_compile_commands_2():
__create_compile_commands()
exclude_path_1 = 'proj2/b'
# TODO: generate in temporary folder
create_gui_project_file(os.path.join(__proj_dir, 'test.cppcheck'),
import_project='compile_commands.json',
exclude_paths=[exclude_path_1])
ret, stdout, _ = cppcheck(['--project=' + os.path.join('proj2','test.cppcheck')], cwd=__script_dir)
os.remove(os.path.join(__proj_dir, 'test.cppcheck')) # TODO: do not remove explicitly
file1 = os.path.join('proj2', 'a', 'a.c')
file2 = os.path.join('proj2', 'b', 'b.c') # Excluded by test.cppcheck
assert ret == 0, stdout
Expand All @@ -97,8 +99,9 @@ def test_gui_project_loads_compile_commands_2():


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

def test_gui_project_loads_absolute_vs_solution():
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project=os.path.join(__proj_dir, 'proj2.sln'))
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
ret, stdout, _ = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
file1 = os.path.join(__proj_dir, 'a', 'a.c')
file2 = os.path.join(__proj_dir, 'b', 'b.c')
assert ret == 0, stdout
Expand All @@ -127,21 +131,25 @@ def test_gui_project_loads_absolute_vs_solution():
assert stdout.find('Checking %s Release|x64...' % file2) >= 0

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

def test_gui_project_loads_relative_vs_solution_with_exclude():
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln', exclude_paths=['b'])
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
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
assert ret == 0, stdout
assert stderr == __ERR_A

def test_gui_project_loads_absolute_vs_solution_2():
# TODO: generate in temporary folder
create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'),
root_path=__proj_dir,
import_project=os.path.join(__proj_dir, 'proj2.sln'))
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir)
os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly
assert ret == 0, stdout
assert stderr == __ERR_A + __ERR_B
23 changes: 13 additions & 10 deletions test/tools/htmlreport/test_htmlreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import os
import contextlib
import shutil
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -37,7 +36,7 @@ def checkReportError(self, xml_version):
self.assertIn('Memory leak:', report)
self.assertIn('bad.c', report)

detail_filename = os.path.join(output_directory, '0.html')
detail_filename = os.path.join(output_directory.name, '0.html')
self.assertTrue(
os.path.exists(detail_filename))

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

output_directory.cleanup()

def testReportNoError(self):
for xml_version in ['2']:
self.checkReportNoError(xml_version)
Expand All @@ -61,7 +62,9 @@ def checkReportNoError(self, xml_version):
self.assertNotIn('good.c', report)

self.assertFalse(
os.path.exists(os.path.join(output_directory, '0.html')))
os.path.exists(os.path.join(output_directory.name, '0.html')))

output_directory.cleanup()

def testMissingInclude(self):
with runCheck(
Expand All @@ -73,7 +76,9 @@ def testMissingInclude(self):
self.assertIn('example.cc', report)

self.assertTrue(
os.path.exists(os.path.join(output_directory, '0.html')))
os.path.exists(os.path.join(output_directory.name, '0.html')))

output_directory.cleanup()


@contextlib.contextmanager
Expand All @@ -84,10 +89,10 @@ def runCheck(source_filename=None, xml_version='1', xml_filename=None):
path.
"""
output_directory = tempfile.mkdtemp(dir='.')
output_directory = tempfile.TemporaryDirectory(dir='.')
if xml_filename is None:
assert source_filename
xml_filename = os.path.join(output_directory, 'output.xml')
xml_filename = os.path.join(output_directory.name, 'output.xml')

with open(xml_filename, 'w') as output_file:
subprocess.check_call(
Expand All @@ -100,16 +105,14 @@ def runCheck(source_filename=None, xml_version='1', xml_filename=None):
subprocess.check_call(
[*HTML_REPORT_BIN,
'--file=' + os.path.realpath(xml_filename),
'--report-dir=' + os.path.realpath(output_directory)],
'--report-dir=' + os.path.realpath(output_directory.name)],
cwd=TEST_TOOLS_DIR)

with open(os.path.join(output_directory, 'index.html')) as index_file:
with open(os.path.join(output_directory.name, 'index.html')) as index_file:
index_contents = index_file.read()

yield index_contents, output_directory

shutil.rmtree(output_directory)


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

0 comments on commit 1093382

Please sign in to comment.