on master help sign in
Add integration tests for clircle cycle detection
ace655eNiklas Mohrin
tests/examples/cycle.txtnew file

No changes to the content.

tests/integration_tests.rs+34−3
@@ -1,11 +1,14 @@
1−use assert_cmd::Command;
1+use assert_cmd::assert::OutputAssertExt;
2+use assert_cmd::cargo::CommandCargoExt;
2use predicates::{prelude::predicate, str::PredicateStrExt};
3use predicates::{prelude::predicate, str::PredicateStrExt};
4+use std::fs::File;
3use std::path::Path;
5use std::path::Path;
6+use std::process::{Command, Stdio};
4use std::str::from_utf8;
7use std::str::from_utf8;
5
8
6const EXAMPLES_DIR: &str = "tests/examples";
9const EXAMPLES_DIR: &str = "tests/examples";
7
10
8−fn bat_with_config() -> Command {
11+fn bat_raw_command() -> Command {
9 let mut cmd = Command::cargo_bin("bat").unwrap();
12 let mut cmd = Command::cargo_bin("bat").unwrap();
10 cmd.current_dir("tests/examples");
13 cmd.current_dir("tests/examples");
11 cmd.env_remove("PAGER");
14 cmd.env_remove("PAGER");
@@ -17,7 +20,11 @@ fn bat_with_config() -> Command {
17 cmd
20 cmd
18}
21}
19
22
23+fn bat_with_config() -> assert_cmd::Command {
24+ assert_cmd::Command::from_std(bat_raw_command())
25+}
26+
20−fn bat() -> Command {
27+fn bat() -> assert_cmd::Command {
21 let mut cmd = bat_with_config();
28 let mut cmd = bat_with_config();
22 cmd.arg("--no-config");
29 cmd.arg("--no-config");
23 cmd
30 cmd
@@ -189,6 +196,30 @@ fn line_range_multiple() {
189 .stdout("line 1\nline 2\nline 4\n");
196 .stdout("line 1\nline 2\nline 4\n");
190}
197}
191
198
199+#[test]
200+fn basic_io_cycle() {
201+ let file_out = Stdio::from(File::open("tests/examples/cycle.txt").unwrap());
202+ bat_raw_command()
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_raw_command()
215+ .stdin(file_in)
216+ .arg("test.txt")
217+ .arg("-")
218+ .stdout(file_out)
219+ .assert()
220+ .failure();
221+}
222+
192#[test]
223#[test]
193fn tabs_numbers() {
224fn tabs_numbers() {
194 bat()
225 bat()