From 4f9a77fff629b28d3db89aee3119bf22789fce40 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 27 Aug 2021 17:01:50 -0700 Subject: [PATCH] Fix error message tests for Alpine Linux (#956) --- tests/choose.rs | 7 ++++--- tests/command.rs | 2 +- tests/edit.rs | 7 ++++--- tests/test.rs | 22 ++++++++++++---------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/choose.rs b/tests/choose.rs index 45954ea..fa37d14 100644 --- a/tests/choose.rs +++ b/tests/choose.rs @@ -160,9 +160,10 @@ fn status_error() { .output() .unwrap(); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - "error: Chooser `exit-2` failed: exit code: 2\n", + assert!( + Regex::new("^error: Chooser `exit-2` failed: exit (code|status): 2\n$") + .unwrap() + .is_match(str::from_utf8(&output.stderr).unwrap()) ); assert_eq!(output.status.code().unwrap(), 2); diff --git a/tests/command.rs b/tests/command.rs index c02f0eb..7caf603 100644 --- a/tests/command.rs +++ b/tests/command.rs @@ -91,7 +91,7 @@ test! { echo XYZ ", args: ("--command", "false"), - stderr: "error: Command `false` failed: exit code: 1\n", + stderr_regex: "error: Command `false` failed: exit (code|status): 1\n", status: EXIT_FAILURE, } diff --git a/tests/edit.rs b/tests/edit.rs index c85bcb6..8eb80dd 100644 --- a/tests/edit.rs +++ b/tests/edit.rs @@ -79,9 +79,10 @@ fn status_error() { .output() .unwrap(); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - "error: Editor `exit-2` failed: exit code: 2\n" + assert!( + Regex::new("^error: Editor `exit-2` failed: exit (code|status): 2\n$") + .unwrap() + .is_match(str::from_utf8(&output.stderr).unwrap(),) ); assert_eq!(output.status.code().unwrap(), 2); diff --git a/tests/test.rs b/tests/test.rs index b998dd5..31cee0d 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -3,17 +3,18 @@ use crate::common::*; use pretty_assertions::assert_eq; macro_rules! test { - ( - name: $name:ident, + { + name: $name:ident, $(justfile: $justfile:expr,)? - $(args: ($($arg:tt),*),)? - $(env: { $($env_key:literal : $env_value:literal,)* },)? - $(stdin: $stdin:expr,)? - $(stdout: $stdout:expr,)? - $(stderr: $stderr:expr,)? - $(status: $status:expr,)? - $(shell: $shell:expr,)? - ) => { + $(args: ($($arg:tt),*),)? + $(env: { $($env_key:literal : $env_value:literal,)* },)? + $(stdin: $stdin:expr,)? + $(stdout: $stdout:expr,)? + $(stderr: $stderr:expr,)? + $(stderr_regex: $stderr_regex:expr,)? + $(status: $status:expr,)? + $(shell: $shell:expr,)? + } => { #[test] fn $name() { let test = crate::test::Test::new(); @@ -24,6 +25,7 @@ macro_rules! test { $(let test = test.shell($shell);)? $(let test = test.status($status);)? $(let test = test.stderr($stderr);)? + $(let test = test.stderr_regex($stderr_regex);)? $(let test = test.stdin($stdin);)? $(let test = test.stdout($stdout);)?