25
25
#include < iostream>
26
26
#include < regex>
27
27
28
- #ifdef WIN32
28
+ #ifdef _WIN32
29
29
#include < Windows.h>
30
30
#include < conio.h>
31
31
#else
45
45
46
46
static void print_help ()
47
47
{
48
- std::cout << " Usage: testrunner.exe <test_binaries> [/list] [/listproperties] [/noignore] [/breakonerror]" <<std::endl;
48
+ std::cout << " Usage: testrunner.exe <test_binaries> [/list] [/listproperties] [/noignore] [/breakonerror] [/detectleaks] " <<std::endl;
49
49
std::cout << " [/name:<test_name>] [/select:@key=value] [/loop:<num_times>]" << std::endl;
50
50
std::cout << std::endl;
51
51
std::cout << " /list List all the names of the test_binaries and their" << std::endl;
@@ -55,6 +55,7 @@ static void print_help()
55
55
std::cout << " test properties." << std::endl;
56
56
std::cout << std::endl;
57
57
std::cout << " /breakonerror Break into the debugger when a failure is encountered." << std::endl;
58
+ std::cout << " /detectleaks Turns CRT leak detection and prints any leaks, Windows only." << std::endl;
58
59
std::cout << std::endl;
59
60
std::cout << " /name:<test_name> Run only test cases with matching name. Can contain the" << std::endl;
60
61
std::cout << " wildcard '*' character." << std::endl;
@@ -84,7 +85,7 @@ static std::vector<std::string> get_files_in_directory()
84
85
{
85
86
std::vector<std::string> files;
86
87
87
- #ifdef WIN32
88
+ #ifdef _WIN32
88
89
89
90
char exe_directory_buffer[MAX_PATH];
90
91
GetModuleFileNameA (NULL , exe_directory_buffer, MAX_PATH);
@@ -347,7 +348,7 @@ static void handle_list_option(bool listProperties, const UnitTest::TestList &te
347
348
348
349
static void ChangeConsoleTextColorToRed ()
349
350
{
350
- #ifdef WIN32
351
+ #ifdef _WIN32
351
352
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), 0x0004 | 0x0008 );
352
353
#else
353
354
std::cout << " \033 [1;31m" ;
@@ -356,7 +357,7 @@ static void ChangeConsoleTextColorToRed()
356
357
357
358
static void ChangeConsoleTextColorToGreen ()
358
359
{
359
- #ifdef WIN32
360
+ #ifdef _WIN32
360
361
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), 0x0002 | 0x0008 );
361
362
#else
362
363
std::cout << " \033 [1;32m" ;
@@ -365,7 +366,7 @@ static void ChangeConsoleTextColorToGreen()
365
366
366
367
static void ChangeConsoleTextColorToGrey ()
367
368
{
368
- #ifdef WIN32
369
+ #ifdef _WIN32
369
370
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
370
371
#else
371
372
std::cout << " \033 [0m" ;
@@ -375,7 +376,7 @@ static void ChangeConsoleTextColorToGrey()
375
376
bool IsTestIgnored (UnitTest::Test *pTest)
376
377
{
377
378
if (pTest->m_properties .Has (" Ignore" )) return true ;
378
- #ifdef WIN32
379
+ #ifdef _WIN32
379
380
if (pTest->m_properties .Has (" Ignore:Windows" )) return true ;
380
381
#elif defined(__APPLE__)
381
382
if (pTest->m_properties .Has (" Ignore:Apple" )) return true ;
@@ -387,24 +388,6 @@ bool IsTestIgnored(UnitTest::Test *pTest)
387
388
return false ;
388
389
}
389
390
390
- //
391
- // These are to handle cases where an exception or assert occurs on a thread
392
- // that isn't being waited on and the process exits. These shouldn't be happening,
393
- // but could happen if we have a bug.
394
- //
395
- #ifdef WIN32
396
-
397
- int CrtReportHandler (int reportType, char *message, int *returnValue)
398
- {
399
- std::cerr << " In CRT Report Handler. ReportType:" << reportType << " , message:" << message << std::endl;
400
-
401
- // Cause break into debugger.
402
- *returnValue = 1 ;
403
- return TRUE ;
404
- }
405
-
406
- #endif
407
-
408
391
typedef std::map<std::string, UnitTest::TestList> testlist_t ;
409
392
410
393
void list_test_options (testlist_t & testlists)
@@ -525,7 +508,15 @@ void run_all_tests(UnitTest::TestRunner& testRunner, testlist_t& testlists)
525
508
526
509
int main (int argc, char * argv[])
527
510
{
528
- #ifdef WIN32
511
+ #ifdef _WIN32
512
+ // Add standard error as output as well.
513
+ _CrtSetReportMode (_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);
514
+ _CrtSetReportFile (_CRT_ASSERT, _CRTDBG_FILE_STDERR);
515
+ _CrtSetReportMode (_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);
516
+ _CrtSetReportFile (_CRT_ERROR, _CRTDBG_FILE_STDERR);
517
+ _CrtSetReportMode (_CRT_WARN, _CRTDBG_MODE_FILE);
518
+ _CrtSetReportFile (_CRT_WARN, _CRTDBG_FILE_STDERR);
519
+
529
520
// The test runner built with WinRT support might be used on a pre Win8 machine.
530
521
// Obviously in that case WinRT test cases can't run, but non WinRT ones should be
531
522
// fine. So dynamically try to call RoInitialize/RoUninitialize.
@@ -540,7 +531,6 @@ int main(int argc, char* argv[])
540
531
}
541
532
}
542
533
543
- _CrtSetReportHook2 (_CRT_RPTHOOK_INSTALL, CrtReportHandler);
544
534
struct console_restorer {
545
535
CONSOLE_SCREEN_BUFFER_INFO m_originalConsoleInfo;
546
536
console_restorer ()
@@ -585,6 +575,12 @@ int main(int argc, char* argv[])
585
575
listOption = true ;
586
576
listPropertiesOption = true ;
587
577
}
578
+ #ifdef _WIN32
579
+ if (UnitTest::GlobalSettings::Has (" detectleaks" ))
580
+ {
581
+ _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
582
+ }
583
+ #endif
588
584
589
585
// Start timer.
590
586
UnitTest::Timer timer;
@@ -639,7 +635,7 @@ int main(int argc, char* argv[])
639
635
<< " Took " << elapsedTime << " ms" << std::endl;
640
636
}
641
637
642
- #ifdef WIN32
638
+ #ifdef _WIN32
643
639
if (hComBase != nullptr )
644
640
{
645
641
typedef void (WINAPI *RoUnInit)();
0 commit comments