Skip to content

Commit 210f9ad

Browse files
authored
added environment variable TEST_CPPCHECK_INJECT_CLANG to inject --clang into the cppcheck invocation of Python tests (#6101)
This is currently disabled since a lot of tests still fail. I did fix some low hanging fruits though.
1 parent f465dc5 commit 210f9ad

8 files changed

Lines changed: 68 additions & 5 deletions

File tree

.github/workflows/CI-unixish.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ jobs:
405405
env:
406406
TEST_CPPCHECK_INJECT_J: 2
407407

408+
# do not use pushd in this step since we go below the working directory
409+
- name: Run test/cli (--clang)
410+
if: false
411+
run: |
412+
cd test/cli
413+
python3 -m pytest -Werror --strict-markers -vv
414+
env:
415+
TEST_CPPCHECK_INJECT_CLANG: clang
416+
408417
- name: Run cfg tests
409418
if: matrix.os != 'ubuntu-22.04'
410419
run: |

.github/workflows/CI-windows.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ jobs:
182182
env:
183183
TEST_CPPCHECK_INJECT_J: 2
184184

185+
# TODO: install clang
186+
- name: Run test/cli (--clang)
187+
if: false # matrix.config == 'release'
188+
run: |
189+
cd test/cli || exit /b !errorlevel!
190+
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
191+
env:
192+
TEST_CPPCHECK_INJECT_CLANG: clang
193+
185194
- name: Test addons
186195
if: matrix.config == 'release'
187196
run: |

.github/workflows/asan.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ jobs:
108108
env:
109109
TEST_CPPCHECK_INJECT_J: 2
110110

111+
- name: Run test/cli (--clang)
112+
if: false
113+
run: |
114+
pwd=$(pwd)
115+
cd test/cli
116+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
117+
env:
118+
TEST_CPPCHECK_INJECT_CLANG: clang
119+
111120
- name: Generate dependencies
112121
if: false
113122
run: |

.github/workflows/tsan.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ jobs:
107107
env:
108108
TEST_CPPCHECK_INJECT_J: 2
109109

110+
- name: Run test/cli (--clang)
111+
if: false
112+
run: |
113+
pwd=$(pwd)
114+
cd test/cli
115+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
116+
env:
117+
TEST_CPPCHECK_INJECT_CLANG: clang
118+
110119
- name: Generate dependencies
111120
if: false
112121
run: |

.github/workflows/ubsan.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ jobs:
107107
env:
108108
TEST_CPPCHECK_INJECT_J: 2
109109

110+
- name: Run test/cli (--clang)
111+
if: false
112+
run: |
113+
pwd=$(pwd)
114+
cd test/cli
115+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
116+
env:
117+
TEST_CPPCHECK_INJECT_CLANG: clang
118+
110119
- name: Generate dependencies
111120
run: |
112121
# make sure auto-generated GUI files exist

lib/cppcheck.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,17 @@ unsigned int CppCheck::checkClang(const std::string &path)
470470
}
471471

472472
std::string output2;
473-
if (mExecuteCommand(exe,split(args2),redirect2,output2) != EXIT_SUCCESS || output2.find("TranslationUnitDecl") == std::string::npos) {
474-
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "'" << std::endl;
475-
return 0;
473+
const int exitcode = mExecuteCommand(exe,split(args2),redirect2,output2);
474+
if (exitcode != EXIT_SUCCESS) {
475+
// TODO: report as proper error
476+
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (exitcode: " << exitcode << " / output: " << output2 << ")" << std::endl;
477+
return 0; // TODO: report as failure?
478+
}
479+
480+
if (output2.find("TranslationUnitDecl") == std::string::npos) {
481+
// TODO: report as proper error
482+
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no TranslationUnitDecl in output)" << std::endl;
483+
return 0; // TODO: report as failure?
476484
}
477485

478486
// Ensure there are not syntax errors...
@@ -551,7 +559,7 @@ unsigned int CppCheck::checkClang(const std::string &path)
551559
unsigned int CppCheck::check(const std::string &path)
552560
{
553561
if (mSettings.clang)
554-
return checkClang(path);
562+
return checkClang(Path::simplifyPath(path));
555563

556564
return checkFile(Path::simplifyPath(path), emptyString);
557565
}

test/cli/helloworld/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int main(void) {
44
(void)printf("Hello world!\n");
5-
x = 3 / 0; // ERROR
5+
int x = 3 / 0; (void)x; // ERROR
66
return 0;
77
}
88

test/cli/testutils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ def cppcheck(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe
8787
arg_j = '-j' + str(os.environ['TEST_CPPCHECK_INJECT_J'])
8888
args.append(arg_j)
8989

90+
if 'TEST_CPPCHECK_INJECT_CLANG' in os.environ:
91+
found_clang = False
92+
for arg in args:
93+
if arg.startswith('--clang'):
94+
found_clang = True
95+
break
96+
if not found_clang:
97+
arg_clang = '--clang=' + str(os.environ['TEST_CPPCHECK_INJECT_CLANG'])
98+
args.append(arg_clang)
99+
90100
logging.info(exe + ' ' + ' '.join(args))
91101
p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, cwd=cwd)
92102
try:

0 commit comments

Comments
 (0)