Skip to content

Commit c756cdc

Browse files
clalancettewuisky
authored andcommitted
Add in checks to ament_cppcheck code. (#472)
This just ensures that it conforms to the same style as the rest of ament_lint. Signed-off-by: Chris Lalancette <[email protected]> Signed-off-by: WU MENGHUNG <[email protected]>
1 parent 54426ec commit c756cdc

File tree

6 files changed

+109
-9
lines changed

6 files changed

+109
-9
lines changed

ament_cppcheck/ament_cppcheck/main.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ def main(argv=sys.argv[1:]):
6767
parser.add_argument(
6868
'--libraries',
6969
nargs='*',
70-
help="Library configurations to load in addition to the standard libraries of C and C++."
70+
help='Library configurations to load in addition to the standard libraries of C and C++.'
7171
"Each library is passed to cppcheck as '--library=<library_name>'")
7272
parser.add_argument(
7373
'--include_dirs',
7474
nargs='*',
75-
help="Include directories for C/C++ files being checked."
75+
help='Include directories for C/C++ files being checked.'
7676
"Each directory is passed to cppcheck as '-I <include_dir>'")
7777
parser.add_argument(
7878
'--exclude',
7979
nargs='*',
80-
help="Exclude C/C++ files from being checked."
80+
help='Exclude C/C++ files from being checked.'
8181
"Each file is passed to cppcheck as '--suppress=*:<file>'")
8282
parser.add_argument(
8383
'--language',
@@ -127,7 +127,8 @@ def main(argv=sys.argv[1:]):
127127
if cppcheck_version == '1.88' or cppcheck_version.startswith('2.'):
128128
print(
129129
f'cppcheck {cppcheck_version} has known performance issues and therefore will not '
130-
'be used, set the AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS environment variable to override this.',
130+
'be used, set the AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS environment variable to '
131+
'override this.',
131132
file=sys.stderr,
132133
)
133134

@@ -203,7 +204,7 @@ def main(argv=sys.argv[1:]):
203204
data = dict(data)
204205
data['filename'] = filename
205206
print('[%(filename)s:%(line)d]: (%(severity)s: %(id)s) %(msg)s' % data,
206-
file=sys.stderr)
207+
file=sys.stderr)
207208

208209
# output summary
209210
error_count = sum(len(r) for r in report.values())
@@ -277,10 +278,10 @@ def get_xunit_content(report, testname, elapsed, skip=None):
277278

278279
if skip:
279280
data = {
280-
'quoted_name': quoteattr(filename),
281-
'testname': testname,
282-
'quoted_message': quoteattr(''),
283-
'skip': skip,
281+
'quoted_name': quoteattr(filename),
282+
'testname': testname,
283+
'quoted_message': quoteattr(''),
284+
'skip': skip,
284285
}
285286
xml += """ <testcase
286287
name=%(quoted_name)s

ament_cppcheck/package.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
<exec_depend>cppcheck</exec_depend>
2222

23+
<test_depend>ament_copyright</test_depend>
24+
<test_depend>ament_flake8</test_depend>
25+
<test_depend>ament_pep257</test_depend>
26+
<test_depend>ament_pycodestyle</test_depend>
27+
<test_depend>python3-pytest</test_depend>
28+
2329
<export>
2430
<build_type>ament_python</build_type>
2531
</export>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_copyright.main import main
16+
import pytest
17+
18+
19+
@pytest.mark.copyright
20+
@pytest.mark.linter
21+
def test_copyright():
22+
rc = main(argv=['.', 'test'])
23+
assert rc == 0, 'Found errors'

ament_cppcheck/test/test_flake8.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_flake8.main import main_with_errors
16+
import pytest
17+
18+
19+
@pytest.mark.flake8
20+
@pytest.mark.linter
21+
def test_flake8():
22+
rc, errors = main_with_errors(argv=[])
23+
assert rc == 0, \
24+
'Found %d code style errors / warnings:\n' % len(errors) + \
25+
'\n'.join(errors)

ament_cppcheck/test/test_pep257.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_pep257.main import main
16+
import pytest
17+
18+
19+
@pytest.mark.linter
20+
@pytest.mark.pep257
21+
def test_pep257():
22+
rc = main(argv=['.', 'test'])
23+
assert rc == 0, 'Found code style errors / warnings'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_pycodestyle.main import main
16+
import pytest
17+
18+
19+
@pytest.mark.linter
20+
def test_pycodestyle():
21+
rc = main(argv=['.', 'test'])
22+
assert rc == 0, 'Found code style errors / warnings'

0 commit comments

Comments
 (0)