Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Jul 1, 2024
1 parent 9936bb3 commit e2c306e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions prqlc/prqlc/tests/integration/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn format() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");

// Copy files from project_path() to temp_dir
copy_dir_contents(&project_path(), temp_dir.path()).expect("Failed to copy directory contents");
copy_dir(&project_path(), temp_dir.path());

// Run fmt command on the temp directory
let _result = prqlc_command()
Expand All @@ -383,19 +383,17 @@ fn format() {
compare_directories(&project_path(), temp_dir.path());
}

fn copy_dir_contents(src: &Path, dst: &Path) -> std::io::Result<()> {
for entry in WalkDir::new(src).into_iter().filter_map(|e| e.ok()) {
fn copy_dir(src: &Path, dst: &Path) {
for entry in WalkDir::new(src) {
let entry = entry.unwrap();
let path = entry.path();
if path.is_file() {
let relative_path = path.strip_prefix(src).unwrap();
let dst_path = dst.join(relative_path);
if let Some(parent) = dst_path.parent() {
fs::create_dir_all(parent)?;
}
fs::copy(path, dst_path)?;
let target_path = dst.join(relative_path);
fs::create_dir_all(target_path.parent().unwrap()).unwrap();
fs::copy(path, target_path).unwrap();
}
}
Ok(())
}

fn compare_directories(dir1: &Path, dir2: &Path) {
Expand All @@ -405,7 +403,12 @@ fn compare_directories(dir1: &Path, dir2: &Path) {
let relative_path = path1.strip_prefix(dir1).unwrap();
let path2 = dir2.join(relative_path);

assert!(path2.exists());
assert!(
path2.exists(),
"File {:?} doesn't exist in the formatted directory",
relative_path
);

similar_asserts::assert_eq!(
fs::read_to_string(path1).unwrap(),
fs::read_to_string(path2).unwrap()
Expand Down

0 comments on commit e2c306e

Please sign in to comment.