@@ -6,7 +6,7 @@ use std::{
6
6
net:: IpAddr ,
7
7
path:: PathBuf ,
8
8
process,
9
- time:: Duration ,
9
+ time:: Duration , ffi :: OsStr , os :: unix :: prelude :: OsStrExt ,
10
10
} ;
11
11
use tempfile:: tempdir;
12
12
use tokio:: {
@@ -292,6 +292,69 @@ async fn stdout() {
292
292
}
293
293
}
294
294
295
+
296
+ #[ tokio:: test]
297
+ #[ cfg_attr( not( ci) , ignore) ]
298
+ async fn with_session ( ) {
299
+ for session in connects ( ) . await {
300
+ let mut command =
301
+ std:: process:: Command :: new ( "echo" )
302
+ . arg ( "foo" )
303
+ . with_session ( & session)
304
+ . expect ( "Expected valid utf-8 command." ) ;
305
+
306
+ let child = command. output ( ) . await . unwrap ( ) ;
307
+ assert_eq ! ( child. stdout, b"foo\n " ) ;
308
+
309
+ let child = session
310
+ . command ( "echo" )
311
+ . arg ( "foo" )
312
+ . raw_arg ( ">" )
313
+ . arg ( "/dev/stderr" )
314
+ . output ( )
315
+ . await
316
+ . unwrap ( ) ;
317
+ assert ! ( child. stdout. is_empty( ) ) ;
318
+
319
+ session. close ( ) . await . unwrap ( ) ;
320
+ }
321
+ }
322
+
323
+
324
+ #[ tokio:: test]
325
+ #[ cfg_attr( not( ci) , ignore) ]
326
+ async fn with_session_err ( ) {
327
+
328
+ for session in connects ( ) . await {
329
+ let bad_string = OsStr :: from_bytes ( b"foo\xFF " ) ;
330
+ let command =
331
+ std:: process:: Command :: new ( "echo" )
332
+ . arg ( bad_string)
333
+ . with_session ( & session) ;
334
+
335
+ let expected_error = openssh:: Error :: InvalidUtf8String ( bad_string. to_owned ( ) ) ;
336
+ assert ! ( command. is_err( ) ) ;
337
+ let err = command. unwrap_err ( ) ;
338
+ assert_eq ! ( err. to_string( ) , expected_error. to_string( ) ) ;
339
+
340
+ // let child = command.output().await.unwrap();
341
+ // assert_eq!(child.stdout, b"foo\n");
342
+
343
+ // let child = session
344
+ // .command("echo")
345
+ // .arg("foo")
346
+ // .raw_arg(">")
347
+ // .arg("/dev/stderr")
348
+ // .output()
349
+ // .await
350
+ // .unwrap();
351
+ // assert!(child.stdout.is_empty());
352
+
353
+ session. close ( ) . await . unwrap ( ) ;
354
+ }
355
+ }
356
+
357
+
295
358
#[ tokio:: test]
296
359
#[ cfg_attr( not( ci) , ignore) ]
297
360
async fn shell ( ) {
0 commit comments