fix integration tests

main
blob42 7 months ago
parent d337639a94
commit 1583b06fb9

@ -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<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
#[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();
}

Loading…
Cancel
Save