Skip to content

Commit

Permalink
Run integration tests with multiple shells
Browse files Browse the repository at this point in the history
  • Loading branch information
jpikl committed Mar 27, 2024
1 parent 3d969f6 commit b2ca270
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
0.4
- Run integration tests using multiple shells.
- Better shell specific examples for `rew x`.
- Add `rew x --quote` with examples.
- Fix `--examples` order in generated docs.
Expand Down
41 changes: 32 additions & 9 deletions tests/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,43 @@ macro_rules! command_test_case {
}
};
($ident:ident, $name:literal, sh $template:literal assert $stdin:expr => $stdout:expr) => {
mod $ident {
#[rstest::rstest]
#[timeout($crate::utils::TIMEOUT)]
fn sh() {
$crate::utils::assert_shell("sh", $template, $name, $stdin)
.success()
.stdout($stdout)
.stderr("");
}

#[cfg(target_os = "windows")]
#[rstest::rstest]
#[timeout($crate::utils::TIMEOUT)]
fn cmd() {
$crate::utils::assert_shell("cmd", $template, $name, $stdin)
.success()
.stdout($stdout)
.stderr("");
}

// We do not test powershell because it normalizes newlines to CRLF which breaks test assertions
}
};
($ident:ident, $name:literal, sh $template:literal assert $stdin:expr => err $stderr:expr) => {
#[rstest::rstest]
#[timeout($crate::utils::TIMEOUT)]
fn $ident() {
$crate::utils::assert_shell($template, $name, $stdin)
.success()
.stdout($stdout)
.stderr("");
$crate::utils::assert_shell("sh", $template, $name, $stdin)
.failure()
.stderr($crate::utils::expand_err($name, $stderr));
}
};
($ident:ident, $name:literal, sh $template:literal assert $stdin:expr => err $stderr:expr) => {

#[cfg(target_os = "windows")]
#[rstest::rstest]
#[timeout($crate::utils::TIMEOUT)]
fn $ident() {
$crate::utils::assert_shell($template, $name, $stdin)
$crate::utils::assert_shell("cmd", $template, $name, $stdin)
.failure()
.stderr($crate::utils::expand_err($name, $stderr));
}
Expand All @@ -69,8 +92,8 @@ pub fn assert_command(name: &str, args: &[&str], stdin: impl Into<Vec<u8>>) -> A
.assert()
}

pub fn assert_shell(template: &str, cmd: &str, stdin: impl Into<Vec<u8>>) -> Assert {
let sh = env::var("SHELL").map(Shell::new).unwrap_or_default();
pub fn assert_shell(sh: &str, template: &str, cmd: &str, stdin: impl Into<Vec<u8>>) -> Assert {
let sh = Shell::new(sh);
let sh_kind = sh.kind();

let bin = get_bin();
Expand Down

0 comments on commit b2ca270

Please sign in to comment.