this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 182 lines 5.4 kB view raw
1use assert_cmd::prelude::*; 2use assert_fs::prelude::*; 3use predicates::prelude::*; 4use std::process::Command; 5 6mod common; 7use common::*; 8 9/// Roundtrip helper: compress two files into `archive.<ext>` and extract into 10/// a fresh directory, asserting that the original files come back identical. 11fn shortcut_roundtrip(ext: &str) -> Result<(), Box<dyn std::error::Error>> { 12 let file = create_test_file("test.txt", "garbage data for testing")?; 13 let file2 = create_test_file("test2.txt", "more garbage data for testing")?; 14 let working_dir = create_working_dir()?; 15 let archive_name = format!("archive.{ext}"); 16 let archive = working_dir.child(&archive_name); 17 archive.assert(predicate::path::missing()); 18 19 let mut compress = Command::cargo_bin("cmprss")?; 20 compress 21 .current_dir(&working_dir) 22 .arg("--ignore-pipes") 23 .arg(file.path()) 24 .arg(file2.path()) 25 .arg(&archive_name); 26 compress.assert().success(); 27 archive.assert(predicate::path::is_file()); 28 29 let extract_dir = create_working_dir()?; 30 let mut extract = Command::cargo_bin("cmprss")?; 31 extract 32 .current_dir(&extract_dir) 33 .arg("--ignore-pipes") 34 .arg(archive.path()); 35 extract.assert().success(); 36 37 assert_files_equal(file.path(), &extract_dir.child("test.txt")); 38 assert_files_equal(file2.path(), &extract_dir.child("test2.txt")); 39 40 Ok(()) 41} 42 43mod shortcuts { 44 use super::*; 45 46 #[test] 47 fn tgz() -> Result<(), Box<dyn std::error::Error>> { 48 shortcut_roundtrip("tgz") 49 } 50 51 #[test] 52 fn tbz() -> Result<(), Box<dyn std::error::Error>> { 53 shortcut_roundtrip("tbz") 54 } 55 56 #[test] 57 fn tbz2() -> Result<(), Box<dyn std::error::Error>> { 58 shortcut_roundtrip("tbz2") 59 } 60 61 #[test] 62 fn txz() -> Result<(), Box<dyn std::error::Error>> { 63 shortcut_roundtrip("txz") 64 } 65 66 #[test] 67 fn tzst() -> Result<(), Box<dyn std::error::Error>> { 68 shortcut_roundtrip("tzst") 69 } 70} 71 72/// Roundtrip helper: pass `format` as the leading positional (e.g. 73/// `cmprss tar.gz src/ out.tar.gz`), then extract with the same format 74/// and compare contents. 75fn format_prefix_roundtrip( 76 format: &str, 77 archive_ext: &str, 78) -> Result<(), Box<dyn std::error::Error>> { 79 let file = create_test_file("test.txt", "garbage data for testing")?; 80 let file2 = create_test_file("test2.txt", "more garbage data for testing")?; 81 let working_dir = create_working_dir()?; 82 let archive_name = format!("archive.{archive_ext}"); 83 let archive = working_dir.child(&archive_name); 84 archive.assert(predicate::path::missing()); 85 86 let mut compress = Command::cargo_bin("cmprss")?; 87 compress 88 .current_dir(&working_dir) 89 .arg("--ignore-pipes") 90 .arg(format) 91 .arg(file.path()) 92 .arg(file2.path()) 93 .arg(&archive_name); 94 compress.assert().success(); 95 archive.assert(predicate::path::is_file()); 96 97 let extract_dir = create_working_dir()?; 98 let mut extract = Command::cargo_bin("cmprss")?; 99 extract 100 .current_dir(&extract_dir) 101 .arg("--ignore-pipes") 102 .arg(format) 103 .arg("--extract") 104 .arg(archive.path()); 105 extract.assert().success(); 106 107 assert_files_equal(file.path(), &extract_dir.child("test.txt")); 108 assert_files_equal(file2.path(), &extract_dir.child("test2.txt")); 109 110 Ok(()) 111} 112 113mod format_prefix { 114 use super::*; 115 116 /// When the user explicitly names a shortcut format like `tgz`, the 117 /// inferred output filename should keep that spelling instead of the 118 /// expanded `.tar.gz` form. 119 #[test] 120 fn shortcut_preserves_extension_in_default_name() -> Result<(), Box<dyn std::error::Error>> { 121 let working_dir = create_working_dir()?; 122 let src = working_dir.child("payload"); 123 src.create_dir_all()?; 124 src.child("a.txt").write_str("hello")?; 125 126 let mut compress = Command::cargo_bin("cmprss")?; 127 compress 128 .current_dir(&working_dir) 129 .arg("--ignore-pipes") 130 .arg("tgz") 131 .arg("payload"); 132 compress.assert().success(); 133 134 working_dir 135 .child("payload.tgz") 136 .assert(predicate::path::is_file()); 137 working_dir 138 .child("payload.tar.gz") 139 .assert(predicate::path::missing()); 140 Ok(()) 141 } 142 143 #[test] 144 fn tar_gz() -> Result<(), Box<dyn std::error::Error>> { 145 format_prefix_roundtrip("tar.gz", "tar.gz") 146 } 147 148 #[test] 149 fn tgz() -> Result<(), Box<dyn std::error::Error>> { 150 format_prefix_roundtrip("tgz", "tgz") 151 } 152 153 #[test] 154 fn tar_xz() -> Result<(), Box<dyn std::error::Error>> { 155 format_prefix_roundtrip("tar.xz", "tar.xz") 156 } 157 158 #[test] 159 fn txz() -> Result<(), Box<dyn std::error::Error>> { 160 format_prefix_roundtrip("txz", "txz") 161 } 162 163 #[test] 164 fn tar_bz2() -> Result<(), Box<dyn std::error::Error>> { 165 format_prefix_roundtrip("tar.bz2", "tar.bz2") 166 } 167 168 #[test] 169 fn tbz2() -> Result<(), Box<dyn std::error::Error>> { 170 format_prefix_roundtrip("tbz2", "tbz2") 171 } 172 173 #[test] 174 fn tar_zst() -> Result<(), Box<dyn std::error::Error>> { 175 format_prefix_roundtrip("tar.zst", "tar.zst") 176 } 177 178 #[test] 179 fn tzst() -> Result<(), Box<dyn std::error::Error>> { 180 format_prefix_roundtrip("tzst", "tzst") 181 } 182}