diff --git a/tests/check.rs b/tests/check.rs index 31aba69..658a2f2 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -114,9 +114,8 @@ fn check_eof() { thread::sleep(Duration::from_millis(600)); let m = session.check(Eof).await.unwrap(); - assert!(m.matches().count() == 0); + assert_eq!(m.before(), b""); - let m = session.check(Eof).await.unwrap(); if m.matches().len() > 0 { let buf = m.get(0).unwrap(); #[cfg(target_os = "macos")] @@ -264,10 +263,11 @@ fn check_macro_eof() { expectrl::check!( &mut session, output = Eof => { + let buf = output.get(0).unwrap(); #[cfg(target_os = "linux")] - assert_eq!(output.get(0).unwrap(), b"'Hello World'\r\n"); + assert_eq!(buf, b"'Hello World'\r\n"); #[cfg(not(target_os = "linux"))] - assert_eq!(output.get(0).unwrap(), b""); + assert!(matches!(buf, b"" | b"'Hello World'\r\n"), "{:?}", buf); assert_eq!(output.before(), b""); }, default => { @@ -289,16 +289,14 @@ fn check_macro_eof() { ); futures_lite::future::block_on(async { - let m = session.check(Eof).await.unwrap(); - assert!(m.matches().next().is_none()); - expectrl::check!( session, output = Eof => { + let buf = output.get(0).unwrap(); #[cfg(target_os = "linux")] - assert_eq!(output.get(0).unwrap(), b"'Hello World'\r\n"); + assert_eq!(buf, b"'Hello World'\r\n"); #[cfg(not(target_os = "linux"))] - assert_eq!(output.get(0).unwrap(), b""); + assert!(matches!(buf, b"" | b"'Hello World'\r\n"), "{:?}", buf); assert_eq!(output.before(), b""); }, default => { diff --git a/tests/repl.rs b/tests/repl.rs index 35788cd..6c48099 100644 --- a/tests/repl.rs +++ b/tests/repl.rs @@ -99,42 +99,14 @@ fn bash_with_log() { }) } -#[cfg(feature = "async")] -#[test] -fn python() { - futures_lite::future::block_on(async { - let mut p = spawn_python().await.unwrap(); - - let prompt = p.execute("print('Hello World')").await.unwrap(); - assert_eq!(prompt, b"Hello World\r\n"); - - thread::sleep(Duration::from_millis(300)); - p.send(ControlCode::EndOfText).await.unwrap(); - thread::sleep(Duration::from_millis(300)); - - let mut msg = String::new(); - p.read_line(&mut msg).await.unwrap(); - assert_eq!(msg, "\r\n"); - - let mut msg = String::new(); - p.read_line(&mut msg).await.unwrap(); - assert_eq!(msg, "KeyboardInterrupt\r\n"); - - p.expect_prompt().await.unwrap(); - - p.send(ControlCode::EndOfTransmission).await.unwrap(); - - assert_eq!(p.wait().unwrap(), WaitStatus::Exited(p.pid(), 0)); - }) -} - #[cfg(not(feature = "async"))] #[test] fn python() { let mut p = spawn_python().unwrap(); let prompt = p.execute("print('Hello World')").unwrap(); - assert_eq!(prompt, b"Hello World\r\n"); + let prompt = String::from_utf8_lossy(&prompt); + assert!(prompt.contains("Hello World"), "{prompt:?}"); thread::sleep(Duration::from_millis(300)); p.send(ControlCode::EndOfText).unwrap(); @@ -158,6 +130,36 @@ fn python() { ); } +#[cfg(feature = "async")] +#[test] +fn python() { + futures_lite::future::block_on(async { + let mut p = spawn_python().await.unwrap(); + + let prompt = p.execute("print('Hello World')").await.unwrap(); + let prompt = String::from_utf8_lossy(&prompt); + assert!(prompt.contains("Hello World"), "{prompt:?}"); + + thread::sleep(Duration::from_millis(300)); + p.send(ControlCode::EndOfText).await.unwrap(); + thread::sleep(Duration::from_millis(300)); + + let mut msg = String::new(); + p.read_line(&mut msg).await.unwrap(); + assert_eq!(msg, "\r\n"); + + let mut msg = String::new(); + p.read_line(&mut msg).await.unwrap(); + assert_eq!(msg, "KeyboardInterrupt\r\n"); + + p.expect_prompt().await.unwrap(); + + p.send(ControlCode::EndOfTransmission).await.unwrap(); + + assert_eq!(p.wait().unwrap(), WaitStatus::Exited(p.pid(), 0)); + }) +} + #[cfg(feature = "async")] #[test] fn bash_pwd() {