mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
tests/common: add util_name+bin_path to CmdResult
This commit is contained in:
parent
ab4573bde9
commit
0bbc805e43
1 changed files with 46 additions and 0 deletions
|
@ -62,6 +62,10 @@ fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: &Option<Rc<TempDir>>, file_rel_p
|
||||||
/// within a struct which has convenience assertion functions about those outputs
|
/// within a struct which has convenience assertion functions about those outputs
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CmdResult {
|
pub struct CmdResult {
|
||||||
|
/// bin_path provided by `TestScenario` or `UCommand`
|
||||||
|
bin_path: String,
|
||||||
|
/// util_name provided by `TestScenario` or `UCommand`
|
||||||
|
util_name: Option<String>,
|
||||||
//tmpd is used for convenience functions for asserts against fixtures
|
//tmpd is used for convenience functions for asserts against fixtures
|
||||||
tmpd: Option<Rc<TempDir>>,
|
tmpd: Option<Rc<TempDir>>,
|
||||||
/// exit status for command (if there is one)
|
/// exit status for command (if there is one)
|
||||||
|
@ -77,6 +81,8 @@ pub struct CmdResult {
|
||||||
|
|
||||||
impl CmdResult {
|
impl CmdResult {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
bin_path: String,
|
||||||
|
util_name: Option<String>,
|
||||||
tmpd: Option<Rc<TempDir>>,
|
tmpd: Option<Rc<TempDir>>,
|
||||||
code: Option<i32>,
|
code: Option<i32>,
|
||||||
success: bool,
|
success: bool,
|
||||||
|
@ -84,6 +90,8 @@ impl CmdResult {
|
||||||
stderr: &[u8],
|
stderr: &[u8],
|
||||||
) -> CmdResult {
|
) -> CmdResult {
|
||||||
CmdResult {
|
CmdResult {
|
||||||
|
bin_path,
|
||||||
|
util_name,
|
||||||
tmpd,
|
tmpd,
|
||||||
code,
|
code,
|
||||||
success,
|
success,
|
||||||
|
@ -1049,6 +1057,8 @@ impl UCommand {
|
||||||
let prog = self.run_no_wait().wait_with_output().unwrap();
|
let prog = self.run_no_wait().wait_with_output().unwrap();
|
||||||
|
|
||||||
CmdResult {
|
CmdResult {
|
||||||
|
bin_path: self.bin_path.clone(),
|
||||||
|
util_name: self.util_name.clone(),
|
||||||
tmpd: self.tmpd.clone(),
|
tmpd: self.tmpd.clone(),
|
||||||
code: prog.status.code(),
|
code: prog.status.code(),
|
||||||
success: prog.status.success(),
|
success: prog.status.success(),
|
||||||
|
@ -1296,6 +1306,8 @@ pub fn expected_result(ts: &TestScenario, args: &[&str]) -> std::result::Result<
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(CmdResult::new(
|
Ok(CmdResult::new(
|
||||||
|
ts.bin_path.as_os_str().to_str().unwrap().to_string(),
|
||||||
|
Some(ts.util_name.clone()),
|
||||||
Some(result.tmpd()),
|
Some(result.tmpd()),
|
||||||
Some(result.code()),
|
Some(result.code()),
|
||||||
result.succeeded(),
|
result.succeeded(),
|
||||||
|
@ -1313,6 +1325,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_code_is() {
|
fn test_code_is() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: Some(32),
|
code: Some(32),
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -1326,6 +1340,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_code_is_fail() {
|
fn test_code_is_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: Some(32),
|
code: Some(32),
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -1338,6 +1354,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_failure() {
|
fn test_failure() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -1351,6 +1369,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_failure_fail() {
|
fn test_failure_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1363,6 +1383,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_success() {
|
fn test_success() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1376,6 +1398,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_success_fail() {
|
fn test_success_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -1388,6 +1412,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_stderr_output() {
|
fn test_no_stderr_output() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1402,6 +1428,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_no_stderr_fail() {
|
fn test_no_stderr_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1416,6 +1444,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_no_stdout_fail() {
|
fn test_no_stdout_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1429,6 +1459,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_std_does_not_contain() {
|
fn test_std_does_not_contain() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1443,6 +1475,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_stdout_does_not_contain_fail() {
|
fn test_stdout_does_not_contain_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1457,6 +1491,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_stderr_does_not_contain_fail() {
|
fn test_stderr_does_not_contain_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1470,6 +1506,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stdout_matches() {
|
fn test_stdout_matches() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1486,6 +1524,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_stdout_matches_fail() {
|
fn test_stdout_matches_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1501,6 +1541,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_stdout_not_matches_fail() {
|
fn test_stdout_not_matches_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1515,6 +1557,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalized_newlines_stdout_is() {
|
fn test_normalized_newlines_stdout_is() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -1531,6 +1575,8 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_normalized_newlines_stdout_is_fail() {
|
fn test_normalized_newlines_stdout_is_fail() {
|
||||||
let res = CmdResult {
|
let res = CmdResult {
|
||||||
|
bin_path: "".into(),
|
||||||
|
util_name: None,
|
||||||
tmpd: None,
|
tmpd: None,
|
||||||
code: None,
|
code: None,
|
||||||
success: true,
|
success: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue