1 //! Files in common between one or more integration tests
10 use ouch::{cli::Command, commands::run, oof};
12 pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {
13 let dirname = Path::new(filename);
14 let full_path = at.join(dirname);
16 fs::create_dir(&full_path).expect("Failed to create an empty directory");
21 pub fn compress_files(at: &Path, paths_to_compress: &[PathBuf], format: &str) -> PathBuf {
22 let archive_path = String::from("archive.") + format;
23 let archive_path = at.join(archive_path);
25 let command = Command::Compress { files: paths_to_compress.to_vec(), output_path: archive_path.to_path_buf() };
26 run(command, &oof::Flags::default()).expect("Failed to compress test dummy files");
31 pub fn extract_files(archive_path: &Path) -> Vec<PathBuf> {
32 // We will extract in the same folder as the archive
33 // If the archive is at:
34 // /tmp/ouch-testing-tar.Rbq4DusBrtF8/archive.tar
35 // Then the extraction_output_folder will be:
36 // /tmp/ouch-testing-tar.Rbq4DusBrtF8/extraction_results/
37 let mut extraction_output_folder = archive_path.to_path_buf();
38 // Remove the name of the extracted archive
39 assert!(extraction_output_folder.pop());
40 // Add the suffix "results"
41 extraction_output_folder.push("extraction_results");
43 let command = Command::Decompress {
44 files: vec![archive_path.to_owned()],
45 output_folder: Some(extraction_output_folder.clone()),
47 run(command, &oof::Flags::default()).expect("Failed to extract");
49 fs::read_dir(extraction_output_folder).unwrap().map(Result::unwrap).map(|entry| entry.path()).collect()
52 pub fn assert_correct_paths(original: &[PathBuf], extracted: &[PathBuf], format: &str) {
56 "Number of compressed files does not match number of decompressed when testing archive format '{:?}'.",
59 for (original, extracted) in original.iter().zip(extracted) {
60 assert_eq!(original.file_name(), extracted.file_name());