Skip to content

Commit c9038a2

Browse files
authored
Merge pull request #1 from emrekovanci/feature-tests
Feature tests
2 parents 63c5fcc + 8c14a72 commit c9038a2

File tree

13 files changed

+215
-27
lines changed

13 files changed

+215
-27
lines changed

.clang-format

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ MaxEmptyLinesToKeep: 1
7878
# Sorting
7979
IncludeBlocks: Regroup
8080
IncludeCategories:
81-
# "Header.h", "Header.hpp" etc.
81+
# Test headers
8282
- Priority: 1
83+
Regex: '<(catch2|gtest).*>'
84+
# "Header.h", "Header.hpp" etc.
85+
- Priority: 2
8386
Regex: '^\"(.+)\"$'
8487
# Core Library
85-
- Priority: 2
88+
- Priority: 3
8689
Regex: '^<Core\/'
8790
# C++ standard headers
88-
- Priority: 3
91+
- Priority: 4
8992
Regex: '<[[:alnum:]_-]+>'
9093
SortIncludes: true
9194
SortUsingDeclarations: true

.clangd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ CompileFlags:
44
Add:
55
- "-ferror-limit=0"
66

7-
Remove:
8-
- "-mabi"
9-
107
# if you are using VSCode and CMake Tools(provided by Microsoft) add
118
# "cmake.copyCompileCommands": "${workspaceFolder}/.vscode/compile_commands.json" to VSCode settings
129
# because CompilationDatabase field in .clangd doesn't support multiple folders to search
@@ -22,7 +19,7 @@ InlayHints:
2219

2320
Diagnostics:
2421
UnusedIncludes: Strict
25-
MissingIncludes: Strict
22+
MissingIncludes: None
2623

2724
---
2825

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ jobs:
7272
else
7373
cmake --build --preset=${{ matrix.compiler }}-${{ matrix.build_type }}
7474
fi
75+
- name: Test
76+
if: ${{ matrix.build_type == 'Debug' }}
77+
shell: bash
78+
run: |
79+
if [ "${{ runner.os }}" == "Windows" ]; then
80+
ctest --preset=test-Windows-${{ matrix.compiler }}-${{ matrix.build_type }}
81+
else
82+
ctest --preset=test-${{ matrix.compiler }}-${{ matrix.build_type }}
83+
fi
7584
7685
format:
7786
name: Formatting

CMakeLists.txt

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

11+
if(FEATURE_TESTS)
12+
enable_testing()
13+
find_package(Catch2 REQUIRED)
14+
endif()
15+
1116
add_subdirectory(library)
1217
add_subdirectory(app)
18+
19+
set(CPACK_PACKAGE_FILE_NAME
20+
"${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}"
21+
)
22+
include(CPack)

CMakePresets.json

Lines changed: 145 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"value": "x64",
3434
"strategy": "external"
3535
},
36-
"toolset":{
36+
"toolset": {
3737
"value": "host=x64",
3838
"strategy": "external"
3939
}
@@ -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": "tests",
113+
"FEATURE_TESTS": true
112114
}
113115
},
114116
{
@@ -120,52 +122,84 @@
120122
},
121123
{
122124
"name": "Windows-msvc-Debug",
123-
"inherits": ["confs-windows-msvc-common", "debug"]
125+
"displayName": "win-msvc-debug",
126+
"inherits": [
127+
"confs-windows-msvc-common",
128+
"debug"
129+
]
124130
},
125131
{
126132
"name": "Windows-msvc-Release",
127-
"inherits": ["confs-windows-msvc-common", "release"]
133+
"displayName": "win-msvc-release",
134+
"inherits": [
135+
"confs-windows-msvc-common",
136+
"release"
137+
]
128138
},
129139
{
130140
"name": "Windows-llvm-Debug",
131-
"inherits": ["confs-windows-llvm-common", "debug"]
141+
"displayName": "win-llvm-debug",
142+
"inherits": [
143+
"confs-windows-llvm-common",
144+
"debug"
145+
]
132146
},
133147
{
134148
"name": "Windows-llvm-Release",
135-
"inherits": ["confs-windows-llvm-common", "release"]
149+
"displayName": "win-llvm-release",
150+
"inherits": [
151+
"confs-windows-llvm-common",
152+
"release"
153+
]
136154
},
137155
{
138156
"name": "llvm-Debug",
139-
"inherits": ["confs-linux-llvm-common", "debug"]
157+
"inherits": [
158+
"confs-linux-llvm-common",
159+
"debug"
160+
]
140161
},
141162
{
142163
"name": "llvm-Release",
143-
"inherits": ["confs-linux-llvm-common", "release"]
164+
"inherits": [
165+
"confs-linux-llvm-common",
166+
"release"
167+
]
144168
},
145169
{
146170
"name": "gcc-Debug",
147-
"inherits": ["confs-linux-gcc-common", "debug"]
171+
"inherits": [
172+
"confs-linux-gcc-common",
173+
"debug"
174+
]
148175
},
149176
{
150177
"name": "gcc-Release",
151-
"inherits": ["confs-linux-gcc-common", "release"]
178+
"inherits": [
179+
"confs-linux-gcc-common",
180+
"release"
181+
]
152182
}
153183
],
154184
"buildPresets": [
155185
{
156186
"name": "Windows-msvc-Debug",
187+
"displayName": "win-msvc-debug",
157188
"configurePreset": "Windows-msvc-Debug"
158189
},
159190
{
160191
"name": "Windows-msvc-Release",
192+
"displayName": "win-msvc-release",
161193
"configurePreset": "Windows-msvc-Release"
162194
},
163195
{
164196
"name": "Windows-llvm-Debug",
197+
"displayName": "win-llvm-debug",
165198
"configurePreset": "Windows-llvm-Debug"
166199
},
167200
{
168201
"name": "Windows-llvm-Release",
202+
"displayName": "win-llvm-release",
169203
"configurePreset": "Windows-llvm-Release"
170204
},
171205
{
@@ -184,5 +218,106 @@
184218
"name": "gcc-Release",
185219
"configurePreset": "gcc-Release"
186220
}
221+
],
222+
"testPresets": [
223+
{
224+
"name": "test-common",
225+
"hidden": true,
226+
"output": {
227+
"outputOnFailure": true
228+
},
229+
"execution": {
230+
"noTestsAction": "error",
231+
"stopOnFailure": true
232+
}
233+
},
234+
{
235+
"name": "test-Windows-msvc-Debug",
236+
"displayName": "test-win-msvc-debug",
237+
"inherits": "test-common",
238+
"configurePreset": "Windows-msvc-Debug"
239+
},
240+
{
241+
"name": "test-Windows-llvm-Debug",
242+
"displayName": "test-win-llvm-debug",
243+
"inherits": "test-common",
244+
"configurePreset": "Windows-llvm-Debug"
245+
},
246+
{
247+
"name": "test-llvm-Debug",
248+
"displayName": "test-llvm-debug",
249+
"inherits": "test-common",
250+
"configurePreset": "llvm-Debug"
251+
},
252+
{
253+
"name": "test-gcc-Debug",
254+
"displayName": "test-gcc-debug",
255+
"inherits": "test-common",
256+
"configurePreset": "gcc-Debug"
257+
}
258+
],
259+
"packagePresets": [
260+
{
261+
"name": "package-Windows-msvc-Debug",
262+
"displayName": "pkg-windows-msvc-debug",
263+
"configurePreset": "Windows-msvc-Debug",
264+
"generators": [
265+
"TGZ"
266+
]
267+
},
268+
{
269+
"name": "package-Windows-llvm-Debug",
270+
"displayName": "pkg-windows-llvm-debug",
271+
"configurePreset": "Windows-llvm-Debug",
272+
"generators": [
273+
"TGZ"
274+
]
275+
}
276+
],
277+
"workflowPresets": [
278+
{
279+
"name": "Windows-msvc-Debug",
280+
"displayName": "win-msvc-debug",
281+
"steps": [
282+
{
283+
"type": "configure",
284+
"name": "Windows-msvc-Debug"
285+
},
286+
{
287+
"type": "build",
288+
"name": "Windows-msvc-Debug"
289+
},
290+
{
291+
"type": "test",
292+
"name": "test-Windows-msvc-Debug"
293+
},
294+
{
295+
"type": "package",
296+
"name": "package-Windows-msvc-Debug"
297+
}
298+
]
299+
},
300+
{
301+
"name": "Windows-llvm-Debug",
302+
"displayName": "win-llvm-debug",
303+
"steps": [
304+
{
305+
"type": "configure",
306+
"name": "Windows-llvm-Debug"
307+
},
308+
{
309+
"type": "build",
310+
"name": "Windows-llvm-Debug"
311+
},
312+
{
313+
"type": "test",
314+
"name": "test-Windows-llvm-Debug"
315+
},
316+
{
317+
"type": "package",
318+
"name": "package-Windows-llvm-Debug"
319+
}
320+
]
321+
}
187322
]
188323
}

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
}

app/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Define executable and its properties
2-
add_executable(${PROJECT_NAME} App.cpp)
3-
target_link_libraries(${PROJECT_NAME} PRIVATE Core)
4-
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})
2+
add_executable(Application App.cpp)
3+
target_link_libraries(Application PRIVATE Core)
4+
set_target_properties(Application PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Application)
5+
install(TARGETS Application)

library/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ set(LIBRARY_SOURCES
1414
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)
17+
install(TARGETS Core)
18+
19+
if (FEATURE_TESTS)
20+
add_subdirectory(${PROJECT_SOURCE_DIR}/library/test)
21+
endif()
1722

1823
# Group headers and sources for IDE
1924
source_group(TREE ${INCROOT} PREFIX "Headers" FILES ${LIBRARY_HEADERS})

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
}

0 commit comments

Comments
 (0)