From 1583b06fb9cd98b5a7f6d2734e027e652200fbcf Mon Sep 17 00:00:00 2001 From: blob42 Date: Sat, 7 Oct 2023 02:02:43 +0200 Subject: [PATCH] fix integration tests --- tests/cli.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tests/cli.rs b/tests/cli.rs index 2ab90c8..2843d28 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,10 +1,24 @@ use std::error::Error; use assert_cmd::Command; +use assert_cmd::assert::Assert; // use assert_cmd::prelude::*; use std::path::Path; use std::fs::read_to_string; type TestResult = Result<(), Box>; +type AssertResult = Result>; + + +// pub fn args(&mut self, args: I) -> &mut Self +// where +// I: IntoIterator, +// S: AsRef, +// ──────────────────────────────────────────────── +fn run_command(test_file: &str, cmd: &mut Command) -> AssertResult +{ + let input = Path::new(test_file); + Ok(cmd.pipe_stdin(input)?.assert()) +} // empty stdin should return an empty line #[test] @@ -49,16 +63,24 @@ fn fail_yargs_mismatch1() -> TestResult { Ok(()) } - // n args <= n cols #[test] -fn cli_pass2() -> TestResult { - run_args("tests/inputs/input1", &["1", "2", "3", "4", "5", "6"]) +fn cli_pass2() { + let mut cmd = Command::cargo_bin("yargs").unwrap(); + cmd.args(&["-d", r"\s"]) + .args(&["1", "2", "3", "4", "5", "6"]); + run_command("tests/inputs/input1", &mut cmd).unwrap() + .success(); } #[test] #[should_panic] // more arguments passed than columns -fn cli_fail1() { - run_args("tests/inputs/input1", &["1", "2", "3", "4", "5", "6", "7", "8"]).unwrap() +// delimiter: space +fn cli_fail1() { + let mut cmd = Command::cargo_bin("yargs").unwrap(); + cmd.args(&["-d", r"\s"]) + .args(&["1", "2", "3", "4", "5", "6", "7", "8"]); + run_command("tests/inputs/input1", &mut cmd).unwrap() + .failure(); }