Question

Any failed ASSERT statements on Windows cause the below debug message to appear and freeze the applications execution. I realise this is expected behaviour but it is running periodically on a headless machine so prevent the unit tests from failing, instead waiting on user input indefinitely.

Is there s a registry key or compiler flag I can use to prevent this message box from requesting user input whilst still allowing the test to fail under ASSERT?

Basically, I want to do this without modifying any code, just changing compiler or Windows options.

Thanks!

Microsoft Visual C++ Debug Library ASSERT http://img519.imageshack.us/img519/853/snapshotbu1.png

Was it helpful?

Solution

From MSDN about the ASSERT macro:

In an MFC ISAPI application, an assertion in debug mode will bring up a modal dialog box (ASSERT dialog boxes are now modal by default); this will interrupt or hang the execution. To suppress modal assertion dialogs, add the following lines to your project source file (projectname.cpp):

// For custom assert and trace handling with WebDbg
#ifdef _DEBUG
CDebugReportHook g_ReportHook;
#endif

Once you have done this, you can use the WebDbg tool (WebDbg.exe) to see the assertions.

OTHER TIPS

I think this is a dialog shown by _CrtDbgReport for reports of type _CRT_ASSERT. With _CrtSetReportHook, you can tailor that behavior for your entire application. (i.e. requires one local change) In particular, you can continue execution after a failed assertion, thus ignoring it.

In a unit-test context, it is often good to convert ASSERTs (actually _CrtDbgReport calls) into some exception, typically a std::exception, that contains some informative text. This tends to wend its way out to the unit test's output log as a fail. That's just what you want: A failed ASSERT should be a failed unit test.

Do that by throwing in your report-hook function, as specified using: _CrtSetReportHook()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top