How to make a Visual Studio session after running a console application in debug mode?

I have a set of Boost module tests that I want to run as a console application.

When I work on a project and I run tests, I would like to be able to debug tests, and I would like the console to remain open after running the tests.

I see that if I run in release mode, the console window remains after the program exits, but in debug mode this is not so.

I do not want to add 'system ("pause"); or any other hacks, such as reading a character in my program. I just want to pause in Visual Studio after running tests with debugging, as if I were working in release mode. I would also like the test result to be captured in one of Visual Studio's output windows, but it also seems more complex than it should be.

How can i do this?

+60
c ++ boost unit-testing visual-studio console
Oct 11 '08 at 0:30
source share
16 answers

The Boost test offers the following usage guidelines for Visual Studio , which will allow you to automatically run unit tests at the end of compilation and capture the exit to the build window.

A good side effect of this trick is that it allows you to handle test crashes as compilation errors. "... you can jump over these errors using the usual keyboard shortcuts / mouse clicks that you use to analyze compilation errors ..."

+18
11 Oct '08 at 6:56
source share
— -

Try to launch the application using the combination Ctrl + F5 .

+112
Dec 14 '08 at 10:07
source share

http://connect.microsoft.com/VisualStudio/feedback/details/540969/missing-press-any-key-to-continue-when-lauching-with-ctrl-f5

In older versions, the console subsystem will be used by default, even if you chose the "empty project", but not in 2010, so you need to install it manually. To do this, select the project in the solution explorer on the right or on the left (perhaps it is already selected, so you do not need to worry about it). Then select “project” from the drop-down menu of the menu bar, then select “project properties"> "configuration properties"> "linker"> "system" and set the first property, the drop-down property of the "subsystem" to "console" (/ SUBSYSTEM: CONSOLE) ". The console window should remain open after execution, as usual.

+69
Feb 03 2018-12-12T00:
source share

Set a breakpoint on the last line of code.

+10
Oct 11 '08 at 4:20
source share

I just copied from http://social.msdn.microsoft.com/forums/en-US/Vsexpressvc/thread/1555ce45-8313-4669-a31e-b95b5d28c787/?prof=required :

The following works for me :-)

//////////////////////////////////////////////////// ///////////////////////////////////

Here is another reason the console might disappear. And the solution:

With the new version of Visual Studio 2010, you can see this behavior even if you use Ctrl + F5 aka "start without debugging". This is most likely because you created an "empty project" instead of a "Win32 console application." If you create the project as a “Win32 console application”, you can ignore it because it is not applicable.

In older versions, it will use the console subsystem by default, even if you select the "empty project", but not in Visual Studio 2010, so you need to install it manually. To do this, select the project in the solution explorer on the right or on the left (perhaps it is already selected, so you do not need to worry about it).

Then select "project" in the drop-down menu of the menu bar, then select "project_name properties" → "configuration properties" → "linker" → "system" and set the first property, the "subsystem" drop-down property to "console (/ SUBSYSTEM: CONSOLE)" . The console window should remain open after execution, as usual.

//////////////////////////////////////////////////// ///////////////////////////////////

+6
Feb 23 2018-11-11T00:
source share

If this is a console application, use Ctrl + F5 .

+5
Nov 14 2018-10-11T00:
source share

You say you do not want to use the system("pause") hack. Why not?

If this is so because you do not want the program to request when it is not being debugged, there is a way around this. This works for me:

 void pause () { system ("pause"); } int main (int argc, char ** argv) { // If "launched", then don't let the console close at the end until // the user has seen the report. // (See the MSDN ConGUI sample code) // do { HANDLE hConsoleOutput = ::GetStdHandle (STD_OUTPUT_HANDLE); if (INVALID_HANDLE_VALUE == hConsoleOutput) break; CONSOLE_SCREEN_BUFFER_INFO csbi; if (0 == ::GetConsoleScreenBufferInfo (hConsoleOutput, &csbi)) break; if (0 != csbi.dwCursorPosition.X) break; if (0 != csbi.dwCursorPosition.Y) break; if (csbi.dwSize.X <= 0) break; if (csbi.dwSize.Y <= 0) break; atexit (pause); } while (0); 

I just paste this code into every new console application that I write. If the program is launched from the command window, the cursor position will not be <0,0>, and it will not call atexit() . If it was launched from your debugger (any debugger), the cursor position in the console will be <0,0> and an atexit() call will be made.

I got the idea from an example program that used to be in the MSDN library, but I think it was deleted.

NOTE. Implementing the Microsoft Visual Studio system () system procedure requires the COMSPEC environment variable to identify the command line interpreter. If this environment variable is confused - for example, if you have a problem with the debugging properties of your Visual Studio project so that the environment variables are not properly transferred when the program starts - then it just fails.

+3
Nov 25 '08 at 21:39
source share

In Boost.Test there is a parameter --auto_start_dbg for breaking into the debugger when the test fails (with an exception or with an assertion error). For some reason this does not work for me.

See http://www.boost.org/doc/libs/1_40_0/libs/test/doc/html/utf/usage-recommendations/dot-net-specific.html

For this reason, I created my own test_observer, which will crash into the debugger if there is an assertion error or an exception. This is included in debug builds when we run under the debugger.

In one of the source files of my unit test EXE file, I added this code:

 #ifdef _DEBUG #include <boost/test/framework.hpp> #include <boost/test/test_observer.hpp> struct BoostUnitTestCrtBreakpointInDebug: boost::unit_test::test_observer { BoostUnitTestCrtBreakpointInDebug() { boost::unit_test::framework::register_observer(*this); } virtual ~BoostUnitTestCrtBreakpointInDebug() { boost::unit_test::framework::deregister_observer(*this); } virtual void assertion_result( bool passed /* passed */ ) { if (!passed) BreakIfInDebugger(); } virtual void exception_caught( boost::execution_exception const& ) { BreakIfInDebugger(); } void BreakIfInDebugger() { if (IsDebuggerPresent()) { /** * Hello, I know you are here staring at the debugger :) * * If you got here then there is an exception in your unit * test code. Walk the call stack to find the actual cause. */ _CrtDbgBreak(); } } }; BOOST_GLOBAL_FIXTURE(BoostUnitTestCrtBreakpointInDebug); #endif 
+3
May 03 '11 at 10:50
source share

Actually, there would be more effort, but you could just build VS.Net, start it from the usual command line (cmd.exe) and then attach it to the process after it starts. This is probably not the solution you are looking for.

+1
Oct 11 '08 at 1:04
source share

I would use the wait command for a specific time (milliseconds) of your own choice. The application runs until the line you want to check, and then continues after the time has passed.

Include the header <time.h> :

 clock_t wait; wait = clock(); while (clock() <= (wait + 5000)) // Wait for 5 seconds and then continue ; wait = 0; 
+1
Feb 15 '11 at 23:35
source share

Or you can use boost_test "Test Log Output."

http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/user-guide/test-output/test-log.html

Then it doesn't matter if the console window appears at all. And your build log can save the device test result as an artifact for checking on failed builds ...

+1
Oct 26 '11 at 3:28
source share

Just use a logging library such as log4net and register it in the file application.

0
Oct 11 '08 at 1:16
source share

You can also configure the executable as an external tool and mark the tool for the Use Output window. Thus, the output of the tool will be visible in Visual Studio itself, and not in a separate window.

0
Oct. 11 '08 at 1:58
source share

I run the application with F11 and get a breakpoint somewhere in unit_test_main.ipp (maybe the build code). I use shift-f11 (step) to run the unit test and get the next build instruction in CRT (usually in mainCRTStartup ()). I use F9 to set a breakpoint in this command.

On the next call, I can start the application with F5, and the application will break after running the tests, so give me the opportunity to look into the console window

0
Mar 13 '10 at 23:21
source share

Adding the following line will make a simple MS-DOS pause that does not display a message.

 system("pause >nul | set /p \"=\""); 

And there is no need for Ctrl + F5 (which will make your application work in release mode)

0
Aug 05 '13 at 12:54 on
source share

Read at the end (this is the “Cochin form,” as we say in Colombia, but it works):

 static void Main(string[] args) { . . . String temp = Console.ReadLine(); } 
-one
Jun 05 '10 at 17:40
source share



All Articles