-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix #13645 (fail to load platform when executing Cppcheck in PATH) #7977
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
Changes from all commits
2aaac23
8f41554
146046e
62f21bc
85e352c
3e0b256
4bc9b2c
73aa896
04e15e3
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 |
|---|---|---|
|
|
@@ -381,6 +381,36 @@ def test_platform_lookup_ext(tmpdir): | |
| ] | ||
|
|
||
|
|
||
| def test_platform_lookup_path(tmpdir): | ||
| test_file = os.path.join(tmpdir, 'test.c') | ||
| with open(test_file, 'wt'): | ||
| pass | ||
|
|
||
| cppcheck = 'cppcheck' # No path | ||
| path = os.path.dirname(__lookup_cppcheck_exe()) | ||
| env = os.environ.copy() | ||
| env['PATH'] = path | ||
| exitcode, stdout, stderr, _ = cppcheck_ex(args=['--debug-lookup=platform', '--platform=avr8.xml', test_file], cppcheck_exe=cppcheck, cwd=str(tmpdir), env=env) | ||
| assert exitcode == 0, stdout if stdout else stderr | ||
| def format_path(p): | ||
| return p.replace('\\', '/').replace('"', '\'') | ||
| def try_fail(f): | ||
| f = format_path(f) | ||
| return "try to load platform file '{}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}".format(f, f) | ||
| def try_success(f): | ||
| f = format_path(f) | ||
| return "try to load platform file '{}' ... Success".format(f) | ||
| lines = stdout.replace('\\', '/').replace('"', '\'').splitlines() | ||
| assert lines == [ | ||
| "looking for platform 'avr8.xml'", | ||
| try_fail(os.path.join(tmpdir, 'avr8.xml')), | ||
| try_fail(os.path.join(tmpdir, 'platforms', 'avr8.xml')), | ||
| try_fail(os.path.join(path, 'avr8.xml')), | ||
| try_success(os.path.join(path, 'platforms', 'avr8.xml')), | ||
| 'Checking {} ...'.format(format_path(test_file)) | ||
| ] | ||
|
|
||
|
|
||
| def test_platform_lookup_notfound(tmpdir): | ||
| test_file = os.path.join(tmpdir, 'test.c') | ||
| with open(test_file, 'wt'): | ||
|
|
@@ -897,4 +927,76 @@ def test_config_invalid(tmpdir): | |
| 'cppcheck: error: could not load cppcheck.cfg - not a valid JSON - syntax error at line 1 near: ' | ||
| ] | ||
|
|
||
| # TODO: test with FILESDIR | ||
| # TODO: test with FILESDIR | ||
|
|
||
| @pytest.mark.parametrize("type,file", [("addon", "misra.py"), ("config", "cppcheck.cfg"), ("library", "gnu.cfg"), ("platform", "avr8.xml")]) | ||
| def test_lookup_path(tmpdir, type, file): | ||
|
Comment on lines
+932
to
+933
Collaborator
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 asked you not to do this. And the readability of this test is beyond horrible. It is impossible to understand what this is testing. And there are no failing tests at all. The expected output is supposed to be identical for all types and that is not reflected at it. This is not usable for test-driven development of my future changes. I will post a PR as soon as I cauught up again.
Owner
Author
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. ok sure we can try to refactor it. I just fear that splitting it up is not ideal neither, this way we know PATH is tested for all variants. But yes I agree my test code is clumpsy.. |
||
| test_file = os.path.join(tmpdir, 'test.c') | ||
| with open(test_file, 'wt'): | ||
| pass | ||
|
|
||
| cppcheck = 'cppcheck' # No path | ||
| path = os.path.dirname(__lookup_cppcheck_exe()) | ||
| env = os.environ.copy() | ||
| env['PATH'] = path + (';' if sys.platform == 'win32' else ':') + env.get('PATH', '') | ||
| if type == 'config': | ||
| with open(os.path.join(path, "cppcheck.cfg"), 'wt') as f: | ||
| f.write('{}') | ||
| exitcode, stdout, stderr, _ = cppcheck_ex(args=[f'--debug-lookup={type}', test_file], cppcheck_exe=cppcheck, cwd=str(tmpdir), env=env) | ||
| os.remove(os.path.join(path, "cppcheck.cfg")) # clean up otherwise other tests may fail | ||
| else: | ||
| exitcode, stdout, stderr, _ = cppcheck_ex(args=[f'--debug-lookup={type}', f'--{type}={file}', test_file], cppcheck_exe=cppcheck, cwd=str(tmpdir), env=env) | ||
| assert exitcode == 0, stdout if stdout else stderr | ||
| def format_path(p): | ||
| return p.replace('\\', '/').replace('"', '\'') | ||
| lines = format_path(stdout).splitlines() | ||
|
|
||
| if type == 'addon': | ||
| def try_fail(f): | ||
| return f"looking for {type} '{format_path(f)}'" | ||
| def try_success(f): | ||
| return f"looking for {type} '{format_path(f)}'" | ||
| assert lines == [ | ||
| f"looking for {type} '{file}'", | ||
| try_fail(os.path.join(path, file)), | ||
| try_success(os.path.join(path, 'addons', file)), | ||
| f'Checking {format_path(test_file)} ...' | ||
| ] | ||
| elif type == 'config': | ||
| def try_success(f): | ||
| return f"looking for '{format_path(f)}'" | ||
| assert lines == [ | ||
| try_success(os.path.join(path, file)), | ||
| f'Checking {format_path(test_file)} ...' | ||
| ] | ||
| elif type == 'platform': | ||
| def try_fail(f): | ||
| f = format_path(f) | ||
| return f"try to load {type} file '{f}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={f}" | ||
| def try_success(f): | ||
| f = format_path(f) | ||
| return f"try to load {type} file '{f}' ... Success" | ||
| assert lines == [ | ||
| f"looking for {type} '{file}'", | ||
| try_fail(os.path.join(tmpdir, file)), | ||
| try_fail(os.path.join(tmpdir, 'platforms', file)), | ||
| try_fail(os.path.join(path, file)), | ||
| try_success(os.path.join(path, 'platforms', file)), | ||
| f'Checking {format_path(test_file)} ...' | ||
| ] | ||
| elif type == 'library': | ||
| def try_fail(f): | ||
| return f"looking for {type} '{format_path(f)}'" | ||
| def try_success(f): | ||
| return f"looking for {type} '{format_path(f)}'" | ||
| assert lines == [ | ||
| f"looking for {type} 'std.cfg'", | ||
| try_fail(os.path.join(path, 'std.cfg')), | ||
| try_success(os.path.join(path, 'cfg', 'std.cfg')), | ||
| f"looking for {type} '{file}'", | ||
| try_fail(os.path.join(path, file)), | ||
| try_success(os.path.join(path, 'cfg', file)), | ||
| f'Checking {format_path(test_file)} ...' | ||
| ] | ||
| else: | ||
| assert False, type + " not tested properly" | ||
Uh oh!
There was an error while loading. Please reload this page.