Skip to content

Commit

Permalink
Add in checks to ament_cppcheck code. (#472)
Browse files Browse the repository at this point in the history
This just ensures that it conforms to the same style
as the rest of ament_lint.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
  • Loading branch information
clalancette authored Jan 30, 2024
1 parent cd37886 commit bf3c609
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ament_cppcheck/ament_cppcheck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ def main(argv=sys.argv[1:]):
parser.add_argument(
'--libraries',
nargs='*',
help="Library configurations to load in addition to the standard libraries of C and C++."
help='Library configurations to load in addition to the standard libraries of C and C++.'
"Each library is passed to cppcheck as '--library=<library_name>'")
parser.add_argument(
'--include_dirs',
nargs='*',
help="Include directories for C/C++ files being checked."
help='Include directories for C/C++ files being checked.'
"Each directory is passed to cppcheck as '-I <include_dir>'")
parser.add_argument(
'--exclude',
nargs='*',
help="Exclude C/C++ files from being checked."
help='Exclude C/C++ files from being checked.'
"Each file is passed to cppcheck as '--suppress=*:<file>'")
parser.add_argument(
'--language',
Expand Down Expand Up @@ -127,7 +127,8 @@ def main(argv=sys.argv[1:]):
if cppcheck_version == '1.88' or cppcheck_version.startswith('2.'):
print(
f'cppcheck {cppcheck_version} has known performance issues and therefore will not '
'be used, set the AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS environment variable to override this.',
'be used, set the AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS environment variable to '
'override this.',
file=sys.stderr,
)

Expand Down Expand Up @@ -203,7 +204,7 @@ def main(argv=sys.argv[1:]):
data = dict(data)
data['filename'] = filename
print('[%(filename)s:%(line)d]: (%(severity)s: %(id)s) %(msg)s' % data,
file=sys.stderr)
file=sys.stderr)

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

if skip:
data = {
'quoted_name': quoteattr(filename),
'testname': testname,
'quoted_message': quoteattr(''),
'skip': skip,
'quoted_name': quoteattr(filename),
'testname': testname,
'quoted_message': quoteattr(''),
'skip': skip,
}
xml += """ <testcase
name=%(quoted_name)s
Expand Down
6 changes: 6 additions & 0 deletions ament_cppcheck/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

<exec_depend>cppcheck</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>ament_pycodestyle</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
Expand Down
23 changes: 23 additions & 0 deletions ament_cppcheck/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_copyright.main import main
import pytest


@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
25 changes: 25 additions & 0 deletions ament_cppcheck/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_flake8.main import main_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)
23 changes: 23 additions & 0 deletions ament_cppcheck/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'
22 changes: 22 additions & 0 deletions ament_cppcheck/test/test_pycodestyle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_pycodestyle.main import main
import pytest


@pytest.mark.linter
def test_pycodestyle():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'

0 comments on commit bf3c609

Please sign in to comment.