Skip to content

Commit 62800aa

Browse files
committed
add test integration
1 parent 63c5fcc commit 62800aa

File tree

10 files changed

+50
-9
lines changed

10 files changed

+50
-9
lines changed

.clangd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ InlayHints:
2222

2323
Diagnostics:
2424
UnusedIncludes: Strict
25-
MissingIncludes: Strict
25+
MissingIncludes: None
2626

2727
---
2828

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ project(
88
LANGUAGES CXX
99
)
1010

11+
if(FEATURE_TESTS)
12+
enable_testing()
13+
endif()
14+
1115
add_subdirectory(library)
1216
add_subdirectory(app)

CMakePresets.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@
108108
"name": "debug",
109109
"hidden": true,
110110
"cacheVariables": {
111-
"CMAKE_BUILD_TYPE": "Debug"
111+
"CMAKE_BUILD_TYPE": "Debug",
112+
"VCPKG_MANIFEST_FEATURES": "test",
113+
"FEATURE_TESTS": true
112114
}
113115
},
114116
{

app/App.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <Core/Lib.hpp>
22

3+
#include <iostream>
4+
35
int main()
46
{
57
Lib lib;
6-
lib.displayName();
8+
std::cout << lib.getName();
79

810
return 0;
911
}

library/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ add_library(Core STATIC ${LIBRARY_HEADERS} ${LIBRARY_SOURCES})
1515
target_include_directories(Core PUBLIC ${PROJECT_SOURCE_DIR}/library/include)
1616
target_compile_features(Core PUBLIC cxx_std_17)
1717

18+
if (FEATURE_TESTS)
19+
add_subdirectory(${PROJECT_SOURCE_DIR}/library/test)
20+
endif()
21+
1822
# Group headers and sources for IDE
1923
source_group(TREE ${INCROOT} PREFIX "Headers" FILES ${LIBRARY_HEADERS})
2024
source_group(TREE ${SRCROOT} PREFIX "Sources" FILES ${LIBRARY_SOURCES})

library/include/Core/Lib.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct Lib
66
{
77
Lib();
88

9-
void displayName() const;
9+
std::string getName() const;
1010

1111
private:
1212
std::string m_name;

library/src/Core/Lib.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#include <Core/Lib.hpp>
22

3-
#include <iostream>
4-
53
Lib::Lib() :
64
m_name { "Library" }
75
{
86
}
97

10-
void Lib::displayName() const
8+
std::string Lib::getName() const
119
{
12-
std::cout << m_name;
10+
return m_name;
1311
}

library/test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include(CTest)
2+
3+
find_package(Catch2 REQUIRED)
4+
include(Catch)
5+
6+
add_executable(CoreTests ${PROJECT_SOURCE_DIR}/library/test/Tests.cpp)
7+
8+
target_link_libraries(CoreTests PRIVATE Core Catch2::Catch2WithMain)
9+
target_compile_features(CoreTests PRIVATE cxx_std_17)
10+
catch_discover_tests(CoreTests)

library/test/Tests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <Core/Lib.hpp>
2+
3+
#include <catch2/catch_test_macros.hpp>
4+
5+
TEST_CASE("some_fun")
6+
{
7+
Lib lib;
8+
REQUIRE(lib.getName() == "Library");
9+
}

vcpkg.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,17 @@
44
"version-string": "0.1.0",
55
"dependencies": [
66

7-
]
7+
],
8+
"default-features": [],
9+
"features": {
10+
"test": {
11+
"description": "Dependencies for testing",
12+
"dependencies": [
13+
{
14+
"name": "catch2",
15+
"version>=": "3.5.2"
16+
}
17+
]
18+
}
19+
}
820
}

0 commit comments

Comments
 (0)