From 0304391bc530c86c59dc9a8b03109ea67fa9d00d Mon Sep 17 00:00:00 2001 From: Tanmay Patil Date: Tue, 23 Apr 2024 22:44:06 +0530 Subject: [PATCH] Create test files in temporary directory --- tests/integration.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index f7174fd..3e14c3c 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -8,8 +8,7 @@ use diffutilslib::assert_diff_eq; use predicates::prelude::*; use std::fs::File; use std::io::Write; -use std::path::PathBuf; -use tempfile::NamedTempFile; +use tempfile::{tempdir, NamedTempFile}; // Integration tests for the diffutils command @@ -238,14 +237,13 @@ fn read_from_stdin() -> Result<(), Box> { } #[test] -fn read_from_directory() -> Result<(), Box> { - let target = PathBuf::from("target/integration"); - let _ = std::fs::create_dir(&target); +fn compare_file_to_directory() -> Result<(), Box> { + let tmp_dir = tempdir()?; - let directory = target.join("d"); + let directory = tmp_dir.path().join("d"); let _ = std::fs::create_dir(&directory); - let a_path = target.join("a"); + let a_path = tmp_dir.path().join("a"); let mut a = File::create(&a_path).unwrap(); a.write_all(b"a\n").unwrap();