@@ -299,33 +299,6 @@ fn output_base_name(config: &config, testfile: &str) -> str {
299
299
#fmt ( "%s%s.%s" , base, filename, config. stage_id )
300
300
}
301
301
302
- #[ cfg( target_os = "win32" ) ]
303
- #[ cfg( target_os = "linux" ) ]
304
- fn dump_output ( config : & config , testfile : & str , out : & str ) {
305
- let outfile = make_out_name ( config, testfile) ;
306
- let writer = io:: file_writer ( outfile, [ io:: create, io:: truncate] ) ;
307
- writer. write_str ( out) ;
308
- maybe_dump_to_stdout ( config, out) ;
309
- }
310
-
311
- // FIXME (726): Can't use file_writer on mac
312
- #[ cfg( target_os = "macos" ) ]
313
- fn dump_output ( config : & config , testfile : & str , out : & str ) {
314
- maybe_dump_to_stdout ( config, out) ;
315
- }
316
-
317
- fn maybe_dump_to_stdout ( config : & config , out : & str ) {
318
- if config. verbose {
319
- io:: stdout ( ) . write_line ( "------------------------------------------" ) ;
320
- io:: stdout ( ) . write_line ( out) ;
321
- io:: stdout ( ) . write_line ( "------------------------------------------" ) ;
322
- }
323
- }
324
-
325
- fn make_out_name ( config : & config , testfile : & str ) -> str {
326
- output_base_name ( config, testfile) + ".out"
327
- }
328
-
329
302
fn logv ( config : & config , s : & str ) {
330
303
log s;
331
304
if config. verbose { io:: stdout ( ) . write_line ( s) ; }
@@ -472,7 +445,7 @@ mod runtest {
472
445
473
446
let next_err_idx = 0 u;
474
447
let next_err_pat = props. error_patterns. ( next_err_idx) ;
475
- for line: str in str :: split( procres. out , '\n' as u8 ) {
448
+ for line: str in str :: split( procres. stdout , '\n' as u8 ) {
476
449
if str :: find( line, next_err_pat) > 0 {
477
450
log #fmt( "found error pattern %s" , next_err_pat) ;
478
451
next_err_idx += 1 u;
@@ -500,7 +473,7 @@ mod runtest {
500
473
501
474
type procargs = { prog: str , args: vec[ str ] } ;
502
475
503
- type procres = { status: int, out : str , cmdline: str } ;
476
+ type procres = { status: int, stdout : str , stderr : str , cmdline: str } ;
504
477
505
478
fn compile_test( cx: & cx, props: & test_props, testfile: & str ) -> procres {
506
479
compose_and_run( cx, testfile, bind make_compile_args( _, props, _) ,
@@ -554,8 +527,52 @@ mod runtest {
554
527
cmdline
555
528
} ;
556
529
let res = procsrv:: run( cx. procsrv, lib_path, prog, args) ;
557
- dump_output( cx. config, testfile, res. out) ;
558
- ret { status: res. status, out: res. out, cmdline: cmdline} ;
530
+ dump_output( cx. config, testfile, res. out, res. err) ;
531
+ ret { status: res. status, stdout: res. out,
532
+ stderr: res. err, cmdline: cmdline} ;
533
+ }
534
+
535
+ fn dump_output( config: & config, testfile: & str ,
536
+ out: & str , err: & str ) {
537
+ dump_output_file( config, testfile, out, "out" ) ;
538
+ dump_output_file( config, testfile, err, "err" ) ;
539
+ maybe_dump_to_stdout( config, out, err) ;
540
+ }
541
+
542
+ #[ cfg( target_os = "win32" ) ]
543
+ #[ cfg( target_os = "linux" ) ]
544
+ fn dump_output_file( config: & config, testfile: & str ,
545
+ out: & str , extension: & str ) {
546
+ let outfile = make_out_name( config, testfile, extension) ;
547
+ let writer = io:: file_writer( outfile, [ io:: create, io:: truncate] ) ;
548
+ writer. write_str( out) ;
549
+ }
550
+
551
+ // FIXME (726): Can't use file_writer on mac
552
+ #[ cfg( target_os = "macos" ) ]
553
+ fn dump_output_file( config: & config, testfile: & str ,
554
+ out: & str , extension: & str ) {
555
+ }
556
+
557
+ fn make_out_name( config: & config, testfile: & str ,
558
+ extension: & str ) -> str {
559
+ output_base_name( config, testfile) + "." + extension
560
+ }
561
+
562
+ fn maybe_dump_to_stdout( config: & config,
563
+ out: & str , err: & str ) {
564
+ if config. verbose {
565
+ let sep1 = #fmt( "-%s-----------------------------------" ,
566
+ "stdout" ) ;
567
+ let sep2 = #fmt( "-%s-----------------------------------" ,
568
+ "stderr" ) ;
569
+ let sep3 = "------------------------------------------" ;
570
+ io:: stdout( ) . write_line( sep1) ;
571
+ io:: stdout( ) . write_line( out) ;
572
+ io:: stdout( ) . write_line( sep2) ;
573
+ io:: stdout( ) . write_line( err) ;
574
+ io:: stdout( ) . write_line( sep3) ;
575
+ }
559
576
}
560
577
561
578
fn error( err: & str ) { io:: stdout( ) . write_line( #fmt( "\n error: %s" , err) ) ; }
@@ -567,12 +584,16 @@ mod runtest {
567
584
#fmt( "\n \
568
585
error: %s\n \
569
586
command: %s\n \
570
- output:\n \
587
+ stdout:\n \
588
+ ------------------------------------------\n \
589
+ %s\n \
590
+ ------------------------------------------\n \
591
+ stderr:\n \
571
592
------------------------------------------\n \
572
593
%s\n \
573
594
------------------------------------------\n \
574
595
\n ",
575
- err, procres. cmdline, procres. out ) ;
596
+ err, procres. cmdline, procres. stdout , procres . stderr ) ;
576
597
io:: stdout( ) . write_str( msg) ;
577
598
fail;
578
599
}
@@ -599,7 +620,7 @@ mod procsrv {
599
620
600
621
tag request { exec( str , str , vec[ str ] , chan[ response] ) ; stop; }
601
622
602
- type response = { pid: int, outfd: int} ;
623
+ type response = { pid: int, outfd: int, errfd : int } ;
603
624
604
625
fn mk( ) -> handle {
605
626
let setupport = port( ) ;
@@ -629,22 +650,28 @@ mod procsrv {
629
650
}
630
651
631
652
fn run( handle: & handle, lib_path: & str , prog: & str , args: & vec[ str ] ) ->
632
- { status: int, out: str } {
653
+ { status: int, out: str , err : str } {
633
654
let p = port[ response] ( ) ;
634
655
let ch = chan( p) ;
635
656
task:: send( handle. chan, exec( lib_path, prog, args, ch) ) ;
636
-
637
657
let resp = task:: recv( p) ;
658
+ let output = readclose( resp. outfd) ;
659
+ let errput = readclose( resp. errfd) ;
660
+ let status = os:: waitpid( resp. pid) ;
661
+ ret { status: status, out: output, err: errput} ;
662
+ }
663
+
664
+ fn readclose( fd: int) -> str {
638
665
// Copied from run::program_output
639
- let outfile = os:: fd_FILE( resp . outfd ) ;
640
- let reader = io:: new_reader( io:: FILE_buf_reader ( outfile , false ) ) ;
666
+ let file = os:: fd_FILE( fd ) ;
667
+ let reader = io:: new_reader( io:: FILE_buf_reader ( file , false ) ) ;
641
668
let buf = "" ;
642
669
while !reader. eof( ) {
643
670
let bytes = reader. read_bytes( 4096 u) ;
644
671
buf += str :: unsafe_from_bytes( bytes) ;
645
672
}
646
- os:: libc:: fclose( outfile ) ;
647
- ret { status : os :: waitpid ( resp . pid ) , out : buf} ;
673
+ os:: libc:: fclose( file ) ;
674
+ ret buf;
648
675
}
649
676
650
677
fn worker( p: port[ request] ) {
@@ -654,15 +681,20 @@ mod procsrv {
654
681
// This is copied from run::start_program
655
682
let pipe_in = os:: pipe( ) ;
656
683
let pipe_out = os:: pipe( ) ;
684
+ let pipe_err = os:: pipe( ) ;
657
685
let spawnproc =
658
686
bind run:: spawn_process( prog, args, pipe_in. in,
659
- pipe_out. out, 0 ) ;
687
+ pipe_out. out, pipe_err . out ) ;
660
688
let pid = with_lib_path( lib_path, spawnproc) ;
661
689
if pid == -1 { fail; }
662
690
os:: libc:: close( pipe_in. in) ;
663
691
os:: libc:: close( pipe_in. out) ;
664
692
os:: libc:: close( pipe_out. out) ;
665
- task:: send( respchan, { pid: pid, outfd: pipe_out. in} ) ;
693
+ os:: libc:: close( pipe_err. out) ;
694
+ task:: send( respchan,
695
+ { pid: pid,
696
+ outfd: pipe_out. in,
697
+ errfd: pipe_err. in} ) ;
666
698
}
667
699
stop. { ret; }
668
700
}
0 commit comments