mardi 29 mai 2018

Catch2 - undefined reference to

I'm testing my project using Catch2 as library. I followed every step in the Catch doc, but when I run the tests I get the following error:

CMakeFiles/tests.dir/tests/IntegerIntervalTest.cpp.o: in function "____C_A_T_C_H____T_E_S_T____0()": /home/davide/cpp-project/tests/IntegerIntervalTest.cpp:8: undefined reference to "domain::IntegerAbstractInterval<int, int>::IntegerAbstractInterval(int, int)"

and this error repeates for every method call in the test "class".

CMakeLists:

PROJECT(cpp_project)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
INCLUDE(CheckCXXCompilerFlag)

CHECK_CXX_COMPILER_FLAG(-std=c++14 COMPILER_SUPPORTS_CXX14)
IF (COMPILER_SUPPORTS_CXX14)
    ADD_COMPILE_OPTIONS("-std=c++14")
ELSE ()
    MESSAGE(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++14 support.")
ENDIF ()


set(BASE_SRCS src/Bound.cpp src/Bound.hpp src/Infinity.cpp src/Infinity.hpp src/AbstractInterval.cpp src/AbstractInterval.hpp
        src/UndefinedOperationException.hpp src/IntegerAbstractInterval.cpp src/IntegerAbstractInterval.hpp src/FloatingPointAbstractInterval.cpp
        src/FloatingPointAbstractInterval.hpp)
ADD_COMPILE_OPTIONS("-Wall" "-Wextra" "-Wpedantic" "-Werror" )
ADD_LIBRARY(cpp-project ${BASE_SRCS})
INCLUDE_DIRECTORIES(libs/variant/include)


set(EXECUTABLE_OUTPUT_PATH bin)
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
set(TEST_SRCS tests/InfinityTest.cpp tests/IntegerIntervalTest.cpp)
add_executable(tests ${BASE_SRCS} ${TEST_SRCS})
target_link_libraries(tests Catch)

and this is the test file IntegerIntervalTest.cpp:

#include "../src/IntegerAbstractInterval.hpp"
#include "../libs/catch2/catch.hpp"

using namespace domain;


TEST_CASE("Operations on IntegerInterval instances", "[IntegerAbstractInterval]") {
    IntegerAbstractInterval<int, int> i(0,1);
    IntegerAbstractInterval<Infinity, Infinity> ii(Infinity('-'), Infinity('+'));
    IntegerAbstractInterval<Infinity, int> iii(Infinity('-'), 5);
    IntegerAbstractInterval<int, Infinity> iv(0, Infinity('+'));
    IntegerAbstractInterval<int, int> v(-1,1);

    SECTION("Sum operations") {
        auto res1 = i + v;
        REQUIRE(res1.getLowerBound() == Bound(-1));
        REQUIRE(res1.getUpperBound() == Bound(2));
    }
}

Aucun commentaire:

Enregistrer un commentaire