Skip to content

Commit

Permalink
Prepare use of run-clang-tidy
Browse files Browse the repository at this point in the history
Also upgrade to catch2 v3.4.0 to use Catch2WithMain.
Add intermeediate header for now.
  • Loading branch information
ClausKlein committed Aug 21, 2023
1 parent 08e6dae commit 3beace3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 20 deletions.
55 changes: 55 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -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 }
...
25 changes: 19 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[requires]
catch2/2.13.10
catch2/3.4.0

[generators]
CMakeDeps
Expand Down
2 changes: 2 additions & 0 deletions include/catch2/catch.hpp
Original file line number Diff line number Diff line change
@@ -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 <catch2/catch_all.hpp>
17 changes: 9 additions & 8 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +17,7 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)

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
Expand All @@ -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
Expand All @@ -48,7 +48,7 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)

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
Expand All @@ -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
Expand Down Expand Up @@ -105,7 +105,7 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)

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
Expand All @@ -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)

Expand All @@ -131,7 +132,7 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)

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
Expand Down
2 changes: 1 addition & 1 deletion test/src/derived_unit_tests/velocity_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ TEST_CASE("GIVEN a length of type float WHEN divided by a value of type double "

SI::metre_t<long double> a = 1.5_km;
SI::seconds_t<float> s{1.0};
SI::metre_per_second_t<long double> c = a / s;
SI::metre_per_second_t<long double> c = a / s; // NOLINT(clang-analyzer-deadcode.DeadStores)
STATIC_REQUIRE(
std::is_same<decltype(c), SI::metre_per_second_t<long double>>::value);
}
Expand Down
8 changes: 4 additions & 4 deletions test/src/detail_tests/unit_t_operator_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}

Expand All @@ -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(
Expand All @@ -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);
}

Expand Down

0 comments on commit 3beace3

Please sign in to comment.