From 85475093ea3afc3c59420f38c293fd6198a527a3 Mon Sep 17 00:00:00 2001 From: simonmicro Date: Thu, 21 Sep 2023 16:24:53 +0200 Subject: [PATCH] Added ability to pass-trough arguments to the unit-test-gramework directly (used for e.g. --filter) --- emulator/src/main.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/emulator/src/main.cpp b/emulator/src/main.cpp index 97350284c..12125505c 100644 --- a/emulator/src/main.cpp +++ b/emulator/src/main.cpp @@ -23,38 +23,28 @@ int main(int argc, char** argv) { // Parse command line arguments cmdline::parser a; const std::string argRunUnitTests = "unit_tests"; - const std::string argListAllTests = "list_tests"; const std::string argUiTests = "ui_tests"; - a.add(argRunUnitTests, '\0', "run the unit test framework"); - a.add(argListAllTests, '\0', "list all unit and UI tests, one per line"); + a.add(argRunUnitTests, '\0', "run the unit test framework (if you have any arguments for it (use it with --help to learn more), just pass them AS THE LAST ONES)"); a.add(argUiTests, '\0', "run emulator with UI tests window"); a.add("headless", '\0', "do not open a window; use software-rendering only"); // Warning: This parameter name is also used in the unit-tests! - a.parse_check(argc, argv); + bool cmdParsed = a.parse(argc, argv); + if(!cmdParsed) { + if(a.exist(argRunUnitTests) or a.exist(argUiTests)) { + // unable to fully parse command line, but I'll ignore that and pass the arguments to the test framework... + } else { + a.parse_check(argc, argv); // this will not only re-parse, but also bail out + } + } // Initialize SDL if (SDL_Init(SDL_INIT_EVERYTHING) != 0) - printf("error initializing SDL: %s\n", SDL_GetError()); + std::cerr << "Error initializing SDL: " << SDL_GetError() << std::endl; // Run the unit tests or the emulator int returnval = EXIT_SUCCESS; if (a.exist(argRunUnitTests)) { // In this mode we won't enter the emulator itself, but instead just run the unit tests returnval = utest_main(argc, argv); - } else if (a.exist(argListAllTests)) { - // Change --list_tests to --list-tests, because utest expects --list-tests - for (int i = 0; i < strlen(argv[1]); i++) { - if (argv[1][i] == '_') { - argv[1][i] = '-'; - break; - } - } - std::cout << "Unit tests:" << std::endl << std::endl; - returnval = utest_main(argc, argv); - std::cout << std::endl << "-------------------" << std::endl << std::endl; - - // returnval here is useless, since UiTests_main always returns 0 - std::cout << "UI tests:" << std::endl << std::endl; - UiTests_main(UiTests_Mode::List); } else if (a.exist(argUiTests)) { // Run the emulator together with the testing engine returnval = UiTests_main();