|
| 1 | +# Copyright 2025 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 | +import json |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +from ament_clang_tidy.main import main |
| 19 | +from ament_lint.test_helpers import TempFileWriter |
| 20 | + |
| 21 | +def test_clang_tidy_execution(): |
| 22 | + """Test that clang tidy can be executed on a simple C++ file, via ament_clang_tidy.""" |
| 23 | + with TempFileWriter("int main() { return 0; }", "test.cpp") as temp_file_path: |
| 24 | + temp_dir = Path(temp_file_path).parent |
| 25 | + |
| 26 | + # Create compile_commands.json |
| 27 | + compile_commands = [ |
| 28 | + { |
| 29 | + "directory": str(temp_dir), |
| 30 | + "command": "c++ -c test.cpp", |
| 31 | + "file": str(temp_file_path) |
| 32 | + } |
| 33 | + ] |
| 34 | + compile_commands_json = json.dumps(compile_commands) |
| 35 | + with TempFileWriter(compile_commands_json, "compile_commands.json") as compile_commands_path: |
| 36 | + rc = main(argv=['ament_clang_tidy', str(compile_commands_path)]) |
| 37 | + assert rc == 0, 'Clang tidy found issues' |
0 commit comments