mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
CMake: unittest improvements (#447)
* Convert TestConfig to proper test environment. * Copy test data to build directory. * Get test recognized by ctest, but disable gtest discovery. Allowing ctest to run each test individually isn't currently practical because it is 50 times slower.
This commit is contained in:
parent
9da3f48274
commit
ad2c429d8f
@ -302,6 +302,7 @@ if(ENABLE_LAUNCHER)
|
||||
add_subdirectory(launcher)
|
||||
endif()
|
||||
if(ENABLE_TEST)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
enable_testing()
|
||||
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
|
||||
include(GoogleTest)
|
||||
endif()
|
||||
|
||||
set(googleTest_Dir ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
|
||||
if(EXISTS ${googleTest_Dir})
|
||||
@ -98,26 +100,36 @@ add_subdirectory_with_folder("3rdparty" googletest EXCLUDE_FROM_ALL)
|
||||
|
||||
add_executable(vcmitest ${test_SRCS} ${test_HEADERS} ${mock_HEADERS} ${GTestSrc}/src/gtest-all.cc ${GMockSrc}/src/gmock-all.cc)
|
||||
target_link_libraries(vcmitest vcmi ${RT_LIB} ${DL_LIB})
|
||||
add_test(vcmitest vcmitest)
|
||||
|
||||
if(FALSE AND NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
|
||||
# Running tests one by one using ctest not recommended due to vcmi having
|
||||
# slow global initialization.
|
||||
gtest_discover_tests(vcmitest
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
|
||||
else()
|
||||
add_test(NAME tests
|
||||
COMMAND vcmitest
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
|
||||
endif()
|
||||
|
||||
|
||||
vcmi_set_output_dir(vcmitest "")
|
||||
|
||||
set_target_properties(vcmitest PROPERTIES ${PCH_PROPERTIES})
|
||||
cotire(vcmitest)
|
||||
|
||||
# Files to copy to the build directory
|
||||
set(vcmitest_FILES
|
||||
testdata/TerrainViewTest.h3m
|
||||
testdata/terrainViewMappings.json
|
||||
testdata/ObjectPropertyTest/header.json
|
||||
testdata/ObjectPropertyTest/objects.json
|
||||
testdata/ObjectPropertyTest/surface_terrain.json
|
||||
testdata/ObjectPropertyTest/underground_terrain.json
|
||||
)
|
||||
|
||||
foreach(file ${vcmitest_FILES})
|
||||
add_custom_command(TARGET vcmitest POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${file}" ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
file (GLOB_RECURSE testdata "testdata/*.*")
|
||||
foreach(resource ${testdata})
|
||||
get_filename_component(filename ${resource} NAME)
|
||||
get_filename_component(dir ${resource} DIRECTORY)
|
||||
get_filename_component(dirname ${dir} NAME)
|
||||
set (output "")
|
||||
while(NOT ${dirname} STREQUAL testdata)
|
||||
get_filename_component(path_component ${dir} NAME)
|
||||
set (output "${path_component}/${output}")
|
||||
get_filename_component(dir ${dir} DIRECTORY)
|
||||
get_filename_component(dirname ${dir} NAME)
|
||||
endwhile()
|
||||
set(output "${CMAKE_BINARY_DIR}/bin/test/testdata/${output}/${filename}")
|
||||
configure_file(${resource} ${output} COPYONLY)
|
||||
endforeach()
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "../lib/filesystem/CFilesystemLoader.h"
|
||||
#include "../lib/filesystem/AdapterLoaders.h"
|
||||
|
||||
CVcmiTestConfig::CVcmiTestConfig()
|
||||
void CVcmiTestConfig::SetUp()
|
||||
{
|
||||
console = new CConsoleHandler();
|
||||
preinitDLL(console, true);
|
||||
@ -39,7 +39,7 @@ CVcmiTestConfig::CVcmiTestConfig()
|
||||
}
|
||||
}
|
||||
|
||||
CVcmiTestConfig::~CVcmiTestConfig()
|
||||
void CVcmiTestConfig::TearDown()
|
||||
{
|
||||
std::cout << "Ending global test tear-down." << std::endl;
|
||||
}
|
||||
|
@ -9,10 +9,12 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "StdInc.h"
|
||||
|
||||
/// Global setup/tear down class for unit tests.
|
||||
class CVcmiTestConfig
|
||||
class CVcmiTestConfig : public ::testing::Environment
|
||||
{
|
||||
public:
|
||||
CVcmiTestConfig();
|
||||
~CVcmiTestConfig();
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
};
|
||||
|
@ -15,6 +15,6 @@
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
CVcmiTestConfig test;
|
||||
::testing::AddGlobalTestEnvironment(new CVcmiTestConfig());
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user