From cc0d44a01dabe9f9899365ecf8f42cd50d38ea69 Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 15 Dec 2018 12:18:07 +0100 Subject: [PATCH] :wrench: Replaced gtest with catch2 --- CMakeLists.txt | 3 +++ test/CMakeLists.txt | 19 ++++++++----------- test/test.cpp | 23 ++++++++++++----------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e69f17..7675941 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,10 @@ # possible settings. #------------------------------------------------------- cmake_minimum_required(VERSION 3.0) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) +set(CMAKE_CXX_STANDARD 11) + project(moFileReader) # Let the user choose between static lib and dll diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b377211..f876925 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,20 +1,17 @@ -if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") - message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") - file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.13/conan.cmake" - "${CMAKE_BINARY_DIR}/conan.cmake") +if(NOT EXISTS "${CMAKE_BINARY_DIR}/catch/catch.hpp") + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/catch") + message(STATUS "Downloading catch.hpp from https://github.com/catchorg/Catch2/") + file(DOWNLOAD "https://github.com/catchorg/Catch2/releases/download/v2.5.0/catch.hpp" + "${CMAKE_BINARY_DIR}/catch/catch.hpp") endif() -include(${CMAKE_BINARY_DIR}/conan.cmake) - -conan_cmake_run(REQUIRES gtest/1.8.1@bincrafters/stable BASIC_SETUP CMAKE_TARGETS BUILD missing) - add_executable(moFileReaderTest test.cpp) -target_include_directories(moFileReaderTest PRIVATE ${CMAKE_SOURCE_DIR}/include) -target_link_libraries(moFileReaderTest CONAN_PKG::gtest moFileReader) +target_include_directories(moFileReaderTest PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/catch) +target_link_libraries(moFileReaderTest moFileReader) add_test(NAME mo_test COMMAND moFileReaderTest) add_custom_command( TARGET moFileReaderTest POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo $/test.mo + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo $/test.mo COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo ${CMAKE_CURRENT_BINARY_DIR}/test.mo ) diff --git a/test/test.cpp b/test/test.cpp index d42a75f..e3325a7 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,35 +1,36 @@ +#define CATCH_CONFIG_MAIN #include "moFileReader.h" -#include "gtest/gtest.h" +#include "catch.hpp" using namespace moFileLib; #define _L(str) moFileReaderSingleton::GetInstance().Lookup(str) #define _LC(ctx,str) moFileReaderSingleton::GetInstance().LookupWithContext(ctx,str) -TEST(moFileReader, setup) +TEST_CASE ("Load mo-file", "[ReadFile]") { - EXPECT_EQ(moFileReaderSingleton::GetInstance().ReadFile("test.mo"), moFileLib::moFileReader::EC_SUCCESS); + CHECK (moFileReaderSingleton::GetInstance().ReadFile("test.mo") == moFileLib::moFileReader::EC_SUCCESS); } -TEST(moFileReader, Lookup) +TEST_CASE ("Lookup string", "[Lookup]") { moFileReaderSingleton::GetInstance ().ReadFile ("test.mo"); /* This is the first comment. */ - EXPECT_EQ ("Text Nederlands Een", _L ("String English One")); + CHECK ("Text Nederlands Een" == _L ("String English One")); /* This is the second comment. */ - EXPECT_EQ ("Text Nederlands Twee", _L ("String English Two")); + CHECK ("Text Nederlands Twee" == _L ("String English Two")); /* This is the third comment. */ - EXPECT_EQ ("Text Nederlands Drie", _L ("String English Three")); + CHECK ("Text Nederlands Drie" == _L ("String English Three")); } -TEST (moFileReader, LookupWithContext) +TEST_CASE ("Lookup string with context", "[LookupWithContext]") { moFileReaderSingleton::GetInstance ().ReadFile ("test.mo"); /* This is the first comment. */ - EXPECT_EQ ("Text Nederlands Een", _LC ("TEST|String|1", "String English")); + CHECK ("Text Nederlands Een" == _LC ("TEST|String|1", "String English")); /* This is the second comment. */ - EXPECT_EQ ("Text Nederlands Twee", _LC ("TEST|String|2", "String English")); + CHECK ("Text Nederlands Twee" == _LC ("TEST|String|2", "String English")); /* This is the third comment. */ - EXPECT_EQ ("Text Nederlands Drie", _LC ("TEST|String|3", "String English")); + CHECK ("Text Nederlands Drie" == _LC ("TEST|String|3", "String English")); } \ No newline at end of file