Skip to content

Commit

Permalink
Add clang-tidy support to test harness
Browse files Browse the repository at this point in the history
This is turned off by default.
  • Loading branch information
Blake-Madden committed May 20, 2024
1 parent c1b90c5 commit c81c28e
Show file tree
Hide file tree
Showing 30 changed files with 239 additions and 44 deletions.
18 changes: 18 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
Checks: '-clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,readability-*,cert-*,bugprone-*,misc-*,openmp-*,performance-*,portability-*,hicpp-*,google-*,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-hicpp-use-emplace,-modernize-use-emplace,-readability-function-cognitive-complexity,-bugprone-branch-clone,-hicpp-signed-bitwise,-misc-use-anonymous-namespace,-misc-no-recursion,-modernize-use-trailing-return-type,-misc-include-cleaner'
HeaderFilterRegex: ''
FormatStyle: none
InheritParentConfig: true
CheckOptions:
readability-braces-around-statements.ShortStatementLines: 1
readability-function-size.LineThreshold: 800
readability-identifier-naming.ClassMemberPrefix: m_
readability-identifier-naming.ClassMemberCase: camelBack
readability-identifier-naming.LocalVariableCase: camelBack
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
readability-identifier-naming.ParameterCase: camelBack
readability-identifier-naming.ClassCase: lower_case
readability-identifier-naming.StructCase: lower_case
readability-identifier-naming.EnumCase: lower_case
readability-identifier-naming.FunctionNameCase: lower_case
readability-identifier-naming.NamespaceCase: lower_case
2 changes: 1 addition & 1 deletion src/i18n-check
67 changes: 41 additions & 26 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,45 @@
# License: 3-Clause BSD license
#############################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED True)
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

PROJECT(WisteriaTestRunner)
# Options:
# - USE_CLANG_TIDY to run clang-tidy

ADD_COMPILE_OPTIONS("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
ADD_COMPILE_OPTIONS("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
find_program(CLANG_TIDY_COMMAND
NAMES
clang-tidy
NO_CACHE)
if(CLANG_TIDY_COMMAND AND USE_CLANG_TIDY)
if(MSVC)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND} --extra-arg=/EHsc)
else()
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND})
endif()
endif()

MESSAGE(STATUS "Finding Catch2...")
project(WisteriaTestRunner)

add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

message(STATUS "Finding Catch2...")
# place Catch2 at the same folder level as this repo if it isn't installed
# (you will need to do this on Windows or macOS or if version 3 of Catch2 isn't installed)
GET_FILENAME_COMPONENT(_fullpath "${_dir}" REALPATH)
IF(EXISTS "${_fullpath}" AND EXISTS "${_fullpath}/../../Catch2")
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../Catch2 ${CMAKE_CURRENT_BINARY_DIR}/Catch2)
ELSE()
get_filename_component(_fullpath "${_dir}" REALPATH)
if(EXISTS "${_fullpath}" AND EXISTS "${_fullpath}/../../Catch2")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../Catch2 ${CMAKE_CURRENT_BINARY_DIR}/Catch2)
else()
# ...otherwise, see if it is installed
FIND_PACKAGE(Catch2 3 REQUIRED)
ENDIF()
find_package(Catch2 3 REQUIRED)
endif()

# Define the build target for the executable
MESSAGE(STATUS "Preparing the test runner...")
INCLUDE(${CMAKE_SOURCE_DIR}/../tools/testfiles.cmake)
SET(LIB_SRC_FILES
message(STATUS "Preparing the test runner...")
include(${CMAKE_SOURCE_DIR}/../tools/testfiles.cmake)
set(LIB_SRC_FILES
../src/import/cpp_extract_text.cpp
../src/import/doc_extract_text.cpp
../src/import/docx_extract_text.cpp
Expand All @@ -40,28 +55,28 @@ SET(LIB_SRC_FILES
../src/import/postscript_extract_text.cpp
../src/import/xlsx_extract_text.cpp
../src/import/rtf_extract_text.cpp)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${TEST_SRC_FILES} ${LIB_SRC_FILES})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(${CMAKE_PROJECT_NAME} ${TEST_SRC_FILES} ${LIB_SRC_FILES})

# Link required libraries to the executable
IF(WIN32)
if(WIN32)
TARGET_COMPILE_DEFINITIONS(${CMAKE_PROJECT_NAME} PUBLIC __UNITTEST _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION)
TARGET_COMPILE_OPTIONS(${CMAKE_PROJECT_NAME} PRIVATE /Zc:__cplusplus /fsanitize=address)
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} PRIVATE Catch2::Catch2WithMain)
ELSEIF(UNIX)
elseif(UNIX)
TARGET_COMPILE_DEFINITIONS(${CMAKE_PROJECT_NAME} PUBLIC __UNITTEST)
FIND_LIBRARY(TBB_LIB tbb)
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} ${TBB_LIB} Catch2::Catch2WithMain)
ENDIF()
endif()

# Copy datasets into build folder
MESSAGE(STATUS "Copying datasets...")
ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}
message(STATUS "Copying datasets...")
add_custom_command(TARGET ${CMAKE_PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/../datasets $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/datasets)

# load the test cases into the runner
INCLUDE(CTest)
INCLUDE(Catch)
CATCH_DISCOVER_TESTS(${CMAKE_PROJECT_NAME})
include(CTest)
include(Catch)
catch_discover_tests(${CMAKE_PROJECT_NAME})
6 changes: 6 additions & 0 deletions tests/comparedoublestests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <map>
Expand Down Expand Up @@ -96,3 +99,6 @@ TEST_CASE("Compare doubles", "[comparedoubles]")
CHECK(has_fractional_part(-5.1));
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/cppparsetests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
Expand Down Expand Up @@ -241,3 +244,6 @@ TEST_CASE("CPP 2", "[cpp]")
CHECK(ext.get_filtered_text_length() == 31);
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/docparsetests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/import/doc_extract_text.h"
Expand Down Expand Up @@ -68,3 +71,6 @@ TEST_CASE("DOC Parser", "[doc import]")
CHECK(stream.seek(9999, word1997_extract_text::cfb_iostream::cfb_strem_seek_type::seek_cur) == buffSize);
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/docxparsetests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/import/docx_extract_text.h"
Expand Down Expand Up @@ -65,3 +68,6 @@ TEST_CASE("Word 2007 Parser", "[docx import]")
CHECK(ext.get_filtered_text_length() == 28);
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/evenoddtests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/math/mathematics.h"
Expand Down Expand Up @@ -81,3 +84,6 @@ TEST_CASE("Even", "[even]")
CHECK(is_even(-27514573.20248) == false);
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/geometrytests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/math/safe_math.h"
Expand Down Expand Up @@ -157,3 +160,6 @@ TEST_CASE("Rescale", "[geometry]")
CHECK_THAT(100, WithinRel(result.second, 1e-4));
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/hhcimporttests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/import/hhc_hhk_extract_text.h"
Expand All @@ -24,3 +27,6 @@ TEST_CASE("HHC Import", "[hhc import]")
CHECK(ext.get_filtered_text_length() == 60);
}
}

// NOLINTEND
// clang-format on
8 changes: 7 additions & 1 deletion tests/htmlencodetests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/import/html_encode.h"
Expand Down Expand Up @@ -53,4 +56,7 @@ TEST_CASE("HTML Encode", "[html encode]")
CHECK(encode.needs_to_be_encoded(text));
CHECK(encode(text, true) == L"he&#226;llo&#1074;");
}
}
}

// NOLINTEND
// clang-format on
8 changes: 7 additions & 1 deletion tests/htmlimporttests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/util/frequencymap.h"
Expand Down Expand Up @@ -1855,4 +1858,7 @@ TEST_CASE("HTML Link Strip", "[html import]")
CHECK(std::wcscmp(strip(text,std::wcslen(text)), expected) == 0);
CHECK(strip.get_filtered_text_length() == std::wcslen(expected));
}
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/idlparsetests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/import/idl_extract_text.h"
Expand Down Expand Up @@ -44,3 +47,6 @@ TEST_CASE("IDL Parser", "[idl import]")
CHECK(ext.get_filtered_text_length() == 0);
}
}

// NOLINTEND
// clang-format on
8 changes: 7 additions & 1 deletion tests/intsplittests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/math/mathematics.h"
Expand Down Expand Up @@ -89,4 +92,7 @@ TEST_CASE("Integer to bool", "[inttobool]")
CHECK_FALSE(int_to_bool(0));
CHECK_FALSE(int_to_bool(false));
CHECK(int_to_bool(true));
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/mapstests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/util/frequencymap.h"
Expand Down Expand Up @@ -328,3 +331,6 @@ TEST_CASE("Frequency sets", "[frequencymaps]")
CHECK(waspsValues->second == 2);
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/mdparsetests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/import/markdown_extract_text.h"
Expand Down Expand Up @@ -255,3 +258,6 @@ The End.)" }) } ==
std::wstring{ L"shared_ptr" });
}
}

// NOLINTEND
// clang-format on
6 changes: 6 additions & 0 deletions tests/odtparsetests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// NOLINTBEGIN
// clang-format off

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "../src/import/odt_odp_extract_text.h"
Expand Down Expand Up @@ -80,3 +83,6 @@ TEST_CASE("OpenDocument Parser", "[odt import]")
CHECK(ext.get_filtered_text_length() == 36);
}
}

// NOLINTEND
// clang-format on
Loading

0 comments on commit c81c28e

Please sign in to comment.