diff options
author | Niklas Mohrin <niklas.mohrin@gmail.com> | 2020-11-08 22:24:14 +0100 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-11-23 14:06:54 +0100 |
commit | 4f0116bee7873033f813d90d86275696c697eae9 (patch) | |
tree | 4810423b9f66f9b7c27ad7f0a4808f605dcc457f | |
parent | 31793cfa6287cb90cc12eb4fbd0c76bd496e91a5 (diff) |
Add cycle detection integration tests
-rw-r--r-- | tests/examples/cycle.txt | 0 | ||||
-rw-r--r-- | tests/integration_tests.rs | 37 |
2 files changed, 34 insertions, 3 deletions
diff --git a/tests/examples/cycle.txt b/tests/examples/cycle.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/examples/cycle.txt diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index ac11efb4..ad3ca9d0 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,11 +1,14 @@ -use assert_cmd::Command; +use assert_cmd::assert::OutputAssertExt; +use assert_cmd::cargo::CommandCargoExt; use predicates::{prelude::predicate, str::PredicateStrExt}; +use std::fs::File; use std::path::Path; +use std::process::{Command, Stdio}; use std::str::from_utf8; const EXAMPLES_DIR: &str = "tests/examples"; -fn bat_with_config() -> Command { +fn bat_as_std() -> Command { let mut cmd = Command::cargo_bin("bat").unwrap(); cmd.current_dir("tests/examples"); cmd.env_remove("PAGER"); @@ -17,7 +20,11 @@ fn bat_with_config() -> Command { cmd } -fn bat() -> Command { +fn bat_with_config() -> assert_cmd::Command { + assert_cmd::Command::from_std(bat_as_std()) +} + +fn bat() -> assert_cmd::Command { let mut cmd = bat_with_config(); cmd.arg("--no-config"); cmd @@ -190,6 +197,30 @@ fn line_range_multiple() { } #[test] +fn basic_io_cycle() { + let file_out = Stdio::from(File::open("tests/examples/cycle.txt").unwrap()); + bat_as_std() + .arg("test.txt") + .arg("cycle.txt") + .stdout(file_out) + .assert() + .failure(); +} + +#[test] +fn stdin_to_stdout_cycle() { + let file_out = Stdio::from(File::open("tests/examples/cycle.txt").unwrap()); + let file_in = Stdio::from(File::open("tests/examples/cycle.txt").unwrap()); + bat_as_std() + .stdin(file_in) + .arg("test.txt") + .arg("-") + .stdout(file_out) + .assert() + .failure(); +} + +#[test] fn tabs_numbers() { bat() .arg("tabs.txt") |