slothg / cmockery

Automatically exported from code.google.com/p/cmockery
0 stars 0 forks source link

stdout and stderr outputs could be messed up #13

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. compile the standard cmockery example 'assert_macro_test.exe' on Windows
2. execute "assert_macro_test.exe 1>output 2>&1"

What is the expected output? What do you see instead?

The file "output" should contain:

get_status_code_string_test: Starting test
"Connection dropped" != "Connection timed out"
ERROR: ..\src\example\assert_macro_test.c:29 Failure!
get_status_code_string_test: Test failed.
string_to_status_code_test: Starting test
0x2 != 0x1
ERROR: ..\src\example\assert_macro_test.c:35 Failure!
string_to_status_code_test: Test failed.
2 out of 2 tests failed!
    get_status_code_string_test
    string_to_status_code_test

but it contains:

get_status_code_string_test: Starting test
get_status_code_string_test: Test failed.
string_to_status_code_test: Starting test
string_to_status_code_test: Test failed.
"Connection dropped" != "Connection timed out"
ERROR: ..\src\example\assert_macro_test.c:29 Failure!
0x2 != 0x1
ERROR: ..\src\example\assert_macro_test.c:35 Failure!
2 out of 2 tests failed!
    get_status_code_string_test
    string_to_status_code_test

What version of the product are you using? On what operating system?

1. cmockery 0.1.2
2. Windows XP SP3
3. Visual Studio 2008

Please provide any additional information below.

fflush() function should be called after each line printed to the stdout or 
stderr.

The patch below fixes this problem:

--- cmockery.c  Sat Aug 30 02:55:54 2008
+++ cmockery.c  Tue Jul 21 10:24:14 2009
@@ -1449,6 +1449,7 @@
    char buffer[1024];
    vsnprintf(buffer, sizeof(buffer), format, args);
    printf(buffer);
+   fflush(stdout);
 #ifdef _WIN32
    OutputDebugString(buffer);
 #endif // _WIN32
@@ -1459,6 +1460,7 @@
    char buffer[1024];
    vsnprintf(buffer, sizeof(buffer), format, args);
    fprintf(stderr, buffer);
+   fflush(stderr);
 #ifdef _WIN32
    OutputDebugString(buffer);
 #endif // _WIN32

Original issue reported on code.google.com by ade...@gmail.com on 21 Jul 2009 at 10:39