mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-15 02:25:40 +00:00
Refactor C++ version of the Gilded Rose kata
* Make it possible to build and run tests in CLion
and Visual Studio 2019 out of the box
* Provide four types of initial test using different test frameworks:
* Catch2 test framework
* Traditional unit testing using Catch2
* Approval test using Catch2
* Google Test test framework
* Traditional unit testing using Google Test
* Approval test using Google Test
* The different types of initial test are located in separate folders
in the test folder.
* Remove scripts to build and run tests and replace
with instructions in the cpp README.md
* Use C++17
* Use CMake => 3.13
This commit is contained in:
1 parent
16dd174765
commit
1836cca836
30 files changed
+20786
-287
No files matched your search
@@ -0,0 +1,4 @@
|
||||
add_subdirectory(cpp_catch2_approvaltest)
|
||||
add_subdirectory(cpp_catch2_unittest)
|
||||
add_subdirectory(cpp_googletest_approvaltest)
|
||||
add_subdirectory(cpp_googletest_unittest)
|
||||
@@ -0,0 +1,15 @@
|
||||
set(TEST_NAME GildedRoseCatch2ApprovalTests)
|
||||
add_executable(${TEST_NAME})
|
||||
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2ApprovalTests.cc)
|
||||
target_link_libraries(${TEST_NAME} lib src)
|
||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 17)
|
||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||
|
||||
# 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.
|
||||
# Links:
|
||||
# * 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
|
||||
if (MSVC)
|
||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||
endif()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
(Foo, 1, 1) => name: Foo, sellIn: 0, quality: 0
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#define APPROVALS_CATCH
|
||||
#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;
|
||||
}
|
||||
|
||||
TEST_CASE("GildedRoseApprovalTests", "VerifyCombinations")
|
||||
{
|
||||
std::vector<string> names { "Foo" };
|
||||
std::vector<int> sellIns { 1 };
|
||||
std::vector<int> qualities { 1 };
|
||||
|
||||
auto f = [](string name, int sellIn, int quality) {
|
||||
vector<Item> items = {Item(name, sellIn, quality)};
|
||||
GildedRose app(items);
|
||||
app.updateQuality();
|
||||
return items[0];
|
||||
};
|
||||
|
||||
ApprovalTests::CombinationApprovals::verifyAllCombinations(
|
||||
f,
|
||||
names, sellIns, qualities);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
set(TEST_NAME GildedRoseCatch2UnitTests)
|
||||
add_executable(${TEST_NAME})
|
||||
target_sources(${TEST_NAME} PRIVATE GildedRoseCatch2UnitTests.cc)
|
||||
target_link_libraries(${TEST_NAME} lib src)
|
||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 17)
|
||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||
|
||||
# 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.
|
||||
# Links:
|
||||
# * 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
|
||||
if (MSVC)
|
||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||
endif()
|
||||
@@ -0,0 +1,12 @@
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "Catch.hpp"
|
||||
#include "GildedRose.h"
|
||||
|
||||
TEST_CASE("GildedRoseUnitTest", "Foo")
|
||||
{
|
||||
vector<Item> items;
|
||||
items.push_back(Item("Foo", 0, 0));
|
||||
GildedRose app(items);
|
||||
app.updateQuality();
|
||||
REQUIRE("fixme" == app.items[0].name);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
set(TEST_NAME GildedRoseGoogletestApprovalTests)
|
||||
add_executable(${TEST_NAME})
|
||||
target_sources(${TEST_NAME} PRIVATE googletest_approval_main.cc GildedRoseGoogletestApprovalTests.cc)
|
||||
target_link_libraries(${TEST_NAME} lib src gtest)
|
||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 17)
|
||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||
|
||||
# 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.
|
||||
# Links:
|
||||
# * 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
|
||||
if (MSVC)
|
||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||
endif()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
(Foo, 1, 1) => name: Foo, sellIn: 0, quality: 0
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Include header files for test frameworks
|
||||
#include <gtest/gtest.h>
|
||||
#include <ApprovalTests.hpp>
|
||||
|
||||
// Include code to be tested
|
||||
#include "GildedRose.h"
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Item& obj)
|
||||
{
|
||||
return os
|
||||
<< "name: " << obj.name
|
||||
<< ", sellIn: " << obj.sellIn
|
||||
<< ", quality: " << obj.quality;
|
||||
}
|
||||
|
||||
TEST(GildedRoseApprovalTests, VerifyCombinations) {
|
||||
|
||||
std::vector<string> names { "Foo" };
|
||||
std::vector<int> sellIns { 1 };
|
||||
std::vector<int> qualities { 1 };
|
||||
|
||||
auto f = [](string name, int sellIn, int quality) {
|
||||
vector<Item> items = {Item(name, sellIn, quality)};
|
||||
GildedRose app(items);
|
||||
app.updateQuality();
|
||||
return items[0];
|
||||
};
|
||||
|
||||
ApprovalTests::CombinationApprovals::verifyAllCombinations(
|
||||
f,
|
||||
names, sellIns, qualities);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#define APPROVALS_GOOGLETEST // This tells Approval Tests to provide a main() - only do this in one cpp file
|
||||
#include "ApprovalTests.hpp"
|
||||
@@ -0,0 +1,15 @@
|
||||
set(TEST_NAME GildedRoseGoogletestUnitTests)
|
||||
add_executable(${TEST_NAME})
|
||||
target_sources(${TEST_NAME} PRIVATE GildedRoseGoogletestUnitTests.cc)
|
||||
target_link_libraries(${TEST_NAME} src gtest gtest_main)
|
||||
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 17)
|
||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||
|
||||
# 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.
|
||||
# Links:
|
||||
# * 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
|
||||
if (MSVC)
|
||||
target_compile_options(${TEST_NAME} PRIVATE "/FC")
|
||||
endif()
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "GildedRose.h"
|
||||
|
||||
TEST(GildedRoseTest, Foo) {
|
||||
vector<Item> items;
|
||||
items.push_back(Item("Foo", 0, 0));
|
||||
GildedRose app(items);
|
||||
app.updateQuality();
|
||||
EXPECT_EQ("fixme", app.items[0].name);
|
||||
}
|
||||
Reference in new issue
Block a user