@@ -245,3 +245,96 @@ fn test_fail_change_directory() {
245
245
. stderr_move_str ( ) ;
246
246
assert ! ( out. contains( "env: cannot change directory to " ) ) ;
247
247
}
248
+
249
+ #[ cfg( unix) ]
250
+ #[ test]
251
+ fn test_simulation_of_terminal_false ( ) {
252
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
253
+
254
+ let out = scene. ucmd ( ) . arg ( "sh" ) . arg ( "is_atty.sh" ) . succeeds ( ) ;
255
+ assert_eq ! (
256
+ String :: from_utf8_lossy( out. stdout( ) ) ,
257
+ "stdin is not atty\n stdout is not atty\n stderr is not atty\n "
258
+ ) ;
259
+ assert_eq ! (
260
+ String :: from_utf8_lossy( out. stderr( ) ) ,
261
+ "This is an error message.\n "
262
+ ) ;
263
+ }
264
+
265
+ #[ cfg( unix) ]
266
+ #[ test]
267
+ fn test_simulation_of_terminal_true ( ) {
268
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
269
+
270
+ let out = scene
271
+ . ucmd ( )
272
+ . arg ( "sh" )
273
+ . arg ( "is_atty.sh" )
274
+ . terminal_simulation ( true )
275
+ . succeeds ( ) ;
276
+ assert_eq ! (
277
+ String :: from_utf8_lossy( out. stdout( ) ) ,
278
+ "stdin is atty\r \n stdout is atty\r \n stderr is atty\r \n "
279
+ ) ;
280
+ assert_eq ! (
281
+ String :: from_utf8_lossy( out. stderr( ) ) ,
282
+ "This is an error message.\r \n "
283
+ ) ;
284
+ }
285
+
286
+ #[ cfg( unix) ]
287
+ #[ test]
288
+ fn test_simulation_of_terminal_pty_sends_eot_automatically ( ) {
289
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
290
+
291
+ let mut cmd = scene. ucmd ( ) ;
292
+ cmd. timeout ( std:: time:: Duration :: from_secs ( 10 ) ) ;
293
+ cmd. args ( & [ "cat" , "-" ] ) ;
294
+ cmd. terminal_simulation ( true ) ;
295
+ let child = cmd. run_no_wait ( ) ;
296
+ let out = child. wait ( ) . unwrap ( ) ; // cat would block if there is no eot
297
+
298
+ assert_eq ! ( String :: from_utf8_lossy( out. stdout( ) ) , "\r \n " ) ;
299
+ assert_eq ! ( String :: from_utf8_lossy( out. stderr( ) ) , "" ) ;
300
+ }
301
+
302
+ #[ cfg( unix) ]
303
+ #[ test]
304
+ fn test_simulation_of_terminal_pty_pipes_into_data_and_sends_eot_automatically ( ) {
305
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
306
+
307
+ let message = "Hello stdin forwarding!" ;
308
+
309
+ let mut cmd = scene. ucmd ( ) ;
310
+ cmd. args ( & [ "cat" , "-" ] ) ;
311
+ cmd. terminal_simulation ( true ) ;
312
+ cmd. pipe_in ( message) ;
313
+ let child = cmd. run_no_wait ( ) ;
314
+ let out = child. wait ( ) . unwrap ( ) ;
315
+
316
+ assert_eq ! (
317
+ String :: from_utf8_lossy( out. stdout( ) ) ,
318
+ format!( "{}\r \n " , message)
319
+ ) ;
320
+ assert_eq ! ( String :: from_utf8_lossy( out. stderr( ) ) , "" ) ;
321
+ }
322
+
323
+ #[ cfg( unix) ]
324
+ #[ test]
325
+ fn test_simulation_of_terminal_pty_write_in_data_and_sends_eot_automatically ( ) {
326
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
327
+
328
+ let mut cmd = scene. ucmd ( ) ;
329
+ cmd. args ( & [ "cat" , "-" ] ) ;
330
+ cmd. terminal_simulation ( true ) ;
331
+ let mut child = cmd. run_no_wait ( ) ;
332
+ child. write_in ( "Hello stdin forwarding via write_in!" ) ;
333
+ let out = child. wait ( ) . unwrap ( ) ;
334
+
335
+ assert_eq ! (
336
+ String :: from_utf8_lossy( out. stdout( ) ) ,
337
+ "Hello stdin forwarding via write_in!\r \n "
338
+ ) ;
339
+ assert_eq ! ( String :: from_utf8_lossy( out. stderr( ) ) , "" ) ;
340
+ }
0 commit comments