1
1
use std:: {
2
2
io:: { BufRead , BufReader } ,
3
- process:: Command ,
3
+ process:: { Child , Command } ,
4
4
time:: Duration ,
5
5
} ;
6
6
@@ -22,13 +22,19 @@ fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
22
22
} ) ;
23
23
let output = client. stdout . unwrap ( ) ;
24
24
BufReader :: new ( output) . lines ( ) . for_each ( |line| {
25
- println ! ( "{}" , line. unwrap( ) ) ;
25
+ println ! ( "client output: {}" , line. unwrap( ) ) ;
26
26
} ) ;
27
27
break ;
28
28
}
29
29
30
30
match client. try_wait ( ) {
31
31
Ok ( Some ( status) ) => {
32
+ println ! (
33
+ "Client exited with status: {:?} success {}" ,
34
+ & status,
35
+ & status. success( )
36
+ ) ;
37
+ wait_with_output ( "client" , client) ;
32
38
client_succeeded = status. success ( ) ;
33
39
break ;
34
40
}
@@ -45,6 +51,7 @@ fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
45
51
46
52
// be sure to clean up the server, the client should have run to completion
47
53
server. kill ( ) ?;
54
+ wait_with_output ( "server" , server) ;
48
55
assert ! ( client_succeeded) ;
49
56
Ok ( ( ) )
50
57
}
@@ -59,3 +66,18 @@ fn run_example(example: &str) -> Command {
59
66
. current_dir ( "example" ) ;
60
67
cmd
61
68
}
69
+
70
+ fn wait_with_output ( name : & str , cmd : Child ) {
71
+ if let Ok ( output) = cmd. wait_with_output ( ) {
72
+ println ! ( "==== {name} output begin" ) ;
73
+ println ! ( "==== stdout:" ) ;
74
+ output. stdout . lines ( ) . for_each ( |line| {
75
+ println ! ( "{}" , line. unwrap( ) ) ;
76
+ } ) ;
77
+ println ! ( "==== stderr:" ) ;
78
+ output. stderr . lines ( ) . for_each ( |line| {
79
+ println ! ( "{}" , line. unwrap( ) ) ;
80
+ } ) ;
81
+ println ! ( "==== {name} output end" ) ;
82
+ }
83
+ }
0 commit comments