mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
test(tidy): check the fairmq-* checks with FileCheck
- Add test/tidy/RunCheck.cmake, a small check_clang_tidy.py: run one check with --fix on a copy of the input, then match the diagnostics against CHECK-MESSAGES lines and the fixed file against CHECK-FIXES lines. Any other warning or error fails the test. - Register one test per test/tidy/fairmq-*.cxx file. The inputs use the real FairMQ headers via the usage requirements of the FairMQ target. - Skip the tests with a warning if FileCheck is not found. - Add the test for fairmq-modernize-nonnamespaced-types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -329,3 +329,7 @@ add_testsuite(MemoryResources
|
|||||||
${definitions}
|
${definitions}
|
||||||
${environment}
|
${environment}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(BUILD_TIDY_TOOL)
|
||||||
|
add_subdirectory(tidy)
|
||||||
|
endif()
|
||||||
|
|||||||
46
test/tidy/CMakeLists.txt
Normal file
46
test/tidy/CMakeLists.txt
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
################################################################################
|
||||||
|
# Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||||
|
# #
|
||||||
|
# This software is distributed under the terms of the #
|
||||||
|
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||||
|
# copied verbatim in the file "LICENSE" #
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
find_program(FAIRMQ_TIDY_FILECHECK NAMES FileCheck FileCheck-${LLVM_VERSION_MAJOR}
|
||||||
|
HINTS "${LLVM_TOOLS_BINARY_DIR}"
|
||||||
|
DOC "FileCheck executable for the fairmq-tidy tests"
|
||||||
|
)
|
||||||
|
if(NOT FAIRMQ_TIDY_FILECHECK)
|
||||||
|
message(WARNING "FileCheck not found (install the LLVM tools, e.g. "
|
||||||
|
"llvm-${LLVM_VERSION_MAJOR}-tools). Skipping the fairmq-tidy tests.")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# The test inputs include the real FairMQ headers. Pass the usage requirements
|
||||||
|
# of the FairMQ target to the clang frontend, one flag per line.
|
||||||
|
# Drop the default system include directory: a second copy in the search
|
||||||
|
# path breaks the #include_next chain of the C++ standard library headers.
|
||||||
|
set(incs "$<TARGET_PROPERTY:FairMQ,INTERFACE_INCLUDE_DIRECTORIES>")
|
||||||
|
set(incs "$<REMOVE_DUPLICATES:$<FILTER:${incs},EXCLUDE,^/usr/include/?$>>")
|
||||||
|
set(defs "$<TARGET_PROPERTY:FairMQ,INTERFACE_COMPILE_DEFINITIONS>")
|
||||||
|
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/flags.txt" CONTENT
|
||||||
|
"-std=c++17
|
||||||
|
$<$<BOOL:${incs}>:-isystem\n$<JOIN:${incs},\n-isystem\n>>
|
||||||
|
$<$<BOOL:${defs}>:-D$<JOIN:${defs},\n-D>>
|
||||||
|
")
|
||||||
|
|
||||||
|
file(GLOB inputs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/fairmq-*.cxx")
|
||||||
|
foreach(input IN LISTS inputs)
|
||||||
|
get_filename_component(check "${input}" NAME_WE)
|
||||||
|
add_test(NAME "tidy.${check}"
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
"-DTIDY=$<TARGET_FILE:FairMQ::fairmq-tidy>"
|
||||||
|
"-DFILECHECK=${FAIRMQ_TIDY_FILECHECK}"
|
||||||
|
"-DCHECK=${check}"
|
||||||
|
"-DINPUT=${input}"
|
||||||
|
"-DFLAGS=${CMAKE_CURRENT_BINARY_DIR}/flags.txt"
|
||||||
|
"-DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${check}"
|
||||||
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/RunCheck.cmake"
|
||||||
|
)
|
||||||
|
set_tests_properties("tidy.${check}" PROPERTIES TIMEOUT 120)
|
||||||
|
endforeach()
|
||||||
68
test/tidy/RunCheck.cmake
Normal file
68
test/tidy/RunCheck.cmake
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
################################################################################
|
||||||
|
# Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||||
|
# #
|
||||||
|
# This software is distributed under the terms of the #
|
||||||
|
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||||
|
# copied verbatim in the file "LICENSE" #
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Runs one fairmq-tidy check on one test input and verifies the result with
|
||||||
|
# FileCheck, like check_clang_tidy.py of the LLVM project:
|
||||||
|
#
|
||||||
|
# // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: <message> [<check>]
|
||||||
|
# <code that triggers the check>
|
||||||
|
# // CHECK-FIXES: <code after the fix>
|
||||||
|
#
|
||||||
|
# Any warning or error without a CHECK-MESSAGES line fails the test.
|
||||||
|
#
|
||||||
|
# Usage: cmake -DTIDY=<exe> -DFILECHECK=<exe> -DCHECK=<name> -DINPUT=<file>
|
||||||
|
# -DFLAGS=<file with one compiler flag per line> -DWORKDIR=<dir> -P RunCheck.cmake
|
||||||
|
|
||||||
|
foreach(var IN ITEMS TIDY FILECHECK CHECK INPUT FLAGS WORKDIR)
|
||||||
|
if(NOT DEFINED ${var})
|
||||||
|
message(FATAL_ERROR "${var} is not set")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
file(MAKE_DIRECTORY "${WORKDIR}")
|
||||||
|
get_filename_component(name "${INPUT}" NAME)
|
||||||
|
set(fixed "${WORKDIR}/${name}")
|
||||||
|
set(messages "${WORKDIR}/${name}.messages")
|
||||||
|
|
||||||
|
# Remove the CHECK lines from the copy, but keep the line numbers.
|
||||||
|
file(READ "${INPUT}" content)
|
||||||
|
string(REGEX REPLACE "// *CHECK-[A-Z-]+:[^\n]*" "//" content "${content}")
|
||||||
|
file(WRITE "${fixed}" "${content}")
|
||||||
|
|
||||||
|
file(STRINGS "${FLAGS}" flags)
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${TIDY}" "--checks=-*,${CHECK}" --fix "${fixed}" -- ${flags}
|
||||||
|
OUTPUT_FILE "${messages}"
|
||||||
|
ERROR_VARIABLE stderr
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
)
|
||||||
|
if(NOT result EQUAL 0)
|
||||||
|
file(READ "${messages}" out)
|
||||||
|
message(FATAL_ERROR "fairmq-tidy failed (${result}):\n${out}\n${stderr}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${FILECHECK}" "${INPUT}" --check-prefix=CHECK-MESSAGES
|
||||||
|
"--input-file=${messages}" "--implicit-check-not={{warning|error}}:"
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
)
|
||||||
|
if(NOT result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "The diagnostics do not match the CHECK-MESSAGES lines.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(STRINGS "${INPUT}" fixes REGEX "// *CHECK-FIXES:")
|
||||||
|
if(fixes)
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${FILECHECK}" "${INPUT}" --check-prefix=CHECK-FIXES
|
||||||
|
"--input-file=${fixed}" --match-full-lines
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
)
|
||||||
|
if(NOT result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "The fixed file does not match the CHECK-FIXES lines.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
46
test/tidy/fairmq-modernize-nonnamespaced-types.cxx
Normal file
46
test/tidy/fairmq-modernize-nonnamespaced-types.cxx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include <fairmq/Channel.h>
|
||||||
|
#include <fairmq/Device.h>
|
||||||
|
#include <fairmq/Message.h>
|
||||||
|
#include <fairmq/Parts.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// CHECK-MESSAGES: :[[@LINE+1]]:18: warning: 'FairMQDevice' is deprecated; use 'fair::mq::Device' [fairmq-modernize-nonnamespaced-types]
|
||||||
|
struct Sampler : FairMQDevice
|
||||||
|
// CHECK-FIXES: struct Sampler : fair::mq::Device
|
||||||
|
{
|
||||||
|
bool ConditionalRun() override
|
||||||
|
{
|
||||||
|
// CHECK-MESSAGES: :[[@LINE+1]]:9: warning: 'FairMQMessagePtr' is deprecated; use 'fair::mq::MessagePtr' [fairmq-modernize-nonnamespaced-types]
|
||||||
|
FairMQMessagePtr msg(NewMessage(10));
|
||||||
|
// CHECK-FIXES: fair::mq::MessagePtr msg(NewMessage(10));
|
||||||
|
// CHECK-MESSAGES: :[[@LINE+1]]:11: warning: 'FairMQParts' is deprecated; use 'fair::mq::Parts' [fairmq-modernize-nonnamespaced-types]
|
||||||
|
::FairMQParts parts;
|
||||||
|
// CHECK-FIXES: ::fair::mq::Parts parts;
|
||||||
|
parts.AddPart(std::move(msg));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// CHECK-MESSAGES: :[[@LINE+1]]:23: warning: 'FairMQChannel' is deprecated; use 'fair::mq::Channel' [fairmq-modernize-nonnamespaced-types]
|
||||||
|
void useChannel(const FairMQChannel&);
|
||||||
|
// CHECK-FIXES: void useChannel(const fair::mq::Channel&);
|
||||||
|
|
||||||
|
// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: 'FairMQMessage' is deprecated; use 'fair::mq::Message' [fairmq-modernize-nonnamespaced-types]
|
||||||
|
std::vector<std::unique_ptr<FairMQMessage>> messages;
|
||||||
|
// CHECK-FIXES: std::vector<std::unique_ptr<fair::mq::Message>> messages;
|
||||||
|
|
||||||
|
// Deprecated global aliases without the FairMQ prefix.
|
||||||
|
// CHECK-MESSAGES: :[[@LINE+1]]:1: warning: 'InputMsgCallback' is deprecated; use 'fair::mq::InputMsgCallback' [fairmq-modernize-nonnamespaced-types]
|
||||||
|
InputMsgCallback callback;
|
||||||
|
// CHECK-FIXES: fair::mq::InputMsgCallback callback;
|
||||||
|
|
||||||
|
// Namespaced types and aliases of the user are not reported.
|
||||||
|
using MyDevice = fair::mq::Device;
|
||||||
|
fair::mq::MessagePtr namespacedMsg;
|
||||||
|
MyDevice* device = nullptr;
|
||||||
|
|
||||||
|
// Spellings in macro expansions are not reported.
|
||||||
|
#define DEVICE_PTR FairMQDevice*
|
||||||
|
DEVICE_PTR macroDevice = nullptr;
|
||||||
Reference in New Issue
Block a user