|
3 | 3 | // For the full copyright and license information, please view the LICENSE-* |
4 | 4 | // files that was distributed with this source code. |
5 | 5 |
|
6 | | -use assert_cmd::prelude::*; |
| 6 | +use assert_cmd::cmd::Command; |
7 | 7 | use predicates::prelude::*; |
8 | 8 | use std::io::Write; |
9 | | -use std::process::Command; |
10 | 9 | use tempfile::NamedTempFile; |
11 | 10 |
|
12 | 11 | // Integration tests for the diffutils command |
@@ -161,3 +160,46 @@ fn missing_newline() -> Result<(), Box<dyn std::error::Error>> { |
161 | 160 | .stderr(predicate::str::starts_with("No newline at end of file")); |
162 | 161 | Ok(()) |
163 | 162 | } |
| 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