Skip to content

Commit

Permalink
Add tests for diff FILE DIRECTORY
Browse files Browse the repository at this point in the history
  • Loading branch information
TanmayPatil105 committed Apr 20, 2024
1 parent 7dacdb3 commit 46245f3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {

#[test]
fn read_from_directory() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("diffutils")?;

let target = "target/integration";
let _ = std::fs::create_dir(target);
let directory = &format!("{target}/d");
Expand All @@ -249,6 +247,7 @@ fn read_from_directory() -> Result<(), Box<dyn std::error::Error>> {
let mut da = File::create(&format!("{directory}/a")).unwrap();
da.write_all(b"da\n").unwrap();

let mut cmd = Command::cargo_bin("diffutils")?;
cmd.arg("-u")
.arg(&format!("{target}/d"))
.arg(&format!("{target}/a"));
Expand All @@ -263,5 +262,20 @@ fn read_from_directory() -> Result<(), Box<dyn std::error::Error>> {
)
);

let mut cmd = Command::cargo_bin("diffutils")?;
cmd.arg("-u")
.arg(&format!("{target}/a"))
.arg(&format!("{target}/d"));
cmd.assert().code(predicate::eq(1)).failure();

let output = cmd.output().unwrap().stdout;
assert_diff_eq!(
output,
format!(
"--- {}/a\tTIMESTAMP\n+++ {}/d/a\tTIMESTAMP\n@@ -1 +1 @@\n-a\n+da\n",
target, target
)
);

Ok(())
}

0 comments on commit 46245f3

Please sign in to comment.