Skip to content

Commit

Permalink
fixup command build and cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeichlersmith committed Sep 2, 2024
1 parent 4e93608 commit 1241139
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/cmdrun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ impl CmdRun {
let (command, correct_exit_code): (String, Option<i32>) = if let Some(first_word) = command.split_whitespace().next() {
if first_word.starts_with('-') {
let (_, exit_code) = first_word.rsplit_once('-').unwrap_or(("","0"));
(command.split_whitespace().skip(1).collect::<String>(), Some(exit_code.parse()?))
(
command.split_whitespace().skip(1).collect::<Vec<&str>>().join(" "),
Some(exit_code.parse()?)
)
} else {
(command, None)
}
Expand Down
13 changes: 9 additions & 4 deletions tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ cfg_if! {
add_test!(quote3, "echo ''", "\n", false);
add_test!(quote4, "echo '\\'", "\\\n", false);

// the inline flag only affects the output and here I'm just checking exit codes
// so I only test without the inline flag
add_test!(match_fail_exit_code, "-1 exit 1", "", false);
add_test!(match_pass_exit_code, "-0 exit 0", "", false);

#[test]
fn fail_inline() {
assert!(CmdRun::run_cmdrun("-1 exit 1".to_string(), ".", true).is_err())
fn exit_code_mismatch() {
assert!(CmdRun::run_cmdrun("-0 exit 1".to_string(), ".", false).is_err())
}

#[test]
fn fail() {
assert!(CmdRun::run_cmdrun("-1 exit 1".to_string(), ".", false).is_err())
fn bad_exit_code_spec() {
assert!(CmdRun::run_cmdrun("-O exit 0".to_string(), ".", false).is_err())
}

add_test!(
Expand Down

0 comments on commit 1241139

Please sign in to comment.