diff --git a/ament_cppcheck/ament_cppcheck/main.py b/ament_cppcheck/ament_cppcheck/main.py index 83c78744..45017992 100755 --- a/ament_cppcheck/ament_cppcheck/main.py +++ b/ament_cppcheck/ament_cppcheck/main.py @@ -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='") 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 '") 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=*:'") parser.add_argument( '--language', @@ -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, ) @@ -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()) @@ -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 += """ cppcheck + ament_copyright + ament_flake8 + ament_pep257 + ament_pycodestyle + python3-pytest + ament_python diff --git a/ament_cppcheck/test/test_copyright.py b/ament_cppcheck/test/test_copyright.py new file mode 100644 index 00000000..4962484e --- /dev/null +++ b/ament_cppcheck/test/test_copyright.py @@ -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' diff --git a/ament_cppcheck/test/test_flake8.py b/ament_cppcheck/test/test_flake8.py new file mode 100644 index 00000000..4d62a9ca --- /dev/null +++ b/ament_cppcheck/test/test_flake8.py @@ -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) diff --git a/ament_cppcheck/test/test_pep257.py b/ament_cppcheck/test/test_pep257.py new file mode 100644 index 00000000..f7ef98bb --- /dev/null +++ b/ament_cppcheck/test/test_pep257.py @@ -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' diff --git a/ament_cppcheck/test/test_pycodestyle.py b/ament_cppcheck/test/test_pycodestyle.py new file mode 100644 index 00000000..d0b4be08 --- /dev/null +++ b/ament_cppcheck/test/test_pycodestyle.py @@ -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'