Skip to content

Commit

Permalink
tests: If system Catch2 is the same or newer, use it
Browse files Browse the repository at this point in the history
... it may contain additional fixes relevant to the given OS and also
issue a warning if there is a newer version, so that we will be notified
to update the bundled one.
  • Loading branch information
lzaoral committed Apr 12, 2021
1 parent 0b8e558 commit 74e4c8d
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 14 deletions.
33 changes: 31 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,48 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} ${CTEST_OPTS}
USES_TERMINAL)

# --------------------------------------------------
# precompile Catch2 main
# Catch2
# --------------------------------------------------

# version of bundled Catch2
set(CATCH_VERSION 2.13.5)

# Catch2 main
add_library(catch-main OBJECT catch-main.cpp)

# If we can find the same version or newer, use it as it may contain
# additional fixes relevant to the given OS
find_package(Catch2 ${CATCH_VERSION} QUIET CONFIG)
if(Catch2_FOUND)
message(STATUS "Found Catch2 (found version \"${Catch2_VERSION}\")")
# Issue a warning if there is a newer version, so that we will be notified
# to update the bundled one.
if(${CATCH_VERSION} VERSION_GREATER ${Catch2_FOUND})
message(WARNING
"The bundled Catch2 seems to be outdated: ${CATCH_VERSION}\n"
"Please report this to our issue tracker. Thank you!")
endif()

# use correct include directories
target_link_libraries(catch-main PRIVATE Catch2::Catch2)
else()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
endif()

macro(add_catch_test TEST_FILE)
if (NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${TEST_FILE}")
message(FATAL_ERROR "Test '${TEST_FILE}' does not exist!")
endif()
get_filename_component(TEST ${TEST_FILE} NAME_WE)

add_executable(${TEST} ${TEST_FILE} $<TARGET_OBJECTS:catch-main>)
add_executable(${TEST} ${TEST_FILE})
add_test(${TEST} ${TEST})
add_dependencies(check ${TEST})
target_link_libraries(${TEST} PRIVATE $<TARGET_OBJECTS:catch-main>)

if(Catch2_FOUND)
target_link_libraries(${TEST} PRIVATE Catch2::Catch2)
endif()
endmacro()

# --------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/adt-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include "dg/ADT/Queue.h"
#include "dg/ADT/Bitvector.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/bitvector-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include <random>
#include <set>
Expand Down
2 changes: 1 addition & 1 deletion tests/catch-main.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <catch2/catch.hpp>
2 changes: 1 addition & 1 deletion tests/disjunctive-intervals-map-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include <random>
#include <sstream>
Expand Down
2 changes: 1 addition & 1 deletion tests/llvm-dg-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include "dg/llvm/LLVMDependenceGraph.h"
#include "dg/DFS.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/nodes-walk-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include <dg/NodesWalk.h>
#include <dg/ADT/Queue.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/numbers-set-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include <set>

Expand Down
2 changes: 1 addition & 1 deletion tests/points-to-set-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include "dg/PointerAnalysis/PSNode.h"
#include "dg/PointerAnalysis/PointerGraph.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/points-to-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include "dg/PointerAnalysis/PointerGraph.h"
#include "dg/PointerAnalysis/PointerAnalysisFI.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/rdmap-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include <random>
#include <cassert>
Expand Down
2 changes: 1 addition & 1 deletion tests/readwritegraph-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include "dg/ReadWriteGraph/ReadWriteGraph.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/thread-regions-test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>

#include "dg/llvm/PointerAnalysis/PointerAnalysis.h"
#include "dg/PointerAnalysis/PointerAnalysisFI.h"
Expand Down

0 comments on commit 74e4c8d

Please sign in to comment.