-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #13825 (toomanyconfigs lacks file information) #7967
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 11 commits
8cacf1f
707d166
39cd696
b3dda6a
41b6f93
49fed2d
4ed0b8d
3943e9e
88efa98
e5da14c
120c393
b862703
ecb1cf2
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 |
|---|---|---|
|
|
@@ -3948,3 +3948,34 @@ def test_simplecpp_syntax_error(tmp_path): | |
| '{}:1:0: error: No header in #include [syntaxError]'.format(test_file), | ||
| '{}:1:0: error: No header in #include [syntaxError]'.format(test_file) | ||
| ] | ||
|
|
||
| def test_max_configs(tmp_path): | ||
| test_file = tmp_path / 'test.cpp' | ||
| with open(test_file, "w") as f: | ||
| for i in range(1,20): | ||
| dir = 'if' if i == 1 else 'elif' | ||
| f.write(f'#{dir} defined(X{i})\nx = {i};\n') | ||
| f.write('#endif\n') | ||
|
|
||
| args = ['--enable=information', '--template=daca2', str(test_file)] | ||
|
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. Why are using the
Collaborator
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. because default template writes 3 lines instead of 1.
Collaborator
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. any 1-line template format will do here imho
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.
|
||
|
|
||
| # default max configs is set to 12, warn if code contains more configurations than that | ||
| _, _, stderr = cppcheck(args) | ||
| assert stderr.splitlines() == [ | ||
| '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) | ||
| ] | ||
|
|
||
| # set explicit max configs => do not warn | ||
| # configurations are likely skipped by intention | ||
| _, _, stderr = cppcheck(['--max-configs=6'] + args) | ||
| assert stderr.splitlines() == [] | ||
|
|
||
| # when using --check-configs, warn if code contains more than max configs | ||
| _, _, stderr = cppcheck(['--check-config', '--max-configs=6'] + args) | ||
| assert stderr.splitlines() == [ | ||
| '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 6 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) | ||
| ] | ||
|
|
||
| # when using --check-configs, do not warn if code contains less than max configs | ||
| _, _, stderr = cppcheck(['--check-config', '--max-configs=60'] + args) | ||
| assert stderr.splitlines() == [] | ||
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 feels very strange.
Also the check for the default value should not be hard-coded - use a default
Settingsobject to check against.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.
I wrote a comment to describe it.
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.
Thanks. Seems to make sense but I have not thought too much about it - as I have not dug too much into #7424.
But I have to from a different angle anyways as part of preprocessor work I am doing. But merging this should be fine (possibly even helpful as there is less code to go through).