@@ -4,12 +4,16 @@ use std::{
44 time:: Duration ,
55} ;
66
7- fn run_example ( server : & str , client : & str ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
7+ fn run_example (
8+ server : & str ,
9+ client : & str ,
10+ args : & [ & str ] ,
11+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
812 // start the server and give it a moment to start.
9- let mut server = do_run_example ( server) . spawn ( ) . unwrap ( ) ;
13+ let mut server = do_run_example ( server, args ) . spawn ( ) . unwrap ( ) ;
1014 std:: thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
1115
12- let mut client = do_run_example ( client) . spawn ( ) . unwrap ( ) ;
16+ let mut client = do_run_example ( client, args ) . spawn ( ) . unwrap ( ) ;
1317 let mut client_succeeded = false ;
1418 let start = std:: time:: Instant :: now ( ) ;
1519 let timeout = Duration :: from_secs ( 600 ) ;
@@ -55,12 +59,15 @@ fn run_example(server: &str, client: &str) -> Result<(), Box<dyn std::error::Err
5559 Ok ( ( ) )
5660}
5761
58- fn do_run_example ( example : & str ) -> Command {
62+ fn do_run_example ( example : & str , args : & [ & str ] ) -> Command {
5963 let mut cmd = Command :: new ( "cargo" ) ;
60- cmd. arg ( "run" )
61- . arg ( "--example" )
62- . arg ( example)
63- . stdout ( std:: process:: Stdio :: piped ( ) )
64+ cmd. arg ( "run" ) . arg ( "--example" ) . arg ( example) ;
65+
66+ if !args. is_empty ( ) {
67+ cmd. arg ( "--" ) . args ( args) ;
68+ }
69+
70+ cmd. stdout ( std:: process:: Stdio :: piped ( ) )
6471 . stderr ( std:: process:: Stdio :: piped ( ) )
6572 . current_dir ( "example" ) ;
6673 cmd
@@ -83,9 +90,18 @@ fn wait_with_output(name: &str, cmd: Child) {
8390
8491#[ test]
8592fn run_examples ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
86- run_example ( "server" , "client" ) ?;
87- run_example ( "async-server" , "async-client" ) ?;
88- run_example ( "async-stream-server" , "async-stream-client" ) ?;
93+ // Local
94+ run_example ( "server" , "client" , & [ ] ) ?;
95+ run_example ( "async-server" , "async-client" , & [ ] ) ?;
96+ run_example ( "async-stream-server" , "async-stream-client" , & [ ] ) ?;
97+
98+ // TCP
99+ #[ cfg( not( windows) ) ]
100+ {
101+ run_example ( "server" , "client" , & [ "--tcp" ] ) ?;
102+ run_example ( "async-server" , "async-client" , & [ "--tcp" ] ) ?;
103+ run_example ( "async-stream-server" , "async-stream-client" , & [ "--tcp" ] ) ?;
104+ }
89105
90106 Ok ( ( ) )
91107}
0 commit comments