mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
Merge pull request #596 from tbeu/update-cpp-cmake
Add test specific CMake options to C++ configuration
This commit is contained in:
commit
71261052fa
4
cpp-catch2/.gitignore
vendored
4
cpp-catch2/.gitignore
vendored
@ -1,4 +0,0 @@
|
|||||||
/build_meson/
|
|
||||||
/subprojects/Catch2-*/
|
|
||||||
/subprojects/packagecache/
|
|
||||||
/cmake-build-*/
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.14..3.16)
|
|
||||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
||||||
project(GildedRoseKata VERSION 1.0
|
|
||||||
DESCRIPTION "The GildedRose Refactoring kata for an approval testing approach"
|
|
||||||
LANGUAGES CXX)
|
|
||||||
include(FetchContent)
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
catch2
|
|
||||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
|
||||||
GIT_TAG v2.13.10
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(catch2)
|
|
||||||
LIST(APPEND CMAKE_MODULE_PATH
|
|
||||||
${catch2_SOURCE_DIR}/contrib
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
approvaltests_ho
|
|
||||||
URL https://github.com/approvals/ApprovalTests.cpp/releases/download/v.10.13.0/ApprovalTests.v.10.13.0.hpp
|
|
||||||
DOWNLOAD_NO_EXTRACT TRUE
|
|
||||||
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/approvaltests
|
|
||||||
DOWNLOAD_NAME ApprovalTests.v.10.13.0.hpp
|
|
||||||
)
|
|
||||||
FetchContent_GetProperties(approvaltests_ho)
|
|
||||||
if (NOT approvaltests_ho_POPULATED)
|
|
||||||
FetchContent_Populate(approvaltests_ho)
|
|
||||||
endif ()
|
|
||||||
add_library(approvaltests INTERFACE)
|
|
||||||
target_include_directories(approvaltests
|
|
||||||
INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/approvaltests
|
|
||||||
INTERFACE ${catch2_SOURCE_DIR}/single_include/catch2
|
|
||||||
)
|
|
||||||
|
|
||||||
if( MINGW )
|
|
||||||
# https://stackoverflow.com/questions/31890021/mingw-too-many-sections-bug-while-compiling-huge-header-file-in-qt
|
|
||||||
set (CMAKE_CXX_FLAGS "-Wa,-mbig-obj ")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(gildedrose_catch2
|
|
||||||
src/GildedRose.h
|
|
||||||
src/GildedRose.cc
|
|
||||||
test/gildedrose_catch.cpp
|
|
||||||
test/main.cpp)
|
|
||||||
set_target_properties(gildedrose_catch2 PROPERTIES CXX_STANDARD 11)
|
|
||||||
target_include_directories(gildedrose_catch2
|
|
||||||
PUBLIC src)
|
|
||||||
target_link_libraries(gildedrose_catch2 Catch2::Catch2 approvaltests)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include(CTest)
|
|
||||||
include(ParseAndAddCatchTests)
|
|
||||||
ParseAndAddCatchTests(gildedrose_catch2)
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
C++ version of Gilded Rose with Catch 2 and Approvals
|
|
||||||
======================================================
|
|
||||||
|
|
||||||
This is a C++ start of the Gilded Rose Refactoring Kata. See
|
|
||||||
the [top level readme](https://github.com/emilybache/GildedRose-Refactoring-Kata)
|
|
||||||
for a general description of the exercise.
|
|
||||||
|
|
||||||
There are two (failing) unit tests included here. One uses only the catch2 framework, the other additionally uses [ApprovalTests](https://github.com/approvals/approvaltests.cpp). You should choose one of these tests to work with and delete the other.
|
|
||||||
|
|
||||||
CMake
|
|
||||||
-----
|
|
||||||
|
|
||||||
CMake is included in CLion from JetBrains. Without CMake files
|
|
||||||
CLion has a hard time to handle c-projects.
|
|
||||||
|
|
||||||
To install CMake (if you don't use CLion) on macOS using brew
|
|
||||||
|
|
||||||
brew install cmake
|
|
||||||
|
|
||||||
Tested on CMake 3.15.3 (included with CLion 2019.3) on macOS
|
|
||||||
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
#include "GildedRose.h"
|
|
||||||
|
|
||||||
GildedRose::GildedRose(vector<Item> & items) : items(items)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void GildedRose::updateQuality()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < items.size(); i++)
|
|
||||||
{
|
|
||||||
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert")
|
|
||||||
{
|
|
||||||
if (items[i].quality > 0)
|
|
||||||
{
|
|
||||||
if (items[i].name != "Sulfuras, Hand of Ragnaros")
|
|
||||||
{
|
|
||||||
items[i].quality = items[i].quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (items[i].quality < 50)
|
|
||||||
{
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
|
|
||||||
if (items[i].name == "Backstage passes to a TAFKAL80ETC concert")
|
|
||||||
{
|
|
||||||
if (items[i].sellIn < 11)
|
|
||||||
{
|
|
||||||
if (items[i].quality < 50)
|
|
||||||
{
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items[i].sellIn < 6)
|
|
||||||
{
|
|
||||||
if (items[i].quality < 50)
|
|
||||||
{
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items[i].name != "Sulfuras, Hand of Ragnaros")
|
|
||||||
{
|
|
||||||
items[i].sellIn = items[i].sellIn - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items[i].sellIn < 0)
|
|
||||||
{
|
|
||||||
if (items[i].name != "Aged Brie")
|
|
||||||
{
|
|
||||||
if (items[i].name != "Backstage passes to a TAFKAL80ETC concert")
|
|
||||||
{
|
|
||||||
if (items[i].quality > 0)
|
|
||||||
{
|
|
||||||
if (items[i].name != "Sulfuras, Hand of Ragnaros")
|
|
||||||
{
|
|
||||||
items[i].quality = items[i].quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
items[i].quality = items[i].quality - items[i].quality;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (items[i].quality < 50)
|
|
||||||
{
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Item
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
string name;
|
|
||||||
int sellIn;
|
|
||||||
int quality;
|
|
||||||
Item(string name, int sellIn, int quality) : name(name), sellIn(sellIn), quality(quality)
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
class GildedRose
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
vector<Item> & items;
|
|
||||||
GildedRose(vector<Item> & items);
|
|
||||||
|
|
||||||
void updateQuality();
|
|
||||||
};
|
|
||||||
|
|
||||||
@ -1 +0,0 @@
|
|||||||
#include "ApprovalTests.v.10.13.0.hpp"
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
#include <catch2/catch.hpp>
|
|
||||||
#include "ApprovalTests.hpp"
|
|
||||||
|
|
||||||
#include "GildedRose.h"
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Item& obj)
|
|
||||||
{
|
|
||||||
return os
|
|
||||||
<< "name: " << obj.name
|
|
||||||
<< ", sellIn: " << obj.sellIn
|
|
||||||
<< ", quality: " << obj.quality;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a normal unit test using Catch2
|
|
||||||
TEST_CASE("UpdateQuality") {
|
|
||||||
|
|
||||||
vector<Item> items;
|
|
||||||
items.push_back(Item("foo", 0, 0));
|
|
||||||
GildedRose app(items);
|
|
||||||
app.updateQuality();
|
|
||||||
REQUIRE("fixme" == app.items[0].name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is an Approval test using https://github.com/approvals/approvaltests.cpp
|
|
||||||
TEST_CASE("UpdateQualityApprovalTest") {
|
|
||||||
vector<Item> items;
|
|
||||||
items.push_back(Item("foo", 0, 0));
|
|
||||||
GildedRose app(items);
|
|
||||||
app.updateQuality();
|
|
||||||
auto item = app.items[0];
|
|
||||||
ApprovalTests::Approvals::verify(item);
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
#define CATCH_CONFIG_MAIN
|
|
||||||
#define APPROVALS_CATCH
|
|
||||||
|
|
||||||
#include "catch2/catch.hpp"
|
|
||||||
#include "ApprovalTests.hpp"
|
|
||||||
@ -6,6 +6,14 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|||||||
# uncomment this line to enable coverage measurements using gcov
|
# uncomment this line to enable coverage measurements using gcov
|
||||||
# set(CMAKE_CXX_FLAGS "--coverage")
|
# set(CMAKE_CXX_FLAGS "--coverage")
|
||||||
|
|
||||||
|
option(BUILD_APPROVAL_TESTS_WITH_GTEST "Use GoogleTest for approval testing" ON)
|
||||||
|
|
||||||
|
option(BUILD_UNIT_TESTS_WITH_GTEST "Use GoogleTest for unit testing" ON)
|
||||||
|
|
||||||
|
option(BUILD_APPROVAL_TESTS_WITH_CATCH2 "Use Catch2 for approval testing" ON)
|
||||||
|
|
||||||
|
option(BUILD_UNIT_TESTS_WITH_CATCH2 "Use Catch2 for unit testing" ON)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|||||||
@ -6,16 +6,16 @@ The C++ version of the Gilded Rose refactoring kata is available in four variant
|
|||||||
* Catch2 test framework
|
* Catch2 test framework
|
||||||
1. Traditional unit test with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_unittest` folder.
|
1. Traditional unit test with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_unittest` folder.
|
||||||
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_approvaltest` folder.
|
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [Catch2](https://github.com/catchorg/Catch2) test framework in the `test/cpp_catch2_approvaltest` folder.
|
||||||
* Google Test framework
|
* GoogleTest framework
|
||||||
1. Traditional unit test with the [Googletest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_unittest` folder.
|
1. Traditional unit test with the [GoogleTest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_unittest` folder.
|
||||||
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [Googletest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_approvaltest` folder.
|
2. [Approval tests](https://github.com/approvals/ApprovalTests.cpp) with the [GoogleTest](https://github.com/google/googletest) test framework in the `test/cpp_googletest_approvaltest` folder.
|
||||||
|
|
||||||
The `GildedRose.cc` file, i.e. the code under test, is identical in all four variants.
|
The `GildedRose.cc` file, i.e. the code under test, is identical in all four variants.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* CMake version >= 3.13
|
* CMake version ≥ 3.13
|
||||||
* C++ compiler that supports C++14
|
* C++ compiler that supports C++14
|
||||||
|
|
||||||
## How to build and run tests in a terminal
|
## How to build and run tests in a terminal
|
||||||
|
|
||||||
@ -27,6 +27,19 @@ The `GildedRose.cc` file, i.e. the code under test, is identical in all four var
|
|||||||
$ cmake ..
|
$ cmake ..
|
||||||
$ cmake --build .
|
$ cmake --build .
|
||||||
|
|
||||||
|
The following test specific options for building with CMake are available.
|
||||||
|
|
||||||
|
* `BUILD_APPROVAL_TESTS_WITH_CATCH2:BOOL=ON`
|
||||||
|
This option builds the approval tests with the Catch2 test framework.
|
||||||
|
* `BUILD_UNIT_TESTS_WITH_CATCH2:BOOL=ON`
|
||||||
|
This option builds the unit tests with the Catch2 test framework.
|
||||||
|
* `BUILD_APPROVAL_TESTS_WITH_GTEST:BOOL=ON`
|
||||||
|
This option builds the approval tests with the GoogleTest test framework.
|
||||||
|
* `BUILD_UNIT_TESTS_WITH_GTEST:BOOL=ON`
|
||||||
|
This option builds the unit tests with the GoogleTest test framework.
|
||||||
|
|
||||||
|
For example, run the CMake configuration `cmake -DBUILD_APPROVAL_TESTS_WITH_CATCH2=OFF -DBUILD_UNIT_TESTS_WITH_CATCH2=OFF ..` to disable the Catch2 based tests.
|
||||||
|
|
||||||
### Show available tests
|
### Show available tests
|
||||||
|
|
||||||
$ cd ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp/build
|
$ cd ${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp/build
|
||||||
@ -55,12 +68,12 @@ The `GildedRose.cc` file, i.e. the code under test, is identical in all four var
|
|||||||
2. Select menu `File - Open...`
|
2. Select menu `File - Open...`
|
||||||
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
|
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
|
||||||
4. Select menu `Build - Build Project`
|
4. Select menu `Build - Build Project`
|
||||||
4. Select menu `Run - Run...`
|
5. Select menu `Run - Run...`
|
||||||
4. Select what test variant to run, e.g. `GildedRoseCatch2ApprovalTests`.
|
6. Select what test variant to run, e.g. `GildedRoseCatch2ApprovalTests`.
|
||||||
|
|
||||||
## How to build and run tests using Visual Studio 2019
|
## How to build and run tests using Visual Studio ≥ 2019
|
||||||
|
|
||||||
1. Start Visual Studio 2019
|
1. Start Visual Studio
|
||||||
2. Select `Open a local folder`
|
2. Select `Open a local folder`
|
||||||
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
|
3. Select folder `${GIT_FOLDER}/GildedRose-Refactoring-Kata/cpp`
|
||||||
4. Wait for message `CMake generation finished.` in the CMake output window at the bottom
|
4. Wait for message `CMake generation finished.` in the CMake output window at the bottom
|
||||||
|
|||||||
@ -1,29 +1,35 @@
|
|||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(
|
if (BUILD_APPROVAL_TESTS_WITH_GTEST OR BUILD_UNIT_TESTS_WITH_GTEST)
|
||||||
googletest
|
FetchContent_Declare(
|
||||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
googletest
|
||||||
GIT_TAG v1.16.0
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
GIT_SHALLOW TRUE
|
GIT_TAG v1.16.0
|
||||||
)
|
GIT_SHALLOW TRUE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
endif()
|
||||||
|
|
||||||
FetchContent_Declare(
|
if (BUILD_APPROVAL_TESTS_WITH_CATCH2 OR BUILD_UNIT_TESTS_WITH_CATCH2)
|
||||||
catch2
|
FetchContent_Declare(
|
||||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
catch2
|
||||||
GIT_TAG v3.8.0
|
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||||
GIT_SHALLOW TRUE
|
GIT_TAG v3.8.0
|
||||||
)
|
GIT_SHALLOW TRUE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(catch2)
|
||||||
|
endif()
|
||||||
|
|
||||||
FetchContent_MakeAvailable(googletest catch2)
|
if (BUILD_APPROVAL_TESTS_WITH_GTEST OR BUILD_UNIT_TESTS_WITH_GTEST)
|
||||||
|
# Force Google Test to link the C/C++ runtimes dynamically
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
# Force Google Test to link the C/C++ runtimes dynamically
|
# Disable building GMock
|
||||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
# Disable building GMock
|
# Do not install GTest
|
||||||
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
|
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
|
||||||
|
endif()
|
||||||
# Do not install GTest
|
|
||||||
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
|
|
||||||
|
|
||||||
add_subdirectory(cpp_catch2_approvaltest)
|
add_subdirectory(cpp_catch2_approvaltest)
|
||||||
add_subdirectory(cpp_catch2_unittest)
|
add_subdirectory(cpp_catch2_unittest)
|
||||||
|
|||||||
@ -1,20 +1,22 @@
|
|||||||
set(TEST_NAME GildedRoseCatch2ApprovalTests)
|
if (BUILD_APPROVAL_TESTS_WITH_CATCH2)
|
||||||
add_executable(${TEST_NAME})
|
set(TEST_NAME GildedRoseCatch2ApprovalTests)
|
||||||
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2ApprovalTests.cc)
|
add_executable(${TEST_NAME})
|
||||||
target_include_directories(${TEST_NAME} PUBLIC ../third_party)
|
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2ApprovalTests.cc)
|
||||||
target_link_libraries(${TEST_NAME} GildedRoseLib Catch2::Catch2 Catch2::Catch2WithMain)
|
target_include_directories(${TEST_NAME} PUBLIC ../third_party)
|
||||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14)
|
target_link_libraries(${TEST_NAME} GildedRoseLib Catch2::Catch2 Catch2::Catch2WithMain)
|
||||||
add_test(
|
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14)
|
||||||
|
add_test(
|
||||||
NAME ${TEST_NAME}
|
NAME ${TEST_NAME}
|
||||||
COMMAND ${TEST_NAME}
|
COMMAND ${TEST_NAME}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
||||||
# The __FILE__ macro is used by Catch2 to get the path to current test file.
|
# The __FILE__ macro is used by Catch2 to get the path to current test file.
|
||||||
# Links:
|
# Links:
|
||||||
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
||||||
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
@ -1,19 +1,21 @@
|
|||||||
set(TEST_NAME GildedRoseCatch2UnitTests)
|
if (BUILD_UNIT_TESTS_WITH_CATCH2)
|
||||||
add_executable(${TEST_NAME})
|
set(TEST_NAME GildedRoseCatch2UnitTests)
|
||||||
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2UnitTests.cc)
|
add_executable(${TEST_NAME})
|
||||||
target_link_libraries(${TEST_NAME} GildedRoseLib Catch2::Catch2 Catch2::Catch2WithMain )
|
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2UnitTests.cc)
|
||||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14)
|
target_link_libraries(${TEST_NAME} GildedRoseLib Catch2::Catch2 Catch2::Catch2WithMain )
|
||||||
add_test(
|
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14)
|
||||||
|
add_test(
|
||||||
NAME ${TEST_NAME}
|
NAME ${TEST_NAME}
|
||||||
COMMAND ${TEST_NAME}
|
COMMAND ${TEST_NAME}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
||||||
# The __FILE__ macro is used by Catch2 to get the path to current test file.
|
# The __FILE__ macro is used by Catch2 to get the path to current test file.
|
||||||
# Links:
|
# Links:
|
||||||
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
||||||
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -1,20 +1,22 @@
|
|||||||
set(TEST_NAME GildedRoseGoogletestApprovalTests)
|
if (BUILD_APPROVAL_TESTS_WITH_GTEST)
|
||||||
add_executable(${TEST_NAME})
|
set(TEST_NAME GildedRoseGoogletestApprovalTests)
|
||||||
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestApprovalTests.cc)
|
add_executable(${TEST_NAME})
|
||||||
target_include_directories(${TEST_NAME} PUBLIC ../third_party)
|
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestApprovalTests.cc)
|
||||||
target_link_libraries(${TEST_NAME} GildedRoseLib gtest)
|
target_include_directories(${TEST_NAME} PUBLIC ../third_party)
|
||||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
|
target_link_libraries(${TEST_NAME} GildedRoseLib gtest)
|
||||||
add_test(
|
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
|
||||||
|
add_test(
|
||||||
NAME ${TEST_NAME}
|
NAME ${TEST_NAME}
|
||||||
COMMAND ${TEST_NAME}
|
COMMAND ${TEST_NAME}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
||||||
# The __FILE__ macro can be used to get the path to current test file.
|
# The __FILE__ macro can be used to get the path to current test file.
|
||||||
# Links:
|
# Links:
|
||||||
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
||||||
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
set(TEST_NAME GildedRoseGoogletestUnitTests)
|
if (BUILD_UNIT_TESTS_WITH_GTEST)
|
||||||
add_executable(${TEST_NAME})
|
set(TEST_NAME GildedRoseGoogletestUnitTests)
|
||||||
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestUnitTests.cc)
|
add_executable(${TEST_NAME})
|
||||||
target_link_libraries(${TEST_NAME} GildedRoseLib gtest gtest_main)
|
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestUnitTests.cc)
|
||||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
|
target_link_libraries(${TEST_NAME} GildedRoseLib gtest gtest_main)
|
||||||
add_test(
|
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
|
||||||
|
add_test(
|
||||||
NAME ${TEST_NAME}
|
NAME ${TEST_NAME}
|
||||||
COMMAND ${TEST_NAME}
|
COMMAND ${TEST_NAME}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
||||||
# The __FILE__ macro can be used to get the path to current test file.
|
# The __FILE__ macro can be used to get the path to current test file.
|
||||||
# Links:
|
# Links:
|
||||||
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
||||||
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -4,9 +4,9 @@ target_sources(${TEST_NAME} PRIVATE GildedRoseTextTests.cc)
|
|||||||
target_link_libraries(${TEST_NAME} GildedRoseLib)
|
target_link_libraries(${TEST_NAME} GildedRoseLib)
|
||||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
|
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 11)
|
||||||
add_test(
|
add_test(
|
||||||
NAME ${TEST_NAME}
|
NAME ${TEST_NAME}
|
||||||
COMMAND ${TEST_NAME}
|
COMMAND ${TEST_NAME}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
# Set compiler option /FC for Visual Studio to to make the __FILE__ macro expand to full path.
|
||||||
@ -15,5 +15,5 @@ add_test(
|
|||||||
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
|
||||||
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
# * https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-diagnostics?view=vs-2019
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user