Skip to content

Commit 6a152cd

Browse files
committed
Add an integration test for reading data from stdin
1 parent b8fada8 commit 6a152cd

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

tests/integration.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
// For the full copyright and license information, please view the LICENSE-*
44
// files that was distributed with this source code.
55

6-
use assert_cmd::prelude::*;
6+
use assert_cmd::cmd::Command;
77
use predicates::prelude::*;
88
use std::io::Write;
9-
use std::process::Command;
109
use tempfile::NamedTempFile;
1110

1211
// Integration tests for the diffutils command
@@ -161,3 +160,46 @@ fn missing_newline() -> Result<(), Box<dyn std::error::Error>> {
161160
.stderr(predicate::str::starts_with("No newline at end of file"));
162161
Ok(())
163162
}
163+
164+
#[test]
165+
fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
166+
let mut file1 = NamedTempFile::new()?;
167+
file1.write_all("foo\n".as_bytes())?;
168+
let mut file2 = NamedTempFile::new()?;
169+
file2.write_all("bar\n".as_bytes())?;
170+
171+
let mut cmd = Command::cargo_bin("diffutils")?;
172+
cmd.arg("-u")
173+
.arg(file1.path())
174+
.arg("-")
175+
.write_stdin("bar\n");
176+
cmd.assert()
177+
.code(predicate::eq(1))
178+
.failure()
179+
.stdout(predicate::eq(format!(
180+
"--- {}\t\n+++ /dev/stdin\t\n@@ -1 +1 @@\n-foo\n+bar\n",
181+
file1.path().to_string_lossy()
182+
)));
183+
184+
let mut cmd = Command::cargo_bin("diffutils")?;
185+
cmd.arg("-u")
186+
.arg("-")
187+
.arg(file2.path())
188+
.write_stdin("foo\n");
189+
cmd.assert()
190+
.code(predicate::eq(1))
191+
.failure()
192+
.stdout(predicate::eq(format!(
193+
"--- /dev/stdin\t\n+++ {}\t\n@@ -1 +1 @@\n-foo\n+bar\n",
194+
file2.path().to_string_lossy()
195+
)));
196+
197+
let mut cmd = Command::cargo_bin("diffutils")?;
198+
cmd.arg("-u").arg("-").arg("-").write_stdin("foo\n");
199+
cmd.assert()
200+
.code(predicate::eq(0))
201+
.success()
202+
.stdout(predicate::str::is_empty());
203+
204+
Ok(())
205+
}

0 commit comments

Comments
 (0)