Skip to content

Commit

Permalink
test exit scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-babichenko committed Nov 25, 2024
1 parent b8c512e commit 155f464
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ panic = "abort"
# This project is conscious about its dependencies. Only add them if you really
# need to. Be aware of crates features, and only enable what is needed.
clap = { version = "4", features = ["derive", "env"] }
ctrlc = "3"
ctrlc = { version = "3", features = ["termination"] }
dialoguer = { version = "0.11", default-features = false }
env_logger = "0.11"
log = "0.4"
Expand Down
10 changes: 8 additions & 2 deletions src/cmd/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ impl Cmd {
print!("{}", fixes[selection]);
Ok(())
}
Ok(None) => Ok(()),
Ok(None) => {
eprintln!("Cancelled.");
Ok(())
}
// Do not throw an error when Ctrl-C is pressed.
Err(dialoguer::Error::IO(e)) if e.kind() == io::ErrorKind::Interrupted => Ok(()),
Err(dialoguer::Error::IO(e)) if e.kind() == io::ErrorKind::Interrupted => {
eprintln!("Cancelled.");
Ok(())
}
Err(e) => Err(Error::Select(e)),
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,16 @@ fn nothing_to_fix(bash: (Session, NamedTempFile)) {
p.send_line("").unwrap();
p.expect("nothing to fix").unwrap();
}

#[rstest]
fn quit(bash: (Session, NamedTempFile)) {
let (mut p, _histfile) = bash;

p.set_expect_timeout(Some(Duration::from_secs(5)));

p.send_line("eco 'Hello, world!'").unwrap();
p.expect("command not found").unwrap();
p.send_line("fix").unwrap();
p.send_line("q").unwrap();
p.expect("Cancelled.").unwrap();
}

0 comments on commit 155f464

Please sign in to comment.