fix integration tests

main
blob42 8 months ago
parent d337639a94
commit 1583b06fb9

@ -1,10 +1,24 @@
use std::error::Error; use std::error::Error;
use assert_cmd::Command; use assert_cmd::Command;
use assert_cmd::assert::Assert;
// use assert_cmd::prelude::*; // use assert_cmd::prelude::*;
use std::path::Path; use std::path::Path;
use std::fs::read_to_string; use std::fs::read_to_string;
type TestResult = Result<(), Box<dyn Error>>; type TestResult = Result<(), Box<dyn Error>>;
type AssertResult = Result<Assert, Box<dyn Error>>;
// pub fn args<I, S>(&mut self, args: I) -> &mut Self
// where
// I: IntoIterator<Item = S>,
// S: AsRef<ffi::OsStr>,
// ────────────────────────────────────────────────
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 // empty stdin should return an empty line
#[test] #[test]
@ -49,16 +63,24 @@ fn fail_yargs_mismatch1() -> TestResult {
Ok(()) Ok(())
} }
// n args <= n cols // n args <= n cols
#[test] #[test]
fn cli_pass2() -> TestResult { fn cli_pass2() {
run_args("tests/inputs/input1", &["1", "2", "3", "4", "5", "6"]) 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] #[test]
#[should_panic] #[should_panic]
// more arguments passed than columns // more arguments passed than columns
fn cli_fail1() { // delimiter: space
run_args("tests/inputs/input1", &["1", "2", "3", "4", "5", "6", "7", "8"]).unwrap() 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();
} }

Loading…
Cancel
Save