make unit tests available in all debug builds

This commit is contained in:
Wengier 2021-11-23 06:09:22 -05:00
parent 8a3b5b7367
commit baaebd367b
9 changed files with 41 additions and 92 deletions

View File

@ -9854,7 +9854,7 @@ bool DOSBOX_parse_argv() {
control->opt_nomenu = true;
control->opt_fastlaunch = true;
}
#ifdef _MSC_VER
#if C_DEBUG
else if (optname == "tests" || optname == "gtest_list_tests") {
putenv(const_cast<char*>("SDL_VIDEODRIVER=dummy"));
control->opt_test = true;
@ -15141,7 +15141,9 @@ fresh_boot:
dos_kernel_shutdown = false;
guest_msdos_mcb_chain = (uint16_t)(~0u);
#if C_DEBUG
if (control->opt_test) ::testing::InitGoogleTest(&argc, argv);
#endif
/* NTS: CPU reset handler, and BIOS init, has the instruction pointer poised to run through BIOS initialization,
* which will then "boot" into the DOSBox-X kernel, and then the shell, by calling VM_Boot_DOSBox_Kernel() */

View File

@ -482,4 +482,3 @@ void E_Exit(const char * format,...) {
}
exit(0);
}

View File

@ -39,6 +39,7 @@
#include "jfont.h"
#include "../dos/drives.h"
#include "../ints/int10.h"
#include "../../tests/tests.h"
#include <unistd.h>
#include <time.h>
#include <string>
@ -1843,7 +1844,7 @@ void SHELL_Run() {
first_shell->WriteOut(MSG_Get("SHELL_MISSING_FILE"), name);
}
}
#if C_DEBUG
if (control->opt_test) {
RUN_ALL_TESTS();
#if defined(WIN32)
@ -1851,6 +1852,7 @@ void SHELL_Run() {
#endif
return;
}
#endif
i4dos=false;
if (altshell) {
if (strstr(name, "4DOS.COM")) i4dos=true;

View File

@ -18,22 +18,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* This sample shows how to write a simple unit test for dosbox-staging using
* Google C++ testing framework.
*
* Read Google Test Primer for reference of most available features, macros,
* and guidance about writing unit tests:
*
* https://github.com/google/googletest/blob/master/googletest/docs/primer.md#googletest-primer
*/
/* Include necessary header files; order of headers should be as follows:
*
* 1. Header declaring functions/classes being tested
* 2. <gtest/gtest.h>, which declares the testing framework
* 3. Additional system headers (if needed)
* 4. Additional dosbox-staging headers (if needed)
*/
#if C_DEBUG
#include "../src/dos/drives.h"
@ -163,3 +148,4 @@ TEST(Set_Label, InvalidCharsEndingDotCD)
}
} // namespace
#endif

9
tests/readme.txt Normal file
View File

@ -0,0 +1,9 @@
Source files in this subdirectory contain unit tests.
They use GTest and GMock for running unit testing.
Unit tests can be launched with "dosbox-x -tests".
Free free to add more unit tests in this directory.
Read Google Test Primer for reference of most available
features, macros, and guidance about writing unit tests:
https://google.github.io/googletest/primer.html

View File

@ -18,22 +18,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* This sample shows how to write a simple unit test for dosbox-staging using
* Google C++ testing framework.
*
* Read Google Test Primer for reference of most available features, macros,
* and guidance about writing unit tests:
*
* https://github.com/google/googletest/blob/master/googletest/docs/primer.md#googletest-primer
*/
/* Include necessary header files; order of headers should be as follows:
*
* 1. Header declaring functions/classes being tested
* 2. <gtest/gtest.h>, which declares the testing framework
* 3. Additional system headers (if needed)
* 4. Additional dosbox-staging headers (if needed)
*/
#if C_DEBUG
#include "shell.h"
@ -190,3 +175,4 @@ TEST_F(DOS_Shell_CMDSTest, CMD_ECHO_space_handling)
}
} // namespace
#endif

22
tests/tests.h Normal file
View File

@ -0,0 +1,22 @@
#if C_DEBUG
// The following includes necessary GTest/GMock source files for unit tests.
// Launch DOSBox-X with -tests option in debug builds to run unit tests.
#include "../../tests/gmock/gmock-cardinalities.cc"
#include "../../tests/gmock/gmock-internal-utils.cc"
#include "../../tests/gmock/gmock-spec-builders.cc"
#include "../../tests/gmock/gmock.cc"
#include "../../tests/gtest/gtest-death-test.cc"
#include "../../tests/gtest/gtest-filepath.cc"
#include "../../tests/gtest/gtest-port.cc"
#include "../../tests/gtest/gtest-printers.cc"
#include "../../tests/gtest/gtest-test-part.cc"
#include "../../tests/gtest/gtest.cc"
// The following are source files containing unit tests.
#include "../../tests/drives_tests.cpp"
#include "../../tests/shell_cmds_tests.cpp"
#endif // DEBUG

View File

@ -1367,18 +1367,6 @@ copy "$(SolutionDir)\..\contrib\windows\shaders\*.*" "$(OutputPath)\shaders\"</C
<ClCompile Include="..\src\libs\fluidsynth\fluid_ringbuffer.c" />
<ClCompile Include="..\src\libs\fluidsynth\fluid_settings.c" />
<ClCompile Include="..\src\libs\fluidsynth\fluid_sys.c" />
<ClCompile Include="..\tests\drives_tests.cpp" />
<ClCompile Include="..\tests\shell_cmds_tests.cpp" />
<ClCompile Include="..\tests\gmock\gmock-cardinalities.cc" />
<ClCompile Include="..\tests\gmock\gmock-internal-utils.cc" />
<ClCompile Include="..\tests\gmock\gmock-spec-builders.cc" />
<ClCompile Include="..\tests\gmock\gmock.cc" />
<ClCompile Include="..\tests\gtest\gtest-death-test.cc" />
<ClCompile Include="..\tests\gtest\gtest-filepath.cc" />
<ClCompile Include="..\tests\gtest\gtest-port.cc" />
<ClCompile Include="..\tests\gtest\gtest-printers.cc" />
<ClCompile Include="..\tests\gtest\gtest-test-part.cc" />
<ClCompile Include="..\tests\gtest\gtest.cc" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\src\winres.rc" />

View File

@ -127,15 +127,6 @@
<Filter Include="Sources\hardware\RetroWaveLib">
<UniqueIdentifier>{2a582629-0964-4559-9992-810e70c2f6ce}</UniqueIdentifier>
</Filter>
<Filter Include="tests">
<UniqueIdentifier>{a94f678b-7e8c-4167-b529-88e333f4eee9}</UniqueIdentifier>
</Filter>
<Filter Include="tests\gtest">
<UniqueIdentifier>{8918f1db-46a7-4ce3-9591-a99ab10c9832}</UniqueIdentifier>
</Filter>
<Filter Include="tests\gmock">
<UniqueIdentifier>{b063c4e7-b3ff-4324-bb7e-0b0cee524642}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\aviwriter\avi_rw_iobuf.cpp">
@ -1575,42 +1566,6 @@
<ClCompile Include="..\src\ints\int_dosv.cpp">
<Filter>Sources\ints</Filter>
</ClCompile>
<ClCompile Include="..\tests\drives_tests.cpp">
<Filter>tests</Filter>
</ClCompile>
<ClCompile Include="..\tests\shell_cmds_tests.cpp">
<Filter>tests</Filter>
</ClCompile>
<ClCompile Include="..\tests\gtest\gtest.cc">
<Filter>tests\gtest</Filter>
</ClCompile>
<ClCompile Include="..\tests\gtest\gtest-port.cc">
<Filter>tests\gtest</Filter>
</ClCompile>
<ClCompile Include="..\tests\gtest\gtest-filepath.cc">
<Filter>tests\gtest</Filter>
</ClCompile>
<ClCompile Include="..\tests\gtest\gtest-printers.cc">
<Filter>tests\gtest</Filter>
</ClCompile>
<ClCompile Include="..\tests\gtest\gtest-test-part.cc">
<Filter>tests\gtest</Filter>
</ClCompile>
<ClCompile Include="..\tests\gtest\gtest-death-test.cc">
<Filter>tests\gtest</Filter>
</ClCompile>
<ClCompile Include="..\tests\gmock\gmock-spec-builders.cc">
<Filter>tests\gmock</Filter>
</ClCompile>
<ClCompile Include="..\tests\gmock\gmock.cc">
<Filter>tests\gmock</Filter>
</ClCompile>
<ClCompile Include="..\tests\gmock\gmock-cardinalities.cc">
<Filter>tests\gmock</Filter>
</ClCompile>
<ClCompile Include="..\tests\gmock\gmock-internal-utils.cc">
<Filter>tests\gmock</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\aviwriter\avi.h">