From 3beace384cc86324c5720e19d5fe970ddae1e74c Mon Sep 17 00:00:00 2001 From: Claus Date: Mon, 21 Aug 2023 09:00:25 +0200 Subject: [PATCH] Prepare use of run-clang-tidy Also upgrade to catch2 v3.4.0 to use Catch2WithMain. Add intermeediate header for now. --- .clang-tidy | 55 +++++++++++++++++++ CMakePresets.json | 25 +++++++-- conanfile.txt | 2 +- include/catch2/catch.hpp | 2 + test/CMakeLists.txt | 17 +++--- test/src/derived_unit_tests/velocity_tests.cc | 2 +- .../src/detail_tests/unit_t_operator_tests.cc | 8 +-- 7 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 .clang-tidy create mode 100644 include/catch2/catch.hpp diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..ab862b2a --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,55 @@ +--- +# +# clang-format v12.0.0 +# +Checks: +'-*, + #TBD llvm-header-guard, + bugprone-*, + cert-*, + clang-analyzer-*, + -clang-analyzer-cplusplus.Move, + cppcoreguidelines-*, + -cppcoreguidelines-macro-usage, + concurrency-*, + #MAYBE google-*, + hicpp-*, + misc-*, + modernize-*, + -modernize-use-trailing-return-type, + performance-*, + portability-*, + readability-*, + -readability-identifier-naming, + -readability-identifier-length, + -*-magic-numbers, +' + +HeaderFilterRegex: '.*' +WarningsAsErrors: 'clang*' +FormatStyle: google +UseColor: false +User: klein_cl + +CheckOptions: + - { key: readability-identifier-naming.NamespaceCase, value: CamelCase } + - { key: readability-identifier-naming.ClassCase, value: CamelCase } + - { key: readability-identifier-naming.MemberCase, value: camelBack } + - { key: readability-identifier-naming.MemberPrefix, value: m_ } + - { key: readability-identifier-naming.StructCase, value: lower_case } + - { key: readability-identifier-naming.UnionCase, value: lower_case } + - { key: readability-identifier-naming.TypedefCase, value: lower_case } + - { key: readability-identifier-naming.TypedefSuffix, value: _type } + - { key: readability-identifier-naming.FunctionCase, value: camelBack } + - { key: readability-identifier-naming.EnumCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprFunctionCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprMethodCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } + - { key: readability-identifier-naming.ClassConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE } + - { key: readability-identifier-naming.LocalConstantPointerCase, value: UPPER_CASE } + - { key: readability-identifier-naming.ScopedEnumConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE } +... diff --git a/CMakePresets.json b/CMakePresets.json index cbf812e9..1ab62046 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,28 +9,42 @@ { "name": "ccache-env", "hidden": true, + "description": "build using ccache", + "cacheVariables": { + "CMAKE_CXX_COMPILER_LAUNCHER ": "ccache" + }, "environment": { "CCACHE_BASEDIR": "${sourceDir}", - "CCACHE_SLOPPINESS": "pch_defines,time_macros", + "CCACHE_SLOPPINESS": "pch_defines,time_macros" + } + }, + { + "name": "clang-tidy", + "hidden": true, + "description": "build using clang-tidy as precompile step", + "cacheVariables": { + "CMAKE_CXX_CLANG_TIDY": "clang-tidy" + }, + "environment": { "CMAKE_EXPORT_COMPILE_COMMANDS": "YES" } }, { "name": "conan-toolchain", "hidden": true, + "description": "setup using conan toolchain", "toolchainFile": "conan_toolchain.cmake", "binaryDir": "${sourceDir}/build" }, { "name": "ci-ninja", - "displayName": "Ninja", + "hidden": true, "description": "build using Ninja generator", "inherits": [ "ccache-env", "conan-toolchain" ], - "generator": "Ninja", - "hidden": true + "generator": "Ninja" }, { "name": "ci-ninja-debug", @@ -94,8 +108,7 @@ "name": "ci-ninja-debug", "displayName": "Ninja debug", "configurePreset": "ci-ninja-debug", - "configuration": "Debug", - "targets": [ "all", "help" ] + "configuration": "Debug" }, { "name": "ci-ninja-release", diff --git a/conanfile.txt b/conanfile.txt index 3558e96f..c26f6e21 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,5 @@ [requires] -catch2/2.13.10 +catch2/3.4.0 [generators] CMakeDeps diff --git a/include/catch2/catch.hpp b/include/catch2/catch.hpp new file mode 100644 index 00000000..564e5e8a --- /dev/null +++ b/include/catch2/catch.hpp @@ -0,0 +1,2 @@ +// see https://github.com/catchorg/Catch2/blob/v3.0.1/docs/migrate-v2-to-v3.md#how-to-migrate-projects-from-v2-to-v3 +#include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d02b93ec..5718a1e4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.23) add_executable(SI_detail_tests) target_sources( SI_detail_tests - PRIVATE src/Catch2Main.cc + PRIVATE #XXX src/Catch2Main.cc src/detail_tests/detail_tests.cc src/detail_tests/number_parser_tests.cc src/detail_tests/unit_t_operator_tests.cc @@ -17,7 +17,7 @@ target_include_directories( $) target_compile_features(SI_detail_tests PRIVATE cxx_std_17) -target_link_libraries(SI_detail_tests Catch2::Catch2) +target_link_libraries(SI_detail_tests Catch2::Catch2WithMain) target_compile_options( SI_detail_tests @@ -33,7 +33,7 @@ target_compile_options( add_executable(SI_base_unit_tests) target_sources( SI_base_unit_tests - PRIVATE src/Catch2Main.cc + PRIVATE #XXX src/Catch2Main.cc src/base_unit_tests/mass_tests.cc src/base_unit_tests/time_tests.cc src/base_unit_tests/electric_current_tests.cc @@ -48,7 +48,7 @@ target_include_directories( $) target_compile_features(SI_base_unit_tests PRIVATE cxx_std_17) -target_link_libraries(SI_base_unit_tests Catch2::Catch2) +target_link_libraries(SI_base_unit_tests Catch2::Catch2WithMain) target_compile_options( SI_base_unit_tests @@ -68,7 +68,7 @@ target_compile_options( add_executable(SI_derived_unit_tests) target_sources( SI_derived_unit_tests - PRIVATE src/Catch2Main.cc + PRIVATE #XXX src/Catch2Main.cc src/derived_unit_tests/area_tests.cc src/derived_unit_tests/frequency_tests.cc src/derived_unit_tests/electric_charge_tests.cc @@ -105,7 +105,7 @@ target_include_directories( $) target_compile_features(SI_derived_unit_tests PRIVATE cxx_std_17) -target_link_libraries(SI_derived_unit_tests Catch2::Catch2) +target_link_libraries(SI_derived_unit_tests Catch2::Catch2WithMain) target_compile_options( SI_derived_unit_tests @@ -121,7 +121,8 @@ target_compile_options( add_executable(SI_unit_benchmarks) target_sources( SI_unit_benchmarks - PRIVATE src/Catch2Main.cc src/benchmarks/unit_assignment_benchmarks.cc + PRIVATE #XXX src/Catch2Main.cc + src/benchmarks/unit_assignment_benchmarks.cc src/benchmarks/detail_benchmarks.cc src/benchmarks/string_operations_benchmarks.cc) @@ -131,7 +132,7 @@ target_include_directories( $) target_compile_features(SI_unit_benchmarks PRIVATE cxx_std_17) -target_link_libraries(SI_unit_benchmarks Catch2::Catch2) +target_link_libraries(SI_unit_benchmarks Catch2::Catch2WithMain) target_compile_options( SI_unit_benchmarks diff --git a/test/src/derived_unit_tests/velocity_tests.cc b/test/src/derived_unit_tests/velocity_tests.cc index 17500476..a9363db6 100644 --- a/test/src/derived_unit_tests/velocity_tests.cc +++ b/test/src/derived_unit_tests/velocity_tests.cc @@ -139,7 +139,7 @@ TEST_CASE("GIVEN a length of type float WHEN divided by a value of type double " SI::metre_t a = 1.5_km; SI::seconds_t s{1.0}; - SI::metre_per_second_t c = a / s; + SI::metre_per_second_t c = a / s; // NOLINT(clang-analyzer-deadcode.DeadStores) STATIC_REQUIRE( std::is_same>::value); } diff --git a/test/src/detail_tests/unit_t_operator_tests.cc b/test/src/detail_tests/unit_t_operator_tests.cc index 37095fa6..b0bcb19f 100644 --- a/test/src/detail_tests/unit_t_operator_tests.cc +++ b/test/src/detail_tests/unit_t_operator_tests.cc @@ -60,7 +60,7 @@ TEMPLATE_TEST_CASE( unit_t<'X', std::ratio<1>, TestType, std::ratio<1>> v1{123}; unit_t<'X', std::ratio<1>, TestType, std::ratio<1>> v2{std::move(v1)}; - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) } TEMPLATE_TEST_CASE( @@ -71,7 +71,7 @@ TEMPLATE_TEST_CASE( unit_t<'X', std::ratio<1>, TestType, std::ratio<1>> v1{1000}; unit_t<'X', std::ratio<1>, TestType, std::kilo> v2{std::move(v1)}; - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) REQUIRE(v2.value() == 1); } @@ -84,7 +84,7 @@ TEMPLATE_TEST_CASE("GIVEN two values of the same unit type WHEN move assigned" v2 = std::move(v1); - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) } TEMPLATE_TEST_CASE( @@ -98,7 +98,7 @@ TEMPLATE_TEST_CASE( unit_t<'X', std::ratio<1>, TestType, std::kilo> v2{0}; v2 = std::move(v1); - REQUIRE(v1 == v2); + REQUIRE(v1 == v2); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) REQUIRE(v2.value() == 1); }