@@ -35,6 +35,7 @@ static int cu_fail_checks = 0;
35
35
36
36
#define CU_OUT_PREFIX_LENGTH 128
37
37
static char cu_out_prefix [CU_OUT_PREFIX_LENGTH + 1 ] = "" ;
38
+ static int cu_out_per_test = 0 ;
38
39
39
40
40
41
/* globally used file descriptor for reading/writing messages */
@@ -68,6 +69,7 @@ static int test_failed;
68
69
69
70
static void redirect_out_err (const char * testName );
70
71
static void close_out_err (void );
72
+ static void redirect_test_out_err (const char * test_suite , const char * test );
71
73
static int run_test (const char * t_name , cu_test_func_t t_func );
72
74
static void run_test_suite (const char * ts_name , cu_test_suite_t * ts ,
73
75
int test_id );
@@ -234,6 +236,9 @@ static int run_test(const char *t_name, cu_test_func_t t_func)
234
236
char buffer [MSGBUF_LEN ];
235
237
int len ;
236
238
239
+ if (cu_out_per_test )
240
+ redirect_test_out_err (cu_current_test_suite , t_name );
241
+
237
242
test_failed = 0 ;
238
243
239
244
/* set up name of test for later messaging */
@@ -266,7 +271,8 @@ static void run_test_suite(const char *ts_name, cu_test_suite_t *ts,
266
271
cu_current_test_suite = ts_name ;
267
272
268
273
/* redirect stdout and stderr */
269
- redirect_out_err (cu_current_test_suite );
274
+ if (!cu_out_per_test )
275
+ redirect_out_err (cu_current_test_suite );
270
276
271
277
while (test_id == -1 && ts -> name != NULL && ts -> func != NULL ){
272
278
test_suite_failed |= run_test (ts -> name , ts -> func );
@@ -389,17 +395,35 @@ void cu_set_out_prefix(const char *str)
389
395
strncpy (cu_out_prefix , str , CU_OUT_PREFIX_LENGTH );
390
396
}
391
397
398
+ void cu_set_out_per_test (int yes )
399
+ {
400
+ cu_out_per_test = yes ;
401
+ }
402
+
392
403
static void redirect_out_err (const char * test_name )
393
404
{
394
- char buf [100 ];
405
+ redirect_test_out_err (test_name , NULL );
406
+ }
395
407
396
- snprintf (buf , 99 , "%stmp.%s.out" , cu_out_prefix , test_name );
408
+ static void redirect_test_out_err (const char * test_suite , const char * test )
409
+ {
410
+ char buf [256 ];
411
+
412
+ if (test != NULL ){
413
+ snprintf (buf , 255 , "%stmp.%s.%s.out" , cu_out_prefix , test_suite , test );
414
+ }else {
415
+ snprintf (buf , 255 , "%stmp.%s.out" , cu_out_prefix , test_suite );
416
+ }
397
417
if (freopen (buf , "w" , stdout ) == NULL ){
398
418
perror ("Redirecting of stdout failed" );
399
419
exit (-1 );
400
420
}
401
421
402
- snprintf (buf , 99 , "%stmp.%s.err" , cu_out_prefix , test_name );
422
+ if (test != NULL ){
423
+ snprintf (buf , 255 , "%stmp.%s.%s.err" , cu_out_prefix , test_suite , test );
424
+ }else {
425
+ snprintf (buf , 255 , "%stmp.%s.err" , cu_out_prefix , test_suite );
426
+ }
403
427
if (freopen (buf , "w" , stderr ) == NULL ){
404
428
perror ("Redirecting of stderr failed" );
405
429
exit (-1 );
0 commit comments