this repo has no description
0
fork

Configure Feed

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

test: move comparison tests into Rust integration suite

+874 -827
+4
Cargo.toml
··· 23 23 assert_cmd = "2.0.11" 24 24 assert_fs = "1.0.12" 25 25 predicates = "3.0.2" 26 + 27 + [features] 28 + default = ["interop"] 29 + interop = []
+1 -1
Taskfile.yml
··· 71 71 coverage: 72 72 desc: Run coverage 73 73 aliases: [cov] 74 - cmd: cargo tarpaulin --skip-clean --output-dir coverage --out lcov 74 + cmd: cargo tarpaulin --skip-clean --include-tests --output-dir coverage --out lcov --no-default-features
+1 -1
bin/test.sh
··· 57 57 58 58 # Run cmprss using cargo to test the current version 59 59 cmprss() { 60 - cargo run --release --quiet -- "$@" 60 + cargo run --release --quiet -- "$1" --ignore-pipes "${@:2}" 61 61 } 62 62 63 63 test_tar() {
+1 -1
flake.nix
··· 96 96 cmprss-tarpaulin = craneLib.cargoTarpaulin (commonArgs 97 97 // { 98 98 # Use lcov output as thats far more widely supported 99 - cargoTarpaulinExtraArgs = "--skip-clean --output-dir $out --out lcov"; 99 + cargoTarpaulinExtraArgs = "--skip-clean --include-tests --output-dir $out --out lcov"; 100 100 }); 101 101 } 102 102 // {
+826 -824
tests/cli.rs
··· 1 - use assert_cmd::prelude::*; 2 - use assert_fs::prelude::*; 3 - use predicates::prelude::*; 4 - use std::{ 5 - fs::File, 6 - process::{Command, Stdio}, 7 - }; 1 + mod cli { 2 + use assert_cmd::prelude::*; 3 + use assert_fs::prelude::*; 4 + use predicates::prelude::*; 5 + use std::{ 6 + fs::File, 7 + process::{Command, Stdio}, 8 + }; 8 9 9 - /// Tar roundtrip with a single file 10 - /// 11 - /// ``` bash 12 - /// cmprss tar test.txt archive.tar 13 - /// cmprss tar --extract archive.tar . 14 - /// ``` 15 - #[test] 16 - fn tar_roundtrip_explicit() -> Result<(), Box<dyn std::error::Error>> { 17 - let file = assert_fs::NamedTempFile::new("test.txt")?; 18 - file.write_str("garbage data for testing")?; 19 - let working_dir = assert_fs::TempDir::new()?; 20 - let archive = working_dir.child("archive.tar"); 21 - archive.assert(predicate::path::missing()); 10 + /// Tar roundtrip with a single file 11 + /// 12 + /// ``` bash 13 + /// cmprss tar test.txt archive.tar 14 + /// cmprss tar --extract archive.tar . 15 + /// ``` 16 + #[test] 17 + fn tar_roundtrip_explicit() -> Result<(), Box<dyn std::error::Error>> { 18 + let file = assert_fs::NamedTempFile::new("test.txt")?; 19 + file.write_str("garbage data for testing")?; 20 + let working_dir = assert_fs::TempDir::new()?; 21 + let archive = working_dir.child("archive.tar"); 22 + archive.assert(predicate::path::missing()); 22 23 23 - let mut compress = Command::cargo_bin("cmprss")?; 24 - compress.arg("tar").arg(file.path()).arg(archive.path()); 25 - compress.assert().success(); 26 - archive.assert(predicate::path::is_file()); 24 + let mut compress = Command::cargo_bin("cmprss")?; 25 + compress.arg("tar").arg(file.path()).arg(archive.path()); 26 + compress.assert().success(); 27 + archive.assert(predicate::path::is_file()); 27 28 28 - let mut extract = Command::cargo_bin("cmprss")?; 29 - extract 30 - .arg("tar") 31 - .arg("--extract") 32 - .arg(archive.path()) 33 - .arg(working_dir.path()); 34 - extract.assert().success(); 29 + let mut extract = Command::cargo_bin("cmprss")?; 30 + extract 31 + .arg("tar") 32 + .arg("--extract") 33 + .arg(archive.path()) 34 + .arg(working_dir.path()); 35 + extract.assert().success(); 35 36 36 - // Assert the files are identical 37 - working_dir 38 - .child("test.txt") 39 - .assert(predicate::path::eq_file(file.path())); 37 + // Assert the files are identical 38 + working_dir 39 + .child("test.txt") 40 + .assert(predicate::path::eq_file(file.path())); 40 41 41 - Ok(()) 42 - } 42 + Ok(()) 43 + } 43 44 44 - /// Tar roundtrip with multiple files 45 - /// 46 - /// ``` bash 47 - /// cmprss tar test.txt test2.txt archive.tar 48 - /// cmprss tar --extract archive.tar . 49 - /// ``` 50 - #[test] 51 - fn tar_roundtrip_explicit_two() -> Result<(), Box<dyn std::error::Error>> { 52 - let file = assert_fs::NamedTempFile::new("test.txt")?; 53 - file.write_str("garbage data for testing")?; 54 - let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 55 - file2.write_str("more garbage data for testing")?; 56 - let working_dir = assert_fs::TempDir::new()?; 57 - let archive = working_dir.child("archive.tar"); 58 - archive.assert(predicate::path::missing()); 45 + /// Tar roundtrip with multiple files 46 + /// 47 + /// ``` bash 48 + /// cmprss tar test.txt test2.txt archive.tar 49 + /// cmprss tar --extract archive.tar . 50 + /// ``` 51 + #[test] 52 + fn tar_roundtrip_explicit_two() -> Result<(), Box<dyn std::error::Error>> { 53 + let file = assert_fs::NamedTempFile::new("test.txt")?; 54 + file.write_str("garbage data for testing")?; 55 + let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 56 + file2.write_str("more garbage data for testing")?; 57 + let working_dir = assert_fs::TempDir::new()?; 58 + let archive = working_dir.child("archive.tar"); 59 + archive.assert(predicate::path::missing()); 59 60 60 - let mut compress = Command::cargo_bin("cmprss")?; 61 - compress 62 - .arg("tar") 63 - .arg(file.path()) 64 - .arg(file2.path()) 65 - .arg(archive.path()); 66 - compress.assert().success(); 67 - archive.assert(predicate::path::is_file()); 61 + let mut compress = Command::cargo_bin("cmprss")?; 62 + compress 63 + .arg("tar") 64 + .arg(file.path()) 65 + .arg(file2.path()) 66 + .arg(archive.path()); 67 + compress.assert().success(); 68 + archive.assert(predicate::path::is_file()); 68 69 69 - let mut extract = Command::cargo_bin("cmprss")?; 70 - extract 71 - .arg("tar") 72 - .arg("--extract") 73 - .arg(archive.path()) 74 - .arg(working_dir.path()); 75 - extract.assert().success(); 70 + let mut extract = Command::cargo_bin("cmprss")?; 71 + extract 72 + .arg("tar") 73 + .arg("--extract") 74 + .arg(archive.path()) 75 + .arg(working_dir.path()); 76 + extract.assert().success(); 76 77 77 - // Assert the files are identical 78 - working_dir 79 - .child("test.txt") 80 - .assert(predicate::path::eq_file(file.path())); 81 - working_dir 82 - .child("test2.txt") 83 - .assert(predicate::path::eq_file(file2.path())); 78 + // Assert the files are identical 79 + working_dir 80 + .child("test.txt") 81 + .assert(predicate::path::eq_file(file.path())); 82 + working_dir 83 + .child("test2.txt") 84 + .assert(predicate::path::eq_file(file2.path())); 84 85 85 - Ok(()) 86 - } 86 + Ok(()) 87 + } 87 88 88 - /// Tar roundtrip with a single file inferring output filename 89 - /// Compressing: output = './test.txt.tar' 90 - /// Extracting: output = '.' 91 - /// 92 - /// ``` bash 93 - /// cmprss tar test.txt 94 - /// cmprss tar --extract test.txt.tar 95 - /// ``` 96 - #[test] 97 - fn tar_roundtrip_implicit() -> Result<(), Box<dyn std::error::Error>> { 98 - let file = assert_fs::NamedTempFile::new("test.txt")?; 99 - file.write_str("garbage data for testing")?; 100 - let working_dir = assert_fs::TempDir::new()?.into_persistent(); 101 - let archive = working_dir.child("test.txt.tar"); 102 - archive.assert(predicate::path::missing()); 89 + /// Tar roundtrip with a single file inferring output filename 90 + /// Compressing: output = './test.txt.tar' 91 + /// Extracting: output = '.' 92 + /// 93 + /// ``` bash 94 + /// cmprss tar test.txt 95 + /// cmprss tar --extract test.txt.tar 96 + /// ``` 97 + #[test] 98 + fn tar_roundtrip_implicit() -> Result<(), Box<dyn std::error::Error>> { 99 + let file = assert_fs::NamedTempFile::new("test.txt")?; 100 + file.write_str("garbage data for testing")?; 101 + let working_dir = assert_fs::TempDir::new()?.into_persistent(); 102 + let archive = working_dir.child("test.txt.tar"); 103 + archive.assert(predicate::path::missing()); 103 104 104 - let mut compress = Command::cargo_bin("cmprss")?; 105 - compress 106 - .current_dir(&working_dir) 107 - .arg("tar") 108 - .arg("--ignore-pipes") 109 - .arg(file.path()); 110 - compress.assert().success(); 111 - archive.assert(predicate::path::is_file()); 105 + let mut compress = Command::cargo_bin("cmprss")?; 106 + compress 107 + .current_dir(&working_dir) 108 + .arg("tar") 109 + .arg("--ignore-pipes") 110 + .arg(file.path()); 111 + compress.assert().success(); 112 + archive.assert(predicate::path::is_file()); 112 113 113 - let mut extract = Command::cargo_bin("cmprss")?; 114 - extract 115 - .current_dir(&working_dir) 116 - .arg("tar") 117 - .arg("--ignore-pipes") 118 - .arg("--extract") 119 - .arg(archive.path()); 120 - extract.assert().success(); 114 + let mut extract = Command::cargo_bin("cmprss")?; 115 + extract 116 + .current_dir(&working_dir) 117 + .arg("tar") 118 + .arg("--ignore-pipes") 119 + .arg("--extract") 120 + .arg(archive.path()); 121 + extract.assert().success(); 121 122 122 - // Assert the files are identical 123 - working_dir 124 - .child("test.txt") 125 - .assert(predicate::path::eq_file(file.path())); 123 + // Assert the files are identical 124 + working_dir 125 + .child("test.txt") 126 + .assert(predicate::path::eq_file(file.path())); 126 127 127 - Ok(()) 128 - } 128 + Ok(()) 129 + } 129 130 130 - /// Tar roundtrip with multiple files inferring output 131 - /// Uses the first file's name to generate the output filename 132 - /// Compressing: output = './test.txt.tar' 133 - /// Extracting: output = '.' 134 - /// 135 - /// ``` bash 136 - /// cmprss tar test.txt test2.txt 137 - /// cmprss tar test.txt.tar 138 - /// ``` 139 - #[test] 140 - fn tar_roundtrip_implicit_two() -> Result<(), Box<dyn std::error::Error>> { 141 - let file = assert_fs::NamedTempFile::new("test.txt")?; 142 - file.write_str("garbage data for testing")?; 143 - let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 144 - file2.write_str("more garbage data for testing")?; 145 - let working_dir = assert_fs::TempDir::new()?.into_persistent(); 146 - let archive = working_dir.child("test.txt.tar"); 147 - archive.assert(predicate::path::missing()); 131 + /// Tar roundtrip with multiple files inferring output 132 + /// Uses the first file's name to generate the output filename 133 + /// Compressing: output = './test.txt.tar' 134 + /// Extracting: output = '.' 135 + /// 136 + /// ``` bash 137 + /// cmprss tar test.txt test2.txt 138 + /// cmprss tar test.txt.tar 139 + /// ``` 140 + #[test] 141 + fn tar_roundtrip_implicit_two() -> Result<(), Box<dyn std::error::Error>> { 142 + let file = assert_fs::NamedTempFile::new("test.txt")?; 143 + file.write_str("garbage data for testing")?; 144 + let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 145 + file2.write_str("more garbage data for testing")?; 146 + let working_dir = assert_fs::TempDir::new()?.into_persistent(); 147 + let archive = working_dir.child("test.txt.tar"); 148 + archive.assert(predicate::path::missing()); 148 149 149 - let mut compress = Command::cargo_bin("cmprss")?; 150 - compress 151 - .current_dir(&working_dir) 152 - .arg("tar") 153 - .arg("--ignore-pipes") 154 - .arg(file.path()) 155 - .arg(file2.path()); 156 - compress.assert().success(); 157 - archive.assert(predicate::path::is_file()); 150 + let mut compress = Command::cargo_bin("cmprss")?; 151 + compress 152 + .current_dir(&working_dir) 153 + .arg("tar") 154 + .arg("--ignore-pipes") 155 + .arg(file.path()) 156 + .arg(file2.path()); 157 + compress.assert().success(); 158 + archive.assert(predicate::path::is_file()); 158 159 159 - let mut extract = Command::cargo_bin("cmprss")?; 160 - extract 161 - .current_dir(&working_dir) 162 - .arg("--ignore-pipes") 163 - .arg(archive.path()); 164 - extract.assert().success(); 160 + let mut extract = Command::cargo_bin("cmprss")?; 161 + extract 162 + .current_dir(&working_dir) 163 + .arg("--ignore-pipes") 164 + .arg(archive.path()); 165 + extract.assert().success(); 165 166 166 - // Assert the files are identical 167 - working_dir 168 - .child("test.txt") 169 - .assert(predicate::path::eq_file(file.path())); 170 - working_dir 171 - .child("test2.txt") 172 - .assert(predicate::path::eq_file(file2.path())); 167 + // Assert the files are identical 168 + working_dir 169 + .child("test.txt") 170 + .assert(predicate::path::eq_file(file.path())); 171 + working_dir 172 + .child("test2.txt") 173 + .assert(predicate::path::eq_file(file2.path())); 173 174 174 - Ok(()) 175 - } 175 + Ok(()) 176 + } 176 177 177 - /// Gzip roundtrip using stdin 178 - /// Compressing: input = stdin, output = test.txt.gz 179 - /// Extracting: input = test.txt.gz, output = test.txt 180 - /// 181 - /// ``` bash 182 - /// cat test.txt | cmprss gzip test.txt.gz 183 - /// cmprss gzip --ignore-pipes --extract test.txt.gz 184 - /// ``` 185 - #[test] 186 - fn gzip_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 187 - let file = assert_fs::NamedTempFile::new("test.txt")?; 188 - file.write_str("garbage data for testing")?; 189 - let working_dir = assert_fs::TempDir::new()?; 190 - let archive = working_dir.child("test.txt.gz"); 191 - archive.assert(predicate::path::missing()); 178 + /// Gzip roundtrip using stdin 179 + /// Compressing: input = stdin, output = test.txt.gz 180 + /// Extracting: input = test.txt.gz, output = test.txt 181 + /// 182 + /// ``` bash 183 + /// cat test.txt | cmprss gzip test.txt.gz 184 + /// cmprss gzip --ignore-pipes --extract test.txt.gz 185 + /// ``` 186 + #[test] 187 + fn gzip_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 188 + let file = assert_fs::NamedTempFile::new("test.txt")?; 189 + file.write_str("garbage data for testing")?; 190 + let working_dir = assert_fs::TempDir::new()?; 191 + let archive = working_dir.child("test.txt.gz"); 192 + archive.assert(predicate::path::missing()); 192 193 193 - // Pipe file to stdin 194 - let mut compress = Command::cargo_bin("cmprss")?; 195 - compress 196 - .current_dir(&working_dir) 197 - .arg("gzip") 198 - .arg("test.txt.gz") 199 - .stdin(Stdio::from(File::open(file.path())?)); 200 - compress.assert().success(); 201 - archive.assert(predicate::path::is_file()); 194 + // Pipe file to stdin 195 + let mut compress = Command::cargo_bin("cmprss")?; 196 + compress 197 + .current_dir(&working_dir) 198 + .arg("gzip") 199 + .arg("test.txt.gz") 200 + .stdin(Stdio::from(File::open(file.path())?)); 201 + compress.assert().success(); 202 + archive.assert(predicate::path::is_file()); 202 203 203 - let mut extract = Command::cargo_bin("cmprss")?; 204 - extract 205 - .current_dir(&working_dir) 206 - .arg("gzip") 207 - .arg("--ignore-pipes") 208 - .arg("--extract") 209 - .arg(archive.path()); 210 - extract.assert().success(); 204 + let mut extract = Command::cargo_bin("cmprss")?; 205 + extract 206 + .current_dir(&working_dir) 207 + .arg("gzip") 208 + .arg("--ignore-pipes") 209 + .arg("--extract") 210 + .arg(archive.path()); 211 + extract.assert().success(); 211 212 212 - // Assert the files are identical 213 - working_dir 214 - .child("test.txt") 215 - .assert(predicate::path::eq_file(file.path())); 213 + // Assert the files are identical 214 + working_dir 215 + .child("test.txt") 216 + .assert(predicate::path::eq_file(file.path())); 216 217 217 - Ok(()) 218 - } 218 + Ok(()) 219 + } 219 220 220 - /// Gzip roundtrip using filename inference 221 - /// Compressing: input = stdin, output = default filename (archive.gz) 222 - /// Extracting: input = archive.gz, output = default filename (archive) 223 - /// 224 - /// ``` bash 225 - /// cat test.txt | cmprss gzip 226 - /// cmprss gzip --ignore-pipes --extract archive.gz 227 - /// ``` 228 - #[test] 229 - fn gzip_roundtrip_inferred_output_filenames() -> Result<(), Box<dyn std::error::Error>> { 230 - let file = assert_fs::NamedTempFile::new("test.txt")?; 231 - file.write_str("garbage data for testing")?; 232 - let working_dir = assert_fs::TempDir::new()?; 233 - let archive = working_dir.child("archive.gz"); // default filename 234 - archive.assert(predicate::path::missing()); 221 + /// Gzip roundtrip using filename inference 222 + /// Compressing: input = stdin, output = default filename (archive.gz) 223 + /// Extracting: input = archive.gz, output = default filename (archive) 224 + /// 225 + /// ``` bash 226 + /// cat test.txt | cmprss gzip 227 + /// cmprss gzip --ignore-pipes --extract archive.gz 228 + /// ``` 229 + #[test] 230 + fn gzip_roundtrip_inferred_output_filenames() -> Result<(), Box<dyn std::error::Error>> { 231 + let file = assert_fs::NamedTempFile::new("test.txt")?; 232 + file.write_str("garbage data for testing")?; 233 + let working_dir = assert_fs::TempDir::new()?; 234 + let archive = working_dir.child("archive.gz"); // default filename 235 + archive.assert(predicate::path::missing()); 235 236 236 - // Pipe file to stdin 237 - let mut compress = Command::cargo_bin("cmprss")?; 238 - compress 239 - .current_dir(&working_dir) 240 - .arg("gzip") 241 - .arg("--ignore-stdout") 242 - .stdin(Stdio::from(File::open(file.path())?)); 243 - compress.assert().success(); 244 - archive.assert(predicate::path::is_file()); 237 + // Pipe file to stdin 238 + let mut compress = Command::cargo_bin("cmprss")?; 239 + compress 240 + .current_dir(&working_dir) 241 + .arg("gzip") 242 + .arg("--ignore-stdout") 243 + .stdin(Stdio::from(File::open(file.path())?)); 244 + compress.assert().success(); 245 + archive.assert(predicate::path::is_file()); 245 246 246 - let mut extract = Command::cargo_bin("cmprss")?; 247 - extract 248 - .current_dir(&working_dir) 249 - .arg("gzip") 250 - .arg("--ignore-pipes") 251 - .arg("--extract") 252 - .arg(archive.path()); 253 - extract.assert().success(); 247 + let mut extract = Command::cargo_bin("cmprss")?; 248 + extract 249 + .current_dir(&working_dir) 250 + .arg("gzip") 251 + .arg("--ignore-pipes") 252 + .arg("--extract") 253 + .arg(archive.path()); 254 + extract.assert().success(); 254 255 255 - // Assert the files are identical 256 - working_dir 257 - .child("archive") 258 - .assert(predicate::path::eq_file(file.path())); 256 + // Assert the files are identical 257 + working_dir 258 + .child("archive") 259 + .assert(predicate::path::eq_file(file.path())); 259 260 260 - Ok(()) 261 - } 261 + Ok(()) 262 + } 262 263 263 - /// Xz roundtrip using files 264 - /// Compressing: input = test.txt, output = test.txt.xz 265 - /// Extracting: input = test.txt.xz, output = test.txt 266 - /// 267 - /// ``` bash 268 - /// cmprss xz test.txt test.txt.xz 269 - /// cmprss xz --extract --ignore-pipes test.txt.xz 270 - /// ``` 271 - #[test] 272 - fn xz_roundtrip_explicit() -> Result<(), Box<dyn std::error::Error>> { 273 - let file = assert_fs::NamedTempFile::new("test.txt")?; 274 - file.write_str("garbage data for testing")?; 275 - let working_dir = assert_fs::TempDir::new()?; 276 - let archive = working_dir.child("test.txt.xz"); 277 - archive.assert(predicate::path::missing()); 264 + /// Xz roundtrip using files 265 + /// Compressing: input = test.txt, output = test.txt.xz 266 + /// Extracting: input = test.txt.xz, output = test.txt 267 + /// 268 + /// ``` bash 269 + /// cmprss xz test.txt test.txt.xz 270 + /// cmprss xz --extract --ignore-pipes test.txt.xz 271 + /// ``` 272 + #[test] 273 + fn xz_roundtrip_explicit() -> Result<(), Box<dyn std::error::Error>> { 274 + let file = assert_fs::NamedTempFile::new("test.txt")?; 275 + file.write_str("garbage data for testing")?; 276 + let working_dir = assert_fs::TempDir::new()?; 277 + let archive = working_dir.child("test.txt.xz"); 278 + archive.assert(predicate::path::missing()); 278 279 279 - let mut compress = Command::cargo_bin("cmprss")?; 280 - compress 281 - .current_dir(&working_dir) 282 - .arg("xz") 283 - .arg(file.path()) 284 - .arg(archive.path()); 285 - compress.assert().success(); 286 - archive.assert(predicate::path::is_file()); 280 + let mut compress = Command::cargo_bin("cmprss")?; 281 + compress 282 + .current_dir(&working_dir) 283 + .arg("xz") 284 + .arg(file.path()) 285 + .arg(archive.path()); 286 + compress.assert().success(); 287 + archive.assert(predicate::path::is_file()); 287 288 288 - let mut extract = Command::cargo_bin("cmprss")?; 289 - extract 290 - .current_dir(&working_dir) 291 - .arg("xz") 292 - .arg("--ignore-pipes") 293 - .arg("--extract") 294 - .arg(archive.path()); 295 - extract.assert().success(); 289 + let mut extract = Command::cargo_bin("cmprss")?; 290 + extract 291 + .current_dir(&working_dir) 292 + .arg("xz") 293 + .arg("--ignore-pipes") 294 + .arg("--extract") 295 + .arg(archive.path()); 296 + extract.assert().success(); 296 297 297 - // Assert the files are identical 298 - working_dir 299 - .child("test.txt") 300 - .assert(predicate::path::eq_file(file.path())); 298 + // Assert the files are identical 299 + working_dir 300 + .child("test.txt") 301 + .assert(predicate::path::eq_file(file.path())); 301 302 302 - Ok(()) 303 - } 303 + Ok(()) 304 + } 304 305 305 - /// Xz roundtrip using stdin 306 - /// Compressing: input = stdin, output = test.txt.xz 307 - /// Extracting: input = stdin(test.txt.xz), output = test.txt 308 - /// 309 - /// ``` bash 310 - /// cat test.txt | cmprss xz test.txt.xz 311 - /// cat test.txt.xz | cmprss xz --extract out.txt 312 - /// ``` 313 - #[test] 314 - fn xz_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 315 - let file = assert_fs::NamedTempFile::new("test.txt")?; 316 - file.write_str("garbage data for testing")?; 317 - let working_dir = assert_fs::TempDir::new()?; 318 - let archive = working_dir.child("test.txt.xz"); 319 - archive.assert(predicate::path::missing()); 306 + /// Xz roundtrip using stdin 307 + /// Compressing: input = stdin, output = test.txt.xz 308 + /// Extracting: input = stdin(test.txt.xz), output = test.txt 309 + /// 310 + /// ``` bash 311 + /// cat test.txt | cmprss xz test.txt.xz 312 + /// cat test.txt.xz | cmprss xz --extract out.txt 313 + /// ``` 314 + #[test] 315 + fn xz_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 316 + let file = assert_fs::NamedTempFile::new("test.txt")?; 317 + file.write_str("garbage data for testing")?; 318 + let working_dir = assert_fs::TempDir::new()?; 319 + let archive = working_dir.child("test.txt.xz"); 320 + archive.assert(predicate::path::missing()); 320 321 321 - // Pipe file to stdin 322 - let mut compress = Command::cargo_bin("cmprss")?; 323 - compress 324 - .current_dir(&working_dir) 325 - .arg("xz") 326 - .arg("test.txt.xz") 327 - .stdin(Stdio::from(File::open(file.path())?)); 328 - compress.assert().success(); 329 - archive.assert(predicate::path::is_file()); 322 + // Pipe file to stdin 323 + let mut compress = Command::cargo_bin("cmprss")?; 324 + compress 325 + .current_dir(&working_dir) 326 + .arg("xz") 327 + .arg("test.txt.xz") 328 + .stdin(Stdio::from(File::open(file.path())?)); 329 + compress.assert().success(); 330 + archive.assert(predicate::path::is_file()); 330 331 331 - let mut extract = Command::cargo_bin("cmprss")?; 332 - extract 333 - .current_dir(&working_dir) 334 - .arg("xz") 335 - .stdin(Stdio::from(File::open(archive.path())?)) 336 - .arg("--extract") 337 - .arg("out.txt"); 338 - extract.assert().success(); 332 + let mut extract = Command::cargo_bin("cmprss")?; 333 + extract 334 + .current_dir(&working_dir) 335 + .arg("xz") 336 + .stdin(Stdio::from(File::open(archive.path())?)) 337 + .arg("--extract") 338 + .arg("out.txt"); 339 + extract.assert().success(); 339 340 340 - // Assert the files are identical 341 - working_dir 342 - .child("out.txt") 343 - .assert(predicate::path::eq_file(file.path())); 341 + // Assert the files are identical 342 + working_dir 343 + .child("out.txt") 344 + .assert(predicate::path::eq_file(file.path())); 344 345 345 - Ok(()) 346 - } 346 + Ok(()) 347 + } 347 348 348 - /// Xz roundtrip using stdout 349 - /// Compressing: input = test.txt, output = stdout 350 - /// Extracting: input = test.txt.xz, output = stdout 351 - /// 352 - /// ``` bash 353 - /// cmprss xz test.txt > test.txt.xz 354 - /// cmprss xz --extract test.txt.xz > out.txt 355 - /// ``` 356 - #[test] 357 - fn xz_roundtrip_stdout() -> Result<(), Box<dyn std::error::Error>> { 358 - let file = assert_fs::NamedTempFile::new("test.txt")?; 359 - file.write_str("garbage data for testing")?; 360 - let working_dir = assert_fs::TempDir::new()?; 361 - let archive = working_dir.child("test.txt.xz"); 362 - archive.assert(predicate::path::missing()); 349 + /// Xz roundtrip using stdout 350 + /// Compressing: input = test.txt, output = stdout 351 + /// Extracting: input = test.txt.xz, output = stdout 352 + /// 353 + /// ``` bash 354 + /// cmprss xz test.txt > test.txt.xz 355 + /// cmprss xz --extract test.txt.xz > out.txt 356 + /// ``` 357 + #[test] 358 + fn xz_roundtrip_stdout() -> Result<(), Box<dyn std::error::Error>> { 359 + let file = assert_fs::NamedTempFile::new("test.txt")?; 360 + file.write_str("garbage data for testing")?; 361 + let working_dir = assert_fs::TempDir::new()?; 362 + let archive = working_dir.child("test.txt.xz"); 363 + archive.assert(predicate::path::missing()); 363 364 364 - // Compress file to stdout 365 - let mut compress = Command::cargo_bin("cmprss")?; 366 - compress 367 - .current_dir(&working_dir) 368 - .arg("xz") 369 - .arg(file.path()) 370 - .stdout(Stdio::from(File::create(archive.path())?)); 371 - compress.assert().success(); 372 - archive.assert(predicate::path::is_file()); 365 + // Compress file to stdout 366 + let mut compress = Command::cargo_bin("cmprss")?; 367 + compress 368 + .current_dir(&working_dir) 369 + .arg("xz") 370 + .arg(file.path()) 371 + .stdout(Stdio::from(File::create(archive.path())?)); 372 + compress.assert().success(); 373 + archive.assert(predicate::path::is_file()); 373 374 374 - // Extract file to stdout 375 - let mut extract = Command::cargo_bin("cmprss")?; 376 - extract 377 - .current_dir(&working_dir) 378 - .arg("xz") 379 - .arg("--ignore-stdin") 380 - .arg("--extract") 381 - .arg(archive.path()) 382 - .arg("out.txt"); 383 - // TODO: This fails, but manual testing shows it works fine 384 - //.stdout(Stdio::from(File::create("out.txt")?)); 385 - extract.assert().success(); 375 + // Extract file to stdout 376 + let mut extract = Command::cargo_bin("cmprss")?; 377 + extract 378 + .current_dir(&working_dir) 379 + .arg("xz") 380 + .arg("--ignore-stdin") 381 + .arg("--extract") 382 + .arg(archive.path()) 383 + .arg("out.txt"); 384 + // TODO: This fails, but manual testing shows it works fine 385 + //.stdout(Stdio::from(File::create("out.txt")?)); 386 + extract.assert().success(); 386 387 387 - // Assert the files are identical 388 - working_dir 389 - .child("out.txt") 390 - .assert(predicate::path::eq_file(file.path())); 388 + // Assert the files are identical 389 + working_dir 390 + .child("out.txt") 391 + .assert(predicate::path::eq_file(file.path())); 391 392 392 - Ok(()) 393 - } 393 + Ok(()) 394 + } 394 395 395 - /// Bzip2 roundtrip using files 396 - /// Compressing: input = test.txt, output = test.txt.bz2 397 - /// Extracting: input = test.txt.bz2, output = test.txt 398 - /// 399 - /// ``` bash 400 - /// cmprss bzip2 test.txt test.txt.bz2 401 - /// cmprss bzip2 --extract --ignore-pipes test.txt.bz2 402 - /// ``` 403 - #[test] 404 - fn bzip2_roundtrip_explicit() -> Result<(), Box<dyn std::error::Error>> { 405 - let file = assert_fs::NamedTempFile::new("test.txt")?; 406 - file.write_str("garbage data for testing")?; 396 + /// Bzip2 roundtrip using files 397 + /// Compressing: input = test.txt, output = test.txt.bz2 398 + /// Extracting: input = test.txt.bz2, output = test.txt 399 + /// 400 + /// ``` bash 401 + /// cmprss bzip2 test.txt test.txt.bz2 402 + /// cmprss bzip2 --extract --ignore-pipes test.txt.bz2 403 + /// ``` 404 + #[test] 405 + fn bzip2_roundtrip_explicit() -> Result<(), Box<dyn std::error::Error>> { 406 + let file = assert_fs::NamedTempFile::new("test.txt")?; 407 + file.write_str("garbage data for testing")?; 407 408 408 - let working_dir = assert_fs::TempDir::new()?; 409 - let archive = working_dir.child("test.txt.bz2"); 410 - archive.assert(predicate::path::missing()); 409 + let working_dir = assert_fs::TempDir::new()?; 410 + let archive = working_dir.child("test.txt.bz2"); 411 + archive.assert(predicate::path::missing()); 411 412 412 - let mut compress = Command::cargo_bin("cmprss")?; 413 - compress 414 - .current_dir(&working_dir) 415 - .arg("bzip2") 416 - .arg(file.path()) 417 - .arg(archive.path()); 418 - compress.assert().success(); 419 - archive.assert(predicate::path::is_file()); 413 + let mut compress = Command::cargo_bin("cmprss")?; 414 + compress 415 + .current_dir(&working_dir) 416 + .arg("bzip2") 417 + .arg(file.path()) 418 + .arg(archive.path()); 419 + compress.assert().success(); 420 + archive.assert(predicate::path::is_file()); 420 421 421 - let mut extract = Command::cargo_bin("cmprss")?; 422 - extract 423 - .current_dir(&working_dir) 424 - .arg("bzip2") 425 - .arg("--ignore-pipes") 426 - .arg("--extract") 427 - .arg(archive.path()); 428 - extract.assert().success(); 422 + let mut extract = Command::cargo_bin("cmprss")?; 423 + extract 424 + .current_dir(&working_dir) 425 + .arg("bzip2") 426 + .arg("--ignore-pipes") 427 + .arg("--extract") 428 + .arg(archive.path()); 429 + extract.assert().success(); 429 430 430 - // Assert the files are identical 431 - working_dir 432 - .child("test.txt") 433 - .assert(predicate::path::eq_file(file.path())); 431 + // Assert the files are identical 432 + working_dir 433 + .child("test.txt") 434 + .assert(predicate::path::eq_file(file.path())); 434 435 435 - Ok(()) 436 - } 436 + Ok(()) 437 + } 437 438 438 - /// Bzip2 roundtrip using stdin 439 - /// Compressing: input = stdin, output = test.txt.bz2 440 - /// Extracting: input = stdin(test.txt.bz2), output = test.txt 441 - /// 442 - /// ``` bash 443 - /// cat test.txt | cmprss bzip2 test.txt.bz2 444 - /// cat test.txt.bz2 | cmprss bzip2 --extract out.txt 445 - /// ``` 446 - #[test] 447 - fn bzip2_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 448 - let file = assert_fs::NamedTempFile::new("test.txt")?; 449 - file.write_str("garbage data for testing")?; 439 + /// Bzip2 roundtrip using stdin 440 + /// Compressing: input = stdin, output = test.txt.bz2 441 + /// Extracting: input = stdin(test.txt.bz2), output = test.txt 442 + /// 443 + /// ``` bash 444 + /// cat test.txt | cmprss bzip2 test.txt.bz2 445 + /// cat test.txt.bz2 | cmprss bzip2 --extract out.txt 446 + /// ``` 447 + #[test] 448 + fn bzip2_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 449 + let file = assert_fs::NamedTempFile::new("test.txt")?; 450 + file.write_str("garbage data for testing")?; 450 451 451 - let working_dir = assert_fs::TempDir::new()?; 452 - let archive = working_dir.child("test.txt.bz2"); 453 - archive.assert(predicate::path::missing()); 452 + let working_dir = assert_fs::TempDir::new()?; 453 + let archive = working_dir.child("test.txt.bz2"); 454 + archive.assert(predicate::path::missing()); 454 455 455 - // Pipe file to stdin 456 - let mut compress = Command::cargo_bin("cmprss")?; 457 - compress 458 - .current_dir(&working_dir) 459 - .arg("bzip2") 460 - .arg("test.txt.bz2") 461 - .stdin(Stdio::from(File::open(file.path())?)); 462 - compress.assert().success(); 463 - archive.assert(predicate::path::is_file()); 456 + // Pipe file to stdin 457 + let mut compress = Command::cargo_bin("cmprss")?; 458 + compress 459 + .current_dir(&working_dir) 460 + .arg("bzip2") 461 + .arg("test.txt.bz2") 462 + .stdin(Stdio::from(File::open(file.path())?)); 463 + compress.assert().success(); 464 + archive.assert(predicate::path::is_file()); 464 465 465 - let mut extract = Command::cargo_bin("cmprss")?; 466 - extract 467 - .current_dir(&working_dir) 468 - .arg("bzip2") 469 - .stdin(Stdio::from(File::open(archive.path())?)) 470 - .arg("--extract") 471 - .arg("out.txt"); 472 - extract.assert().success(); 466 + let mut extract = Command::cargo_bin("cmprss")?; 467 + extract 468 + .current_dir(&working_dir) 469 + .arg("bzip2") 470 + .stdin(Stdio::from(File::open(archive.path())?)) 471 + .arg("--extract") 472 + .arg("out.txt"); 473 + extract.assert().success(); 473 474 474 - // Assert the files are identical 475 - working_dir 476 - .child("out.txt") 477 - .assert(predicate::path::eq_file(file.path())); 475 + // Assert the files are identical 476 + working_dir 477 + .child("out.txt") 478 + .assert(predicate::path::eq_file(file.path())); 478 479 479 - Ok(()) 480 - } 480 + Ok(()) 481 + } 481 482 482 - /// Bzip2 roundtrip using stdout 483 - /// Compressing: input = test.txt, output = stdout 484 - /// Extracting: input = test.txt.bz2, output = stdout 485 - /// 486 - /// ``` bash 487 - /// cmprss bzip2 test.txt > test.txt.bz2 488 - /// cmprss bzip2 --extract test.txt.bz2 > out.txt 489 - /// ``` 490 - #[test] 491 - fn bzip2_roundtrip_stdout() -> Result<(), Box<dyn std::error::Error>> { 492 - let file = assert_fs::NamedTempFile::new("test.txt")?; 493 - file.write_str("garbage data for testing")?; 483 + /// Bzip2 roundtrip using stdout 484 + /// Compressing: input = test.txt, output = stdout 485 + /// Extracting: input = test.txt.bz2, output = stdout 486 + /// 487 + /// ``` bash 488 + /// cmprss bzip2 test.txt > test.txt.bz2 489 + /// cmprss bzip2 --extract test.txt.bz2 > out.txt 490 + /// ``` 491 + #[test] 492 + fn bzip2_roundtrip_stdout() -> Result<(), Box<dyn std::error::Error>> { 493 + let file = assert_fs::NamedTempFile::new("test.txt")?; 494 + file.write_str("garbage data for testing")?; 494 495 495 - let working_dir = assert_fs::TempDir::new()?; 496 - let archive = working_dir.child("test.txt.bz2"); 497 - archive.assert(predicate::path::missing()); 496 + let working_dir = assert_fs::TempDir::new()?; 497 + let archive = working_dir.child("test.txt.bz2"); 498 + archive.assert(predicate::path::missing()); 498 499 499 - // Compress file to stdout 500 - let mut compress = Command::cargo_bin("cmprss")?; 501 - compress 502 - .current_dir(&working_dir) 503 - .arg("bzip2") 504 - .arg(file.path()) 505 - .stdout(Stdio::from(File::create(archive.path())?)); 506 - compress.assert().success(); 507 - archive.assert(predicate::path::is_file()); 500 + // Compress file to stdout 501 + let mut compress = Command::cargo_bin("cmprss")?; 502 + compress 503 + .current_dir(&working_dir) 504 + .arg("bzip2") 505 + .arg(file.path()) 506 + .stdout(Stdio::from(File::create(archive.path())?)); 507 + compress.assert().success(); 508 + archive.assert(predicate::path::is_file()); 508 509 509 - // Extract file to stdout 510 - let mut extract = Command::cargo_bin("cmprss")?; 511 - extract 512 - .current_dir(&working_dir) 513 - .arg("bzip2") 514 - .arg("--ignore-stdin") 515 - .arg("--extract") 516 - .arg(archive.path()) 517 - .arg("out.txt"); 518 - // TODO: This fails, but manual testing shows it works fine 519 - //.stdout(Stdio::from(File::create("out.txt")?)); 520 - extract.assert().success(); 510 + // Extract file to stdout 511 + let mut extract = Command::cargo_bin("cmprss")?; 512 + extract 513 + .current_dir(&working_dir) 514 + .arg("bzip2") 515 + .arg("--ignore-stdin") 516 + .arg("--extract") 517 + .arg(archive.path()) 518 + .arg("out.txt"); 519 + // TODO: This fails, but manual testing shows it works fine 520 + //.stdout(Stdio::from(File::create("out.txt")?)); 521 + extract.assert().success(); 521 522 522 - // Assert the files are identical 523 - working_dir 524 - .child("out.txt") 525 - .assert(predicate::path::eq_file(file.path())); 523 + // Assert the files are identical 524 + working_dir 525 + .child("out.txt") 526 + .assert(predicate::path::eq_file(file.path())); 526 527 527 - Ok(()) 528 - } 528 + Ok(()) 529 + } 529 530 530 - /// Magic roundtrip using stdin 531 - /// Compressing: input = stdin, output = test.txt.gz 532 - /// Extracting: input = test.txt.gz, output = test.txt 533 - /// 534 - /// ``` bash 535 - /// cat test.txt | cmprss test.txt.gz 536 - /// cmprss gz --extract test.txt.gz out.txt 537 - /// ``` 538 - #[test] 539 - fn magic_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 540 - let file = assert_fs::NamedTempFile::new("test.txt")?; 541 - file.write_str("garbage data for testing")?; 531 + /// Magic roundtrip using stdin 532 + /// Compressing: input = stdin, output = test.txt.gz 533 + /// Extracting: input = test.txt.gz, output = test.txt 534 + /// 535 + /// ``` bash 536 + /// cat test.txt | cmprss test.txt.gz 537 + /// cmprss gz --extract test.txt.gz out.txt 538 + /// ``` 539 + #[test] 540 + fn magic_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> { 541 + let file = assert_fs::NamedTempFile::new("test.txt")?; 542 + file.write_str("garbage data for testing")?; 542 543 543 - let working_dir = assert_fs::TempDir::new()?; 544 - let archive = working_dir.child("test.txt.gz"); 545 - archive.assert(predicate::path::missing()); 544 + let working_dir = assert_fs::TempDir::new()?; 545 + let archive = working_dir.child("test.txt.gz"); 546 + archive.assert(predicate::path::missing()); 546 547 547 - // Pipe file to stdin 548 - let mut compress = Command::cargo_bin("cmprss")?; 549 - compress 550 - .current_dir(&working_dir) 551 - .arg("--ignore-stdout") 552 - .arg("test.txt.gz") 553 - .stdin(Stdio::from(File::open(file.path())?)); 554 - compress.assert().success(); 555 - archive.assert(predicate::path::is_file()); 548 + // Pipe file to stdin 549 + let mut compress = Command::cargo_bin("cmprss")?; 550 + compress 551 + .current_dir(&working_dir) 552 + .arg("--ignore-stdout") 553 + .arg("test.txt.gz") 554 + .stdin(Stdio::from(File::open(file.path())?)); 555 + compress.assert().success(); 556 + archive.assert(predicate::path::is_file()); 556 557 557 - let mut extract = Command::cargo_bin("cmprss")?; 558 - extract 559 - .current_dir(&working_dir) 560 - .arg("gz") 561 - .arg("--ignore-pipes") 562 - .arg("--extract") 563 - .arg("test.txt.gz"); 564 - extract.assert().success(); 558 + let mut extract = Command::cargo_bin("cmprss")?; 559 + extract 560 + .current_dir(&working_dir) 561 + .arg("gz") 562 + .arg("--ignore-pipes") 563 + .arg("--extract") 564 + .arg("test.txt.gz"); 565 + extract.assert().success(); 565 566 566 - // Assert the files are identical 567 - working_dir 568 - .child("test.txt") 569 - .assert(predicate::path::eq_file(file.path())); 567 + // Assert the files are identical 568 + working_dir 569 + .child("test.txt") 570 + .assert(predicate::path::eq_file(file.path())); 570 571 571 - Ok(()) 572 - } 572 + Ok(()) 573 + } 573 574 574 - /// Magic roundtrip using files 575 - /// Compressing: input = test.txt, output = test.txt.gz 576 - /// Extracting: input = test.txt.gz, output = stdout 577 - /// 578 - /// ``` bash 579 - /// cmprss test.txt test.txt.gz 580 - /// cmprss test.txt.gz out.txt 581 - /// ``` 582 - #[test] 583 - fn magic_roundtrip_files() -> Result<(), Box<dyn std::error::Error>> { 584 - let file = assert_fs::NamedTempFile::new("test.txt")?; 585 - file.write_str("garbage data for testing")?; 575 + /// Magic roundtrip using files 576 + /// Compressing: input = test.txt, output = test.txt.gz 577 + /// Extracting: input = test.txt.gz, output = stdout 578 + /// 579 + /// ``` bash 580 + /// cmprss test.txt test.txt.gz 581 + /// cmprss test.txt.gz out.txt 582 + /// ``` 583 + #[test] 584 + fn magic_roundtrip_files() -> Result<(), Box<dyn std::error::Error>> { 585 + let file = assert_fs::NamedTempFile::new("test.txt")?; 586 + file.write_str("garbage data for testing")?; 586 587 587 - let working_dir = assert_fs::TempDir::new()?; 588 - let archive = working_dir.child("test.txt.gz"); 589 - archive.assert(predicate::path::missing()); 588 + let working_dir = assert_fs::TempDir::new()?; 589 + let archive = working_dir.child("test.txt.gz"); 590 + archive.assert(predicate::path::missing()); 590 591 591 - // Compress file to an archive 592 - let mut compress = Command::cargo_bin("cmprss")?; 593 - compress 594 - .current_dir(&working_dir) 595 - .arg("--ignore-pipes") 596 - .arg(file.path()) 597 - .arg("test.txt.gz"); 598 - compress.assert().success(); 599 - archive.assert(predicate::path::is_file()); 592 + // Compress file to an archive 593 + let mut compress = Command::cargo_bin("cmprss")?; 594 + compress 595 + .current_dir(&working_dir) 596 + .arg("--ignore-pipes") 597 + .arg(file.path()) 598 + .arg("test.txt.gz"); 599 + compress.assert().success(); 600 + archive.assert(predicate::path::is_file()); 600 601 601 - // Extract file to given file 602 - let mut extract = Command::cargo_bin("cmprss")?; 603 - extract 604 - .current_dir(&working_dir) 605 - .arg("--ignore-pipes") 606 - .arg("test.txt.gz") 607 - .arg("out.txt"); 608 - extract.assert().success(); 602 + // Extract file to given file 603 + let mut extract = Command::cargo_bin("cmprss")?; 604 + extract 605 + .current_dir(&working_dir) 606 + .arg("--ignore-pipes") 607 + .arg("test.txt.gz") 608 + .arg("out.txt"); 609 + extract.assert().success(); 609 610 610 - // Assert the files are identical 611 - working_dir 612 - .child("out.txt") 613 - .assert(predicate::path::eq_file(file.path())); 611 + // Assert the files are identical 612 + working_dir 613 + .child("out.txt") 614 + .assert(predicate::path::eq_file(file.path())); 614 615 615 - Ok(()) 616 - } 616 + Ok(()) 617 + } 617 618 618 - /// Magic roundtrip using stdout decompression 619 - /// Compressing: input = test.txt, output = test.txt.gz 620 - /// Extracting: input = test.txt.gz, output = stdout 621 - /// 622 - /// ``` bash 623 - /// cmprss test.txt test.txt.gz 624 - /// cmprss test.txt.gz > out.txt 625 - /// ``` 626 - #[test] 627 - fn magic_roundtrip_stdout_decompression() -> Result<(), Box<dyn std::error::Error>> { 628 - let file = assert_fs::NamedTempFile::new("test.txt")?; 629 - file.write_str("garbage data for testing")?; 619 + /// Magic roundtrip using stdout decompression 620 + /// Compressing: input = test.txt, output = test.txt.gz 621 + /// Extracting: input = test.txt.gz, output = stdout 622 + /// 623 + /// ``` bash 624 + /// cmprss test.txt test.txt.gz 625 + /// cmprss test.txt.gz > out.txt 626 + /// ``` 627 + #[test] 628 + fn magic_roundtrip_stdout_decompression() -> Result<(), Box<dyn std::error::Error>> { 629 + let file = assert_fs::NamedTempFile::new("test.txt")?; 630 + file.write_str("garbage data for testing")?; 630 631 631 - let working_dir = assert_fs::TempDir::new()?; 632 - let archive = working_dir.child("test.txt.gz"); 633 - archive.assert(predicate::path::missing()); 632 + let working_dir = assert_fs::TempDir::new()?; 633 + let archive = working_dir.child("test.txt.gz"); 634 + archive.assert(predicate::path::missing()); 634 635 635 - let out_file = working_dir.child("out.txt"); 636 + let out_file = working_dir.child("out.txt"); 636 637 637 - // Compress file to an archive 638 - let mut compress = Command::cargo_bin("cmprss")?; 639 - compress 640 - .current_dir(&working_dir) 641 - .arg("--ignore-pipes") 642 - .arg(file.path()) 643 - .arg("test.txt.gz"); 644 - compress.assert().success(); 645 - archive.assert(predicate::path::is_file()); 638 + // Compress file to an archive 639 + let mut compress = Command::cargo_bin("cmprss")?; 640 + compress 641 + .current_dir(&working_dir) 642 + .arg("--ignore-pipes") 643 + .arg(file.path()) 644 + .arg("test.txt.gz"); 645 + compress.assert().success(); 646 + archive.assert(predicate::path::is_file()); 646 647 647 - // Extract file to stdout 648 - let mut extract = Command::cargo_bin("cmprss")?; 649 - extract 650 - .current_dir(&working_dir) 651 - .arg("--ignore-stdin") 652 - .arg("test.txt.gz") 653 - .stdout(Stdio::from(File::create(&out_file)?)); 654 - extract.assert().success(); 648 + // Extract file to stdout 649 + let mut extract = Command::cargo_bin("cmprss")?; 650 + extract 651 + .current_dir(&working_dir) 652 + .arg("--ignore-stdin") 653 + .arg("test.txt.gz") 654 + .stdout(Stdio::from(File::create(&out_file)?)); 655 + extract.assert().success(); 655 656 656 - // Assert the files are identical 657 - out_file.assert(predicate::path::eq_file(file.path())); 658 - Ok(()) 659 - } 657 + // Assert the files are identical 658 + out_file.assert(predicate::path::eq_file(file.path())); 659 + Ok(()) 660 + } 660 661 661 - /// Magic roundtrip using stdin compression 662 - /// Compressing: input = stdin, output = test.txt.gz 663 - /// Extracting: input = test.txt.gz, output = test.txt 664 - /// 665 - /// ``` bash 666 - /// cat test.txt | cmprss test.txt.gz 667 - /// cmprss test.txt.gz out.txt 668 - /// ``` 669 - #[test] 670 - fn magic_roundtrip_stdin_compression() -> Result<(), Box<dyn std::error::Error>> { 671 - let file = assert_fs::NamedTempFile::new("test.txt")?; 672 - file.write_str("garbage data for testing")?; 662 + /// Magic roundtrip using stdin compression 663 + /// Compressing: input = stdin, output = test.txt.gz 664 + /// Extracting: input = test.txt.gz, output = test.txt 665 + /// 666 + /// ``` bash 667 + /// cat test.txt | cmprss test.txt.gz 668 + /// cmprss test.txt.gz out.txt 669 + /// ``` 670 + #[test] 671 + fn magic_roundtrip_stdin_compression() -> Result<(), Box<dyn std::error::Error>> { 672 + let file = assert_fs::NamedTempFile::new("test.txt")?; 673 + file.write_str("garbage data for testing")?; 673 674 674 - let working_dir = assert_fs::TempDir::new()?; 675 - let archive = working_dir.child("test.txt.gz"); 676 - archive.assert(predicate::path::missing()); 675 + let working_dir = assert_fs::TempDir::new()?; 676 + let archive = working_dir.child("test.txt.gz"); 677 + archive.assert(predicate::path::missing()); 677 678 678 - let out_file = working_dir.child("out.txt"); 679 + let out_file = working_dir.child("out.txt"); 679 680 680 - // Compress stdin to an archive 681 - let mut compress = Command::cargo_bin("cmprss")?; 682 - compress 683 - .current_dir(&working_dir) 684 - .arg("--ignore-stdout") 685 - .arg("test.txt.gz") 686 - .stdin(Stdio::from(File::open(file.path())?)); 687 - compress.assert().success(); 688 - archive.assert(predicate::path::is_file()); 681 + // Compress stdin to an archive 682 + let mut compress = Command::cargo_bin("cmprss")?; 683 + compress 684 + .current_dir(&working_dir) 685 + .arg("--ignore-stdout") 686 + .arg("test.txt.gz") 687 + .stdin(Stdio::from(File::open(file.path())?)); 688 + compress.assert().success(); 689 + archive.assert(predicate::path::is_file()); 689 690 690 - // Extract file to given file 691 - let mut extract = Command::cargo_bin("cmprss")?; 692 - extract 693 - .current_dir(&working_dir) 694 - .arg("--ignore-pipes") 695 - .arg("test.txt.gz") 696 - .arg(out_file.path()); 697 - extract.assert().success(); 691 + // Extract file to given file 692 + let mut extract = Command::cargo_bin("cmprss")?; 693 + extract 694 + .current_dir(&working_dir) 695 + .arg("--ignore-pipes") 696 + .arg("test.txt.gz") 697 + .arg(out_file.path()); 698 + extract.assert().success(); 698 699 699 - // Assert the files are identical 700 - out_file.assert(predicate::path::eq_file(file.path())); 700 + // Assert the files are identical 701 + out_file.assert(predicate::path::eq_file(file.path())); 701 702 702 - Ok(()) 703 - } 703 + Ok(()) 704 + } 704 705 705 - /// Magic roundtrip using default filenames 706 - /// Compressing: input = test.txt, output = test.txt.gz 707 - /// Extracting: input = test.txt.gz, output = <default> 708 - /// 709 - /// ``` bash 710 - /// cmprss test.txt test.txt.gz 711 - /// cmprss test.txt.gz 712 - /// ``` 713 - #[test] 714 - fn magic_roundtrip_default_filenames() -> Result<(), Box<dyn std::error::Error>> { 715 - let file = assert_fs::NamedTempFile::new("test.txt")?; 716 - file.write_str("garbage data for testing")?; 706 + /// Magic roundtrip using default filenames 707 + /// Compressing: input = test.txt, output = test.txt.gz 708 + /// Extracting: input = test.txt.gz, output = <default> 709 + /// 710 + /// ``` bash 711 + /// cmprss test.txt test.txt.gz 712 + /// cmprss test.txt.gz 713 + /// ``` 714 + #[test] 715 + fn magic_roundtrip_default_filenames() -> Result<(), Box<dyn std::error::Error>> { 716 + let file = assert_fs::NamedTempFile::new("test.txt")?; 717 + file.write_str("garbage data for testing")?; 717 718 718 - let working_dir = assert_fs::TempDir::new()?; 719 - let archive = working_dir.child("test.txt.gz"); 720 - archive.assert(predicate::path::missing()); 719 + let working_dir = assert_fs::TempDir::new()?; 720 + let archive = working_dir.child("test.txt.gz"); 721 + archive.assert(predicate::path::missing()); 721 722 722 - // Compress file to an archive 723 - let mut compress = Command::cargo_bin("cmprss")?; 724 - compress 725 - .current_dir(&working_dir) 726 - .arg("--ignore-pipes") 727 - .arg(file.path()) 728 - .arg("test.txt.gz"); 729 - compress.assert().success(); 730 - archive.assert(predicate::path::is_file()); 723 + // Compress file to an archive 724 + let mut compress = Command::cargo_bin("cmprss")?; 725 + compress 726 + .current_dir(&working_dir) 727 + .arg("--ignore-pipes") 728 + .arg(file.path()) 729 + .arg("test.txt.gz"); 730 + compress.assert().success(); 731 + archive.assert(predicate::path::is_file()); 731 732 732 - // Extract file to default filename 733 - let mut extract = Command::cargo_bin("cmprss")?; 734 - extract 735 - .current_dir(&working_dir) 736 - .arg("--ignore-pipes") 737 - .arg("test.txt.gz"); 738 - extract.assert().success(); 733 + // Extract file to default filename 734 + let mut extract = Command::cargo_bin("cmprss")?; 735 + extract 736 + .current_dir(&working_dir) 737 + .arg("--ignore-pipes") 738 + .arg("test.txt.gz"); 739 + extract.assert().success(); 739 740 740 - // Assert the files are identical 741 - working_dir 742 - .child("test.txt") 743 - .assert(predicate::path::eq_file(file.path())); 741 + // Assert the files are identical 742 + working_dir 743 + .child("test.txt") 744 + .assert(predicate::path::eq_file(file.path())); 744 745 745 - Ok(()) 746 - } 746 + Ok(()) 747 + } 747 748 748 - /// Magic roundtrip using multiple files with tar 749 - /// Compressing: input = test.txt/test2.txt, output = archive.tar 750 - /// Extracting: input = archive.tar, output = <default> 751 - /// 752 - /// ``` bash 753 - /// cmprss test.txt test2.txt archive.tar 754 - /// cmprss archive.tar 755 - /// ``` 756 - #[test] 757 - fn magic_roundtrip_multiple_files_tar() -> Result<(), Box<dyn std::error::Error>> { 758 - let file = assert_fs::NamedTempFile::new("test.txt")?; 759 - file.write_str("garbage data for testing")?; 760 - let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 761 - file2.write_str("more garbage data for testing")?; 749 + /// Magic roundtrip using multiple files with tar 750 + /// Compressing: input = test.txt/test2.txt, output = archive.tar 751 + /// Extracting: input = archive.tar, output = <default> 752 + /// 753 + /// ``` bash 754 + /// cmprss test.txt test2.txt archive.tar 755 + /// cmprss archive.tar 756 + /// ``` 757 + #[test] 758 + fn magic_roundtrip_multiple_files_tar() -> Result<(), Box<dyn std::error::Error>> { 759 + let file = assert_fs::NamedTempFile::new("test.txt")?; 760 + file.write_str("garbage data for testing")?; 761 + let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 762 + file2.write_str("more garbage data for testing")?; 762 763 763 - let working_dir = assert_fs::TempDir::new()?; 764 - let archive = working_dir.child("archive.tar"); 765 - archive.assert(predicate::path::missing()); 764 + let working_dir = assert_fs::TempDir::new()?; 765 + let archive = working_dir.child("archive.tar"); 766 + archive.assert(predicate::path::missing()); 766 767 767 - // Compress files to an archive 768 - let mut compress = Command::cargo_bin("cmprss")?; 769 - compress 770 - .current_dir(&working_dir) 771 - .arg("--ignore-pipes") 772 - .arg(file.path()) 773 - .arg(file2.path()) 774 - .arg("archive.tar"); 775 - compress.assert().success(); 776 - archive.assert(predicate::path::is_file()); 768 + // Compress files to an archive 769 + let mut compress = Command::cargo_bin("cmprss")?; 770 + compress 771 + .current_dir(&working_dir) 772 + .arg("--ignore-pipes") 773 + .arg(file.path()) 774 + .arg(file2.path()) 775 + .arg("archive.tar"); 776 + compress.assert().success(); 777 + archive.assert(predicate::path::is_file()); 777 778 778 - // Extract file to default filename 779 - let mut extract = Command::cargo_bin("cmprss")?; 780 - extract 781 - .current_dir(&working_dir) 782 - .arg("--ignore-pipes") 783 - .arg("archive.tar"); 784 - extract.assert().success(); 779 + // Extract file to default filename 780 + let mut extract = Command::cargo_bin("cmprss")?; 781 + extract 782 + .current_dir(&working_dir) 783 + .arg("--ignore-pipes") 784 + .arg("archive.tar"); 785 + extract.assert().success(); 785 786 786 - // Assert the files are identical 787 - working_dir 788 - .child("test.txt") 789 - .assert(predicate::path::eq_file(file.path())); 790 - working_dir 791 - .child("test2.txt") 792 - .assert(predicate::path::eq_file(file2.path())); 787 + // Assert the files are identical 788 + working_dir 789 + .child("test.txt") 790 + .assert(predicate::path::eq_file(file.path())); 791 + working_dir 792 + .child("test2.txt") 793 + .assert(predicate::path::eq_file(file2.path())); 793 794 794 - Ok(()) 795 - } 795 + Ok(()) 796 + } 796 797 797 - /// Magic roundtrip with tar.gz 798 - /// Infer things as much as possible 799 - /// Compressing: input = test.txt + test2.txt, output = test.tar.gz 800 - /// Extracting: input = test.tar.gz, output = test.txt + test2.txt 801 - /// 802 - /// ``` bash 803 - /// cmprss test.txt test2.txt archive.tar 804 - /// cmprss archive.tar archive.tar.gz 805 - /// cmprss archive.tar.gz archive.tar 806 - /// cmprss archive.tar 807 - /// ``` 808 - #[test] 809 - fn magic_roundtrip_tar_gz() -> Result<(), Box<dyn std::error::Error>> { 810 - let file = assert_fs::NamedTempFile::new("test.txt")?; 811 - file.write_str("garbage data for testing")?; 812 - let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 813 - file2.write_str("more garbage data for testing")?; 798 + /// Magic roundtrip with tar.gz 799 + /// Infer things as much as possible 800 + /// Compressing: input = test.txt + test2.txt, output = test.tar.gz 801 + /// Extracting: input = test.tar.gz, output = test.txt + test2.txt 802 + /// 803 + /// ``` bash 804 + /// cmprss test.txt test2.txt archive.tar 805 + /// cmprss archive.tar archive.tar.gz 806 + /// cmprss archive.tar.gz archive.tar 807 + /// cmprss archive.tar 808 + /// ``` 809 + #[test] 810 + fn magic_roundtrip_tar_gz() -> Result<(), Box<dyn std::error::Error>> { 811 + let file = assert_fs::NamedTempFile::new("test.txt")?; 812 + file.write_str("garbage data for testing")?; 813 + let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 814 + file2.write_str("more garbage data for testing")?; 814 815 815 - let working_dir = assert_fs::TempDir::new()?; 816 - let archive = working_dir.child("archive.tar"); 817 - archive.assert(predicate::path::missing()); 818 - let archive2 = working_dir.child("archive.tar.gz"); 819 - archive2.assert(predicate::path::missing()); 816 + let working_dir = assert_fs::TempDir::new()?; 817 + let archive = working_dir.child("archive.tar"); 818 + archive.assert(predicate::path::missing()); 819 + let archive2 = working_dir.child("archive.tar.gz"); 820 + archive2.assert(predicate::path::missing()); 820 821 821 - let extract_dir = assert_fs::TempDir::new()?; 822 + let extract_dir = assert_fs::TempDir::new()?; 822 823 823 - // Compress files to an archive 824 - let mut compress = Command::cargo_bin("cmprss")?; 825 - compress 826 - .current_dir(&working_dir) 827 - .arg("--ignore-pipes") 828 - .arg(file.path()) 829 - .arg(file2.path()) 830 - .arg("archive.tar"); 831 - compress.assert().success(); 832 - archive.assert(predicate::path::is_file()); 824 + // Compress files to an archive 825 + let mut compress = Command::cargo_bin("cmprss")?; 826 + compress 827 + .current_dir(&working_dir) 828 + .arg("--ignore-pipes") 829 + .arg(file.path()) 830 + .arg(file2.path()) 831 + .arg("archive.tar"); 832 + compress.assert().success(); 833 + archive.assert(predicate::path::is_file()); 833 834 834 - // Compress tar to an archive 835 - let mut compress2 = Command::cargo_bin("cmprss")?; 836 - compress2 837 - .current_dir(&working_dir) 838 - .arg("--ignore-pipes") 839 - .arg("archive.tar") 840 - .arg("archive.tar.gz"); 841 - compress2.assert().success(); 842 - archive2.assert(predicate::path::is_file()); 835 + // Compress tar to an archive 836 + let mut compress2 = Command::cargo_bin("cmprss")?; 837 + compress2 838 + .current_dir(&working_dir) 839 + .arg("--ignore-pipes") 840 + .arg("archive.tar") 841 + .arg("archive.tar.gz"); 842 + compress2.assert().success(); 843 + archive2.assert(predicate::path::is_file()); 843 844 844 - // Extract file to default filename 845 - let mut extract = Command::cargo_bin("cmprss")?; 846 - extract 847 - .current_dir(&extract_dir) 848 - .arg("--ignore-pipes") 849 - .arg(archive2.path()) 850 - .arg("archive.tar"); 851 - extract.assert().success(); 845 + // Extract file to default filename 846 + let mut extract = Command::cargo_bin("cmprss")?; 847 + extract 848 + .current_dir(&extract_dir) 849 + .arg("--ignore-pipes") 850 + .arg(archive2.path()) 851 + .arg("archive.tar"); 852 + extract.assert().success(); 852 853 853 - // Extract file to default filename 854 - let mut extract2 = Command::cargo_bin("cmprss")?; 855 - extract2 856 - .current_dir(&extract_dir) 857 - .arg("--ignore-pipes") 858 - .arg("archive.tar"); 859 - extract2.assert().success(); 854 + // Extract file to default filename 855 + let mut extract2 = Command::cargo_bin("cmprss")?; 856 + extract2 857 + .current_dir(&extract_dir) 858 + .arg("--ignore-pipes") 859 + .arg("archive.tar"); 860 + extract2.assert().success(); 860 861 861 - // Assert the files are identical 862 - extract_dir 863 - .child("test.txt") 864 - .assert(predicate::path::eq_file(file.path())); 865 - extract_dir 866 - .child("test2.txt") 867 - .assert(predicate::path::eq_file(file2.path())); 862 + // Assert the files are identical 863 + extract_dir 864 + .child("test.txt") 865 + .assert(predicate::path::eq_file(file.path())); 866 + extract_dir 867 + .child("test2.txt") 868 + .assert(predicate::path::eq_file(file2.path())); 868 869 869 - Ok(()) 870 - } 870 + Ok(()) 871 + } 871 872 872 - /// Magic roundtrip with tar.gz using pipes 873 - /// Infer things as much as possible 874 - /// Compressing: input = test.txt + test2.txt, output = test.tar.gz 875 - /// Extracting: input = test.tar.gz, output = test.txt + test2.txt 876 - /// 877 - /// ``` bash 878 - /// cmprss tar test.txt test2.txt | cmprss gzip | cmprss gzip --extract | cmprss tar --extract 879 - /// ``` 880 - #[test] 881 - fn magic_roundtrip_tar_gz_pipes() -> Result<(), Box<dyn std::error::Error>> { 882 - let file = assert_fs::NamedTempFile::new("test.txt")?; 883 - file.write_str("garbage data for testing")?; 884 - let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 885 - file2.write_str("more garbage data for testing")?; 873 + /// Magic roundtrip with tar.gz using pipes 874 + /// Infer things as much as possible 875 + /// Compressing: input = test.txt + test2.txt, output = test.tar.gz 876 + /// Extracting: input = test.tar.gz, output = test.txt + test2.txt 877 + /// 878 + /// ``` bash 879 + /// cmprss tar test.txt test2.txt | cmprss gzip | cmprss gzip --extract | cmprss tar --extract 880 + /// ``` 881 + #[test] 882 + fn magic_roundtrip_tar_gz_pipes() -> Result<(), Box<dyn std::error::Error>> { 883 + let file = assert_fs::NamedTempFile::new("test.txt")?; 884 + file.write_str("garbage data for testing")?; 885 + let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 886 + file2.write_str("more garbage data for testing")?; 886 887 887 - let working_dir = assert_fs::TempDir::new()?; 888 - let tee1 = working_dir.child("tee1"); 889 - let tee2 = working_dir.child("tee2"); 890 - let tee3 = working_dir.child("tee3"); 888 + let working_dir = assert_fs::TempDir::new()?; 889 + let tee1 = working_dir.child("tee1"); 890 + let tee2 = working_dir.child("tee2"); 891 + let tee3 = working_dir.child("tee3"); 891 892 892 - let extract_dir = assert_fs::TempDir::new()?; 893 + let extract_dir = assert_fs::TempDir::new()?; 893 894 894 - let mut compress = Command::cargo_bin("cmprss")?; 895 - compress 896 - .current_dir(&working_dir) 897 - .arg("tar") 898 - .arg("--ignore-stdin") 899 - .arg(file.path()) 900 - .arg(file2.path()) 901 - .stdout(Stdio::from(File::create(tee1.path())?)); 902 - compress.assert().success(); 903 - tee1.assert(predicate::path::is_file()); 895 + let mut compress = Command::cargo_bin("cmprss")?; 896 + compress 897 + .current_dir(&working_dir) 898 + .arg("tar") 899 + .arg("--ignore-stdin") 900 + .arg(file.path()) 901 + .arg(file2.path()) 902 + .stdout(Stdio::from(File::create(tee1.path())?)); 903 + compress.assert().success(); 904 + tee1.assert(predicate::path::is_file()); 904 905 905 - let mut compress2 = Command::cargo_bin("cmprss")?; 906 - compress2 907 - .current_dir(&working_dir) 908 - .arg("gzip") 909 - .stdin(Stdio::from(File::open(tee1.path())?)) 910 - .stdout(Stdio::from(File::create(tee2.path())?)); 911 - compress2.assert().success(); 912 - tee2.assert(predicate::path::is_file()); 906 + let mut compress2 = Command::cargo_bin("cmprss")?; 907 + compress2 908 + .current_dir(&working_dir) 909 + .arg("gzip") 910 + .stdin(Stdio::from(File::open(tee1.path())?)) 911 + .stdout(Stdio::from(File::create(tee2.path())?)); 912 + compress2.assert().success(); 913 + tee2.assert(predicate::path::is_file()); 913 914 914 - let mut extract = Command::cargo_bin("cmprss")?; 915 - extract 916 - .current_dir(&working_dir) 917 - .arg("gzip") 918 - .arg("--extract") 919 - .stdin(Stdio::from(File::open(tee2.path())?)) 920 - .stdout(Stdio::from(File::create(tee3.path())?)); 921 - extract.assert().success(); 922 - tee3.assert(predicate::path::is_file()); 915 + let mut extract = Command::cargo_bin("cmprss")?; 916 + extract 917 + .current_dir(&working_dir) 918 + .arg("gzip") 919 + .arg("--extract") 920 + .stdin(Stdio::from(File::open(tee2.path())?)) 921 + .stdout(Stdio::from(File::create(tee3.path())?)); 922 + extract.assert().success(); 923 + tee3.assert(predicate::path::is_file()); 923 924 924 - // Extract file to default filename 925 - let mut extract2 = Command::cargo_bin("cmprss")?; 926 - extract2 927 - .current_dir(&extract_dir) 928 - .arg("tar") 929 - .arg("--ignore-stdout") 930 - .arg("--extract") 931 - .stdin(Stdio::from(File::open(tee3.path())?)); 932 - extract2.assert().success(); 925 + // Extract file to default filename 926 + let mut extract2 = Command::cargo_bin("cmprss")?; 927 + extract2 928 + .current_dir(&extract_dir) 929 + .arg("tar") 930 + .arg("--ignore-stdout") 931 + .arg("--extract") 932 + .stdin(Stdio::from(File::open(tee3.path())?)); 933 + extract2.assert().success(); 933 934 934 - // Assert the files are identical 935 - extract_dir 936 - .child("test.txt") 937 - .assert(predicate::path::eq_file(file.path())); 938 - extract_dir 939 - .child("test2.txt") 940 - .assert(predicate::path::eq_file(file2.path())); 935 + // Assert the files are identical 936 + extract_dir 937 + .child("test.txt") 938 + .assert(predicate::path::eq_file(file.path())); 939 + extract_dir 940 + .child("test2.txt") 941 + .assert(predicate::path::eq_file(file2.path())); 941 942 942 - Ok(()) 943 + Ok(()) 944 + } 943 945 }
+41
tests/compare.rs
··· 1 + /// Compare the interoperability of cmprss with the official tools. 2 + 3 + #[allow(dead_code)] 4 + mod compare { 5 + /// Tests the tar comparisons 6 + #[test] 7 + #[cfg(feature = "interop")] 8 + fn tar() { 9 + test_with("tar"); 10 + } 11 + 12 + /// Tests the gzip comparisons 13 + #[test] 14 + #[cfg(feature = "interop")] 15 + fn gzip() { 16 + test_with("gzip"); 17 + } 18 + 19 + /// Tests the bzip2 comparisons 20 + #[test] 21 + #[cfg(feature = "interop")] 22 + fn bzip2() { 23 + test_with("bzip2"); 24 + } 25 + 26 + /// Tests the xz comparisons 27 + #[test] 28 + #[cfg(feature = "interop")] 29 + fn xz() { 30 + test_with("xz"); 31 + } 32 + 33 + /// Helper to spawn the script with any tool 34 + fn test_with(tool: &str) { 35 + let output = std::process::Command::new("bin/test.sh") 36 + .arg(tool) 37 + .output() 38 + .expect("Failed to execute command"); 39 + assert!(output.status.success()); 40 + } 41 + }