-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#12254: cppcheck.cfg can't be loaded from relative paths anymore #5753
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ | |
import os | ||
import sys | ||
import pytest | ||
import time | ||
|
||
from testutils import cppcheck, assert_cppcheck | ||
from testutils import cppcheck, assert_cppcheck, lookup_cppcheck_exe | ||
|
||
|
||
def __test_missing_include(tmpdir, use_j): | ||
|
@@ -825,3 +826,41 @@ def test_file_duplicate_2(tmpdir): | |
'3/3 files checked 0% done' | ||
] | ||
assert stderr == '' | ||
|
||
|
||
def test_premium_with_relative_path(tmpdir): #12254 | ||
|
||
|
||
test_file = os.path.join(tmpdir, 'test.c') | ||
with open(test_file, 'wt'): | ||
pass | ||
|
||
product_name = 'Cppcheck Premium ' + str(time.time()) | ||
|
||
test_cfg = lookup_cppcheck_exe() | ||
if(test_cfg.endswith('.exe')): | ||
test_cfg = test_cfg[:-4] | ||
test_cfg += '.cfg' | ||
with open(test_cfg, 'wt') as f: | ||
f.write(""" | ||
{ | ||
"addons": [], | ||
"productName": "NAME", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's also used for an assert on line 863. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I knew I overlooked it somehow. Still you should use |
||
"about": "Cppcheck Premium 1.2.3.4" | ||
} | ||
""".replace('NAME', product_name)) | ||
|
||
if os.path.isfile('cppcheck'): | ||
os.chdir('test/cli') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just no. If you need to change the directory for running a process please pass the |
||
|
||
args = ['--premium=misra-c++-2008', test_file] | ||
|
||
exitcode, _, stderr = cppcheck(args) | ||
assert exitcode == 0 | ||
assert stderr == '' | ||
danmar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_, stdout, stderr = cppcheck(['--version']) | ||
assert stdout == product_name + '\n' | ||
assert stderr == '' | ||
|
||
os.remove(test_cfg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you put the folder as suggested into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very bad and dangerous. If the test gets aborted beforehand you have a stray file which will infer with your system. It might also override a file the user might have created for themselves.
A better way to test this would probably be to copy the folder where the binary is located in into a new folder within
tmpdir
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already do something similar in other tests with the local
cppcheck_local()
- which is not something I would encourage. I will try to provide a shared helper which will generate a copy for the execution and update the existing tests.