this repo has no description
0
fork

Configure Feed

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

at main 154 lines 5.3 kB view raw
1use assert_cmd::prelude::*; 2use assert_fs::prelude::*; 3use predicates::prelude::*; 4use std::{ 5 fs::File, 6 process::{Command, Stdio}, 7}; 8 9mod common; 10use common::*; 11 12mod lz4 { 13 use super::*; 14 15 mod roundtrip { 16 use super::*; 17 18 /// LZ4 roundtrip using explicit filenames 19 /// Compressing: input = test.txt, output = test.txt.lz4 20 /// Extracting: input = test.txt.lz4, output = test.txt 21 /// 22 /// ``` bash 23 /// cmprss lz4 test.txt test.txt.lz4 24 /// cmprss lz4 --extract test.txt.lz4 test.txt 25 /// ``` 26 #[test] 27 fn explicit() -> Result<(), Box<dyn std::error::Error>> { 28 let file = create_test_file("test.txt", "This is a test file for LZ4 compression.")?; 29 let working_dir = create_working_dir()?; 30 let archive = working_dir.child("test.txt.lz4"); 31 let extracted_file = working_dir.child("test_extracted.txt"); 32 33 // Compress the file 34 let mut compress = Command::cargo_bin("cmprss")?; 35 compress 36 .arg("lz4") 37 .arg("--compress") 38 .arg(file.path()) 39 .arg(archive.path()) 40 .arg("--progress=off"); 41 compress.assert().success(); 42 archive.assert(predicate::path::exists()); 43 44 // Extract the file 45 let mut extract = Command::cargo_bin("cmprss")?; 46 extract 47 .arg("lz4") 48 .arg("--extract") 49 .arg(archive.path()) 50 .arg(extracted_file.path()) 51 .arg("--progress=off"); 52 extract.assert().success(); 53 extracted_file.assert(predicate::path::exists()); 54 55 // Verify the contents 56 assert_files_equal(file.path(), extracted_file.path()); 57 58 Ok(()) 59 } 60 61 /// LZ4 roundtrip using stdin 62 /// Compressing: input = stdin, output = test.txt.lz4 63 /// Extracting: input = test.txt.lz4, output = test.txt 64 /// 65 /// ``` bash 66 /// cat test.txt | cmprss lz4 test.txt.lz4 67 /// cmprss lz4 --extract test.txt.lz4 test.txt 68 /// ``` 69 #[test] 70 fn stdin() -> Result<(), Box<dyn std::error::Error>> { 71 let file = create_test_file( 72 "test.txt", 73 "This is a test file for LZ4 compression via stdin.", 74 )?; 75 let working_dir = create_working_dir()?; 76 let archive = working_dir.child("test.txt.lz4"); 77 let extracted_file = working_dir.child("test_extracted.txt"); 78 79 // Compress the file via stdin 80 let mut compress = Command::cargo_bin("cmprss")?; 81 compress 82 .arg("lz4") 83 .arg("--compress") 84 .arg("--output") 85 .arg(archive.path()) 86 .arg("--progress=off") 87 .stdin(Stdio::from(File::open(file.path())?)); 88 compress.assert().success(); 89 archive.assert(predicate::path::exists()); 90 91 // Extract the file 92 let mut extract = Command::cargo_bin("cmprss")?; 93 extract 94 .arg("lz4") 95 .arg("--extract") 96 .arg(archive.path()) 97 .arg(extracted_file.path()) 98 .arg("--progress=off"); 99 extract.assert().success(); 100 extracted_file.assert(predicate::path::exists()); 101 102 // Verify the contents 103 assert_files_equal(file.path(), extracted_file.path()); 104 105 Ok(()) 106 } 107 108 /// LZ4 roundtrip using stdout 109 /// Compressing: input = test.txt, output = stdout 110 /// Extracting: input = test.txt.lz4, output = stdout 111 /// 112 /// ``` bash 113 /// cmprss lz4 test.txt > test.txt.lz4 114 /// cmprss lz4 --extract test.txt.lz4 > test.txt 115 /// ``` 116 #[test] 117 fn stdout() -> Result<(), Box<dyn std::error::Error>> { 118 let file = create_test_file( 119 "test.txt", 120 "This is a test file for LZ4 compression to stdout.", 121 )?; 122 let working_dir = create_working_dir()?; 123 let archive = working_dir.child("test.txt.lz4"); 124 let extracted_file = working_dir.child("test_extracted.txt"); 125 126 // Compress the file 127 let mut compress = Command::cargo_bin("cmprss")?; 128 compress 129 .arg("lz4") 130 .arg("--compress") 131 .arg(file.path()) 132 .arg("--progress=off") 133 .stdout(Stdio::from(File::create(archive.path())?)); 134 compress.assert().success(); 135 archive.assert(predicate::path::exists()); 136 137 // Extract the file to stdout 138 let mut extract = Command::cargo_bin("cmprss")?; 139 extract 140 .arg("lz4") 141 .arg("--extract") 142 .arg(archive.path()) 143 .arg("--progress=off") 144 .stdout(Stdio::from(File::create(extracted_file.path())?)); 145 extract.assert().success(); 146 extracted_file.assert(predicate::path::exists()); 147 148 // Verify the contents 149 assert_files_equal(file.path(), extracted_file.path()); 150 151 Ok(()) 152 } 153 } 154}