Skip to content

Commit

Permalink
Fix failing tests on macos
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
  • Loading branch information
zhiburt committed Mar 29, 2023
1 parent 64d52fc commit 4485e15
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
16 changes: 7 additions & 9 deletions tests/check.rs
Expand Up @@ -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")]
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down
62 changes: 32 additions & 30 deletions tests/repl.rs
Expand Up @@ -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();
Expand All @@ -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() {
Expand Down

0 comments on commit 4485e15

Please sign in to comment.