Skip to content

Commit 7169a8d

Browse files
committed
Add test subdirectory
1 parent a5c29d4 commit 7169a8d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ set(CMAKE_AUTORCC ON)
99
set(CMAKE_CXX_STANDARD 17)
1010
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111

12+
option(SCRATCHCPPGUI_BUILD_UNIT_TESTS "Build unit tests" ON)
13+
1214
include(build/FindQt.cmake)
1315

1416
qt_standard_project_setup(REQUIRES 6.6)
@@ -26,3 +28,8 @@ target_link_libraries(libscratchcpp-gui PRIVATE scratchcpp)
2628
add_subdirectory(thirdparty/libqnanopainter)
2729
target_include_directories(libscratchcpp-gui PRIVATE thirdparty/libqnanopainter)
2830
target_link_libraries(libscratchcpp-gui PRIVATE qnanopainter)
31+
32+
if (SCRATCHCPPGUI_BUILD_UNIT_TESTS)
33+
enable_testing()
34+
add_subdirectory(test)
35+
endif()

test/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(libscratchcpp_test)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
add_compile_definitions(DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
7+
8+
set(GTEST_DIR thirdparty/googletest)
9+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../${GTEST_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${GTEST_DIR})
10+
11+
# For Windows: Prevent overriding the parent project's compiler/linker settings
12+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
13+
14+
include(GoogleTest)
15+
16+
function(add_test TARGET)
17+
target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/ScratchCPPGui)
18+
endfunction()

test/common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <gtest/gtest.h>
4+
#include <filesystem>
5+
#include <fstream>
6+
7+
int main(int argc, char **argv)
8+
{
9+
std::filesystem::current_path(DATA_DIR);
10+
::testing::InitGoogleTest(&argc, argv);
11+
return RUN_ALL_TESTS();
12+
}

0 commit comments

Comments
 (0)