mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-06-04 22:08:40 +02:00
8f8173feb6
To improve codebase quality and reduce human error, this PR introduces the pre-commit framework. This ensures that all code adheres to project standards before it is even committed, maintaining a consistent style and catching common mistakes early. Key Changes: - Code Formatting: Automated C++ formatting using clang-format (based on the project's .clang-format file). - Syntax Validation: Basic checks for file integrity and syntax. - Spell Check: Automated scanning for typos in source code and comments. - CMake Formatting: Standardization of CMakeLists.txt and .cmake configuration files. - GitHub Workflow: Added a CI action that validates every Pull Request against the pre-commit configuration to ensure compliance. The configuration includes a [ci] block to handle automated fixes within the PR. Currently, this is disabled. If we want the CI to automatically commit formatting fixes back to the PR branch, this can be toggled to true in .pre-commit-config.yaml. ```yaml ci: autofix_commit_msg: [pre-commit] auto fixes from pre-commit hooks autofix_prs: false autoupdate_schedule: monthly ``` The last large commit with the fit functions, for example, was not formatted according to the clang-format rules. This PR would allow to avoid similar mistakes in the future. Python fomat with `ruff` for tests and sanitiser for `.ipynb` notebooks can be added as well.
42 lines
1.4 KiB
CMake
42 lines
1.4 KiB
CMake
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
# Download catch2 if configured to do so
|
|
if(AARE_FETCH_CATCH)
|
|
FetchContent_Declare(
|
|
Catch2
|
|
GIT_SHALLOW TRUE
|
|
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
|
GIT_TAG v3.5.3)
|
|
FetchContent_MakeAvailable(Catch2)
|
|
else()
|
|
# Otherwise look for installed catch2
|
|
find_package(Catch2 3 REQUIRED)
|
|
endif()
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
|
|
|
|
add_executable(tests test.cpp)
|
|
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain aare_core
|
|
aare_compiler_flags)
|
|
# target_compile_options(tests PRIVATE -fno-omit-frame-pointer
|
|
# -fsanitize=address)
|
|
set_target_properties(
|
|
tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_NAME
|
|
run_tests)
|
|
|
|
include(CTest)
|
|
include(Catch)
|
|
catch_discover_tests(tests)
|
|
|
|
set(TestSources ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp)
|
|
target_sources(tests PRIVATE ${TestSources})
|
|
|
|
# Work around to remove, this is not the way to do it =)
|
|
# target_link_libraries(tests PRIVATE aare_core aare_compiler_flags)
|
|
|
|
# configure a header to pass test file paths
|
|
get_filename_component(TEST_FILE_PATH ${PROJECT_SOURCE_DIR}/data ABSOLUTE)
|
|
configure_file(test_config.hpp.in test_config.hpp)
|
|
target_include_directories(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
|
${CMAKE_CURRENT_BINARY_DIR})
|