UnitTests: Add custom main that calls RegisterMsgAlertHandler

This prevents a failed assertion from hanging on the MSVC buildbots.
This commit is contained in:
Pokechu22 2023-01-12 13:28:42 -08:00
parent f4f94396e9
commit 92b6446da1
3 changed files with 34 additions and 2 deletions

View File

@ -4,6 +4,8 @@ add_custom_command(TARGET unittests POST_BUILD COMMAND ${CMAKE_CTEST_COMMAND})
string(APPEND CMAKE_RUNTIME_OUTPUT_DIRECTORY "/Tests")
add_library(unittests_main OBJECT UnitTestsMain.cpp)
target_link_libraries(unittests_main PUBLIC fmt gtest)
# Since this is a Core dependency, it can't be linked as a normal library.
# Otherwise CMake inserts the library after core, but before other core
# dependencies like videocommon which also use Host_ functions, which makes the
@ -16,7 +18,7 @@ macro(add_dolphin_test target)
$<TARGET_OBJECTS:unittests_stubhost>
)
set_target_properties(${target} PROPERTIES FOLDER Tests)
target_link_libraries(${target} PRIVATE core uicommon gtest_main)
target_link_libraries(${target} PRIVATE core uicommon unittests_main)
add_dependencies(unittests ${target})
add_test(NAME ${target} COMMAND ${target})
endmacro()

View File

@ -36,8 +36,8 @@
<ItemGroup>
<!--gtest is rather small, so just include it into the build here-->
<ClCompile Include="$(ExternalsDir)gtest\src\gtest-all.cc" />
<ClCompile Include="$(ExternalsDir)gtest\src\gtest_main.cc" />
<!--Lump all of the tests (and supporting code) into one binary-->
<ClCompile Include="UnitTestsMain.cpp" />
<ClCompile Include="Common\BitFieldTest.cpp" />
<ClCompile Include="Common\BitSetTest.cpp" />
<ClCompile Include="Common\BitUtilsTest.cpp" />

View File

@ -0,0 +1,30 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Based on gtest_main.cc
#include <cstdio>
#include <fmt/format.h>
#include "Common/MsgHandler.h"
#include "gtest/gtest.h"
namespace
{
bool TestMsgHandler(const char* caption, const char* text, bool yes_no, Common::MsgType style)
{
fmt::print(stderr, "{}\n", text);
ADD_FAILURE();
// Return yes to any question (we don't need Dolphin to break on asserts)
return true;
}
} // namespace
int main(int argc, char** argv)
{
fmt::print(stderr, "Running main() from UnitTestsMain.cpp\n");
Common::RegisterMsgAlertHandler(TestMsgHandler);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}