diff --git a/CMakeLists.txt b/CMakeLists.txt index 50960c01c..8f92690b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -542,7 +542,6 @@ if(RUN_TESTS) include(GoogleTest) find_package(GTest REQUIRED) target_include_directories(devilutionx-tests PRIVATE ${GTEST_INCLUDE_DIRS}) - add_definitions(-DRUN_TESTS) if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(devilutionx-tests PRIVATE -fprofile-arcs -ftest-coverage) endif() diff --git a/Source/DiabloUI/dialogs.cpp b/Source/DiabloUI/dialogs.cpp index c84f0c830..f83774f39 100644 --- a/Source/DiabloUI/dialogs.cpp +++ b/Source/DiabloUI/dialogs.cpp @@ -266,15 +266,13 @@ void UiOkDialog(const char *text, const char *caption, bool error, const std::ve if (SDL_ShowCursor(SDL_ENABLE) <= -1) { Log("{}", SDL_GetError()); } -#ifndef RUN_TESTS - if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, text, caption, nullptr) <= -1) { - Log("{}", SDL_GetError()); -#else - { -#endif - Log("{}", text); - Log("{}", caption); + if (!gbQuietMode) { + if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, text, caption, nullptr) <= -1) { + Log("{}", SDL_GetError()); + } } + Log("{}", text); + Log("{}", caption); return; } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 1c0d886f9..d22ab6fbc 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -109,6 +109,7 @@ bool forceDiablo; bool gbNestArt; bool gbBard; bool gbBarbarian; +bool gbQuietMode = false; int sgnTimeoutCurs; clicktype sgbMouseDown; int color_cycle_timer; diff --git a/Source/diablo.h b/Source/diablo.h index 519c03a3f..854ddf390 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -44,6 +44,10 @@ extern int PauseMode; extern bool gbNestArt; extern bool gbBard; extern bool gbBarbarian; +/** + * @brief Don't show Messageboxes or other user-interaction. Needed for UnitTests. + */ +extern bool gbQuietMode; extern clicktype sgbMouseDown; extern uint16_t gnTickDelay; extern char gszProductName[64]; diff --git a/test/main.cpp b/test/main.cpp index b4aa7f06d..e3b60271d 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,7 +1,10 @@ #include +#include "diablo.h" + int main(int argc, char **argv) { + devilution::gbQuietMode = true; testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }