Skip to content

Commit

Permalink
added environment variable TEST_CPPCHECK_INJECT_CLANG to inject `--…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
firewave authored Mar 8, 2024
1 parent f465dc5 commit 210f9ad
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@ jobs:
env:
TEST_CPPCHECK_INJECT_J: 2

# do not use pushd in this step since we go below the working directory
- name: Run test/cli (--clang)
if: false
run: |
cd test/cli
python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Run cfg tests
if: matrix.os != 'ubuntu-22.04'
run: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ jobs:
env:
TEST_CPPCHECK_INJECT_J: 2

# TODO: install clang
- name: Run test/cli (--clang)
if: false # matrix.config == 'release'
run: |
cd test/cli || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Test addons
if: matrix.config == 'release'
run: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ jobs:
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Run test/cli (--clang)
if: false
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Generate dependencies
if: false
run: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ jobs:
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Run test/cli (--clang)
if: false
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Generate dependencies
if: false
run: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ jobs:
env:
TEST_CPPCHECK_INJECT_J: 2

- name: Run test/cli (--clang)
if: false
run: |
pwd=$(pwd)
cd test/cli
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Generate dependencies
run: |
# make sure auto-generated GUI files exist
Expand Down
16 changes: 12 additions & 4 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,17 @@ unsigned int CppCheck::checkClang(const std::string &path)
}

std::string output2;
if (mExecuteCommand(exe,split(args2),redirect2,output2) != EXIT_SUCCESS || output2.find("TranslationUnitDecl") == std::string::npos) {
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "'" << std::endl;
return 0;
const int exitcode = mExecuteCommand(exe,split(args2),redirect2,output2);
if (exitcode != EXIT_SUCCESS) {
// TODO: report as proper error
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (exitcode: " << exitcode << " / output: " << output2 << ")" << std::endl;
return 0; // TODO: report as failure?
}

if (output2.find("TranslationUnitDecl") == std::string::npos) {
// TODO: report as proper error
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no TranslationUnitDecl in output)" << std::endl;
return 0; // TODO: report as failure?
}

// Ensure there are not syntax errors...
Expand Down Expand Up @@ -551,7 +559,7 @@ unsigned int CppCheck::checkClang(const std::string &path)
unsigned int CppCheck::check(const std::string &path)
{
if (mSettings.clang)
return checkClang(path);
return checkClang(Path::simplifyPath(path));

return checkFile(Path::simplifyPath(path), emptyString);
}
Expand Down
2 changes: 1 addition & 1 deletion test/cli/helloworld/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

int main(void) {
(void)printf("Hello world!\n");
x = 3 / 0; // ERROR
int x = 3 / 0; (void)x; // ERROR
return 0;
}

Expand Down
10 changes: 10 additions & 0 deletions test/cli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def cppcheck(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe
arg_j = '-j' + str(os.environ['TEST_CPPCHECK_INJECT_J'])
args.append(arg_j)

if 'TEST_CPPCHECK_INJECT_CLANG' in os.environ:
found_clang = False
for arg in args:
if arg.startswith('--clang'):
found_clang = True
break
if not found_clang:
arg_clang = '--clang=' + str(os.environ['TEST_CPPCHECK_INJECT_CLANG'])
args.append(arg_clang)

logging.info(exe + ' ' + ' '.join(args))
p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, cwd=cwd)
try:
Expand Down

0 comments on commit 210f9ad

Please sign in to comment.