Skip to content

Commit ec60d84

Browse files
committed
Add cycle detection integration tests
1 parent aa2ae19 commit ec60d84

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

tests/examples/cycle.txt

Whitespace-only changes.

tests/integration_tests.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
use assert_cmd::Command;
1+
use assert_cmd::assert::OutputAssertExt;
2+
use assert_cmd::cargo::CommandCargoExt;
23
use predicates::{prelude::predicate, str::PredicateStrExt};
4+
use std::fs::File;
35
use std::path::Path;
6+
use std::process::{Command, Stdio};
47
use std::str::from_utf8;
58

69
const EXAMPLES_DIR: &str = "tests/examples";
710

8-
fn bat_with_config() -> Command {
11+
fn bat_as_std() -> Command {
912
let mut cmd = Command::cargo_bin("bat").unwrap();
1013
cmd.current_dir("tests/examples");
1114
cmd.env_remove("PAGER");
@@ -17,7 +20,11 @@ fn bat_with_config() -> Command {
1720
cmd
1821
}
1922

20-
fn bat() -> Command {
23+
fn bat_with_config() -> assert_cmd::Command {
24+
assert_cmd::Command::from_std(bat_as_std())
25+
}
26+
27+
fn bat() -> assert_cmd::Command {
2128
let mut cmd = bat_with_config();
2229
cmd.arg("--no-config");
2330
cmd
@@ -189,6 +196,30 @@ fn line_range_multiple() {
189196
.stdout("line 1\nline 2\nline 4\n");
190197
}
191198

199+
#[test]
200+
fn basic_io_cycle() {
201+
let file_out = Stdio::from(File::open("tests/examples/cycle.txt").unwrap());
202+
bat_as_std()
203+
.arg("test.txt")
204+
.arg("cycle.txt")
205+
.stdout(file_out)
206+
.assert()
207+
.failure();
208+
}
209+
210+
#[test]
211+
fn stdin_to_stdout_cycle() {
212+
let file_out = Stdio::from(File::open("tests/examples/cycle.txt").unwrap());
213+
let file_in = Stdio::from(File::open("tests/examples/cycle.txt").unwrap());
214+
bat_as_std()
215+
.stdin(file_in)
216+
.arg("test.txt")
217+
.arg("-")
218+
.stdout(file_out)
219+
.assert()
220+
.failure();
221+
}
222+
192223
#[test]
193224
fn tabs_numbers() {
194225
bat()

0 commit comments

Comments
 (0)