1 //! Files in common between one or more integration tests
5 use std::path::{Path, PathBuf};
8 use ouch::{commands::run, Opts, QuestionPolicy, Subcommand};
10 pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {
11 let dirname = Path::new(filename);
12 let full_path = at.join(dirname);
14 fs::create_dir(&full_path).expect("Failed to create an empty directory");
19 pub fn compress_files(at: &Path, paths_to_compress: &[PathBuf], format: &str) -> PathBuf {
20 let archive_path = String::from("archive.") + format;
21 let archive_path = at.join(archive_path);
26 cmd: Subcommand::Compress { files: paths_to_compress.to_vec(), output: archive_path.clone() },
28 run(command, QuestionPolicy::Ask).expect("Failed to compress test dummy files");
33 pub fn extract_files(archive_path: &Path) -> Vec<PathBuf> {
34 // We will extract in the same folder as the archive
35 // If the archive is at:
36 // /tmp/ouch-testing-tar.Rbq4DusBrtF8/archive.tar
37 // Then the extraction_output_folder will be:
38 // /tmp/ouch-testing-tar.Rbq4DusBrtF8/extraction_results/
39 let mut extraction_output_folder = archive_path.to_path_buf();
40 // Remove the name of the extracted archive
41 assert!(extraction_output_folder.pop());
42 // Add the suffix "results"
43 extraction_output_folder.push("extraction_results");
48 cmd: Subcommand::Decompress {
49 files: vec![archive_path.to_owned()],
50 output_dir: Some(extraction_output_folder.clone()),
53 run(command, QuestionPolicy::Ask).expect("Failed to extract");
55 fs::read_dir(extraction_output_folder).unwrap().map(Result::unwrap).map(|entry| entry.path()).collect()
58 pub fn assert_correct_paths(original: &[PathBuf], extracted: &[PathBuf], format: &str) {
62 "Number of compressed files does not match number of decompressed when testing archive format '{:?}'.",
65 for (original, extracted) in original.iter().zip(extracted) {
66 assert_eq!(original.file_name(), extracted.file_name());