@@ -1249,3 +1249,51 @@ fn extra_operand_without_double_dash() -> Result<(), Box<dyn std::error::Error>> |
1249 | 1249 | .stderr("diff: extra operand 'extra'\ndiff: Try 'diff --help' for more information.\n"); |
1250 | 1250 | Ok(()) |
1251 | 1251 | } |
| 1252 | + |
| 1253 | +#[test] |
| 1254 | +fn trailing_context_without_final_newlines() -> Result<(), Box<dyn std::error::Error>> { |
| 1255 | + let mut file1 = NamedTempFile::new()?; |
| 1256 | + file1.write_all(b"1\n2\n3\n4\n5\n6\n7\n8")?; |
| 1257 | + let mut file2 = NamedTempFile::new()?; |
| 1258 | + file2.write_all(b"1\nX\n3\n4\n5\n6\n7\n8")?; |
| 1259 | + |
| 1260 | + for (format, hunk) in [ |
| 1261 | + ("-u", "@@ -1,5 +1,5 @@\n 1\n-2\n+X\n 3\n 4\n 5\n"), |
| 1262 | + ( |
| 1263 | + "-c", |
| 1264 | + "*** 1,5 ****\n 1\n! 2\n 3\n 4\n 5\n--- 1,5 ----\n 1\n! X\n 3\n 4\n 5\n", |
| 1265 | + ), |
| 1266 | + ] { |
| 1267 | + let mut cmd = cargo_bin_cmd!("diffutils"); |
| 1268 | + cmd.arg("diff") |
| 1269 | + .arg(format) |
| 1270 | + .arg(file1.path()) |
| 1271 | + .arg(file2.path()); |
| 1272 | + cmd.assert() |
| 1273 | + .code(predicate::eq(1)) |
| 1274 | + .stdout(predicate::str::ends_with(hunk)); |
| 1275 | + } |
| 1276 | + |
| 1277 | + // the last line is still shown when it is within the trailing context |
| 1278 | + let mut cmd = cargo_bin_cmd!("diffutils"); |
| 1279 | + cmd.arg("diff") |
| 1280 | + .arg("-U5") |
| 1281 | + .arg(file1.path()) |
| 1282 | + .arg(file2.path()); |
| 1283 | + cmd.assert() |
| 1284 | + .code(predicate::eq(1)) |
| 1285 | + .stdout(predicate::str::ends_with( |
| 1286 | + "@@ -1,7 +1,7 @@\n 1\n-2\n+X\n 3\n 4\n 5\n 6\n 7\n", |
| 1287 | + )); |
| 1288 | + let mut cmd = cargo_bin_cmd!("diffutils"); |
| 1289 | + cmd.arg("diff") |
| 1290 | + .arg("-U6") |
| 1291 | + .arg(file1.path()) |
| 1292 | + .arg(file2.path()); |
| 1293 | + cmd.assert() |
| 1294 | + .code(predicate::eq(1)) |
| 1295 | + .stdout(predicate::str::ends_with( |
| 1296 | + "@@ -1,8 +1,8 @@\n 1\n-2\n+X\n 3\n 4\n 5\n 6\n 7\n 8\n\\ No newline at end of file\n", |
| 1297 | + )); |
| 1298 | + Ok(()) |
| 1299 | +} |