this repo has no description
0
fork

Configure Feed

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

test: add some tar cli tests with target inferrence

+148 -7
+7 -3
src/main.rs
··· 49 49 50 50 #[derive(Args, Debug)] 51 51 struct CommonArgs { 52 - /// Input/Output file/directory 52 + /// Input file/directory 53 53 #[arg(short, long)] 54 54 input: Option<String>, 55 55 ··· 69 69 /// This consists of all the inputs followed by the single output, with intelligent fallback to stdin/stdout. 70 70 #[arg()] 71 71 io_list: Vec<String>, 72 + 73 + /// Ignore pipes when inferring I/O 74 + #[arg(long)] 75 + ignore_pipes: bool, 72 76 } 73 77 74 78 #[derive(Args, Debug)] ··· 212 216 // Fallback to stdin/stdout if we're missing files 213 217 let cmprss_input = match inputs.is_empty() { 214 218 true => { 215 - if !std::io::stdin().is_terminal() { 219 + if !std::io::stdin().is_terminal() && !&common_args.ignore_pipes { 216 220 CmprssInput::Pipe(std::io::stdin()) 217 221 } else { 218 222 return Err(io::Error::new(io::ErrorKind::Other, "No specified input")); ··· 223 227 let cmprss_output = match output { 224 228 Some(path) => CmprssOutput::Path(path.to_path_buf()), 225 229 None => { 226 - if !std::io::stdout().is_terminal() { 230 + if !std::io::stdout().is_terminal() && !&common_args.ignore_pipes { 227 231 CmprssOutput::Pipe(std::io::stdout()) 228 232 } else { 229 233 match action {
+141 -4
tests/cli.rs
··· 3 3 use predicates::prelude::*; 4 4 use std::process::Command; 5 5 6 - #[allow(dead_code)] 6 + /// Tar roundtrip with a single file 7 + /// 8 + /// ``` bash 9 + /// cmprss tar test.txt archive.tar 10 + /// cmprss tar --extract archive.tar . 11 + /// ``` 7 12 #[test] 8 - fn tar_roundtrip() -> Result<(), Box<dyn std::error::Error>> { 13 + fn tar_roundtrip_explicit() -> Result<(), Box<dyn std::error::Error>> { 9 14 let file = assert_fs::NamedTempFile::new("test.txt")?; 10 15 file.write_str("garbage data for testing")?; 11 16 let working_dir = assert_fs::TempDir::new()?; ··· 21 26 extract 22 27 .arg("tar") 23 28 .arg("--extract") 24 - .arg("--input") 29 + .arg(archive.path()) 30 + .arg(working_dir.path()); 31 + extract.assert().success(); 32 + 33 + // Assert the files are identical 34 + working_dir 35 + .child("test.txt") 36 + .assert(predicate::path::eq_file(file.path())); 37 + 38 + Ok(()) 39 + } 40 + 41 + /// Tar roundtrip with multiple files 42 + /// 43 + /// ``` bash 44 + /// cmprss tar test.txt test2.txt archive.tar 45 + /// cmprss tar --extract archive.tar . 46 + /// ``` 47 + #[test] 48 + fn tar_roundtrip_explicit_two() -> Result<(), Box<dyn std::error::Error>> { 49 + let file = assert_fs::NamedTempFile::new("test.txt")?; 50 + file.write_str("garbage data for testing")?; 51 + let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 52 + file2.write_str("more garbage data for testing")?; 53 + let working_dir = assert_fs::TempDir::new()?; 54 + let archive = working_dir.child("archive.tar"); 55 + archive.assert(predicate::path::missing()); 56 + 57 + let mut compress = Command::cargo_bin("cmprss")?; 58 + compress 59 + .arg("tar") 60 + .arg(file.path()) 61 + .arg(file2.path()) 62 + .arg(archive.path()); 63 + compress.assert().success(); 64 + archive.assert(predicate::path::is_file()); 65 + 66 + let mut extract = Command::cargo_bin("cmprss")?; 67 + extract 68 + .arg("tar") 69 + .arg("--extract") 25 70 .arg(archive.path()) 26 - .arg("--output") 27 71 .arg(working_dir.path()); 28 72 extract.assert().success(); 29 73 ··· 31 75 working_dir 32 76 .child("test.txt") 33 77 .assert(predicate::path::eq_file(file.path())); 78 + working_dir 79 + .child("test2.txt") 80 + .assert(predicate::path::eq_file(file2.path())); 81 + 82 + Ok(()) 83 + } 84 + 85 + /// Tar roundtrip with a single file inferring output 86 + /// Compressing: output = './archive.tar' 87 + /// Extracting: output = '.' 88 + /// 89 + /// ``` bash 90 + /// cmprss tar test.txt 91 + /// cmprss tar --extract archive.tar 92 + /// ``` 93 + #[test] 94 + fn tar_roundtrip_implicit() -> Result<(), Box<dyn std::error::Error>> { 95 + let file = assert_fs::NamedTempFile::new("test.txt")?; 96 + file.write_str("garbage data for testing")?; 97 + let working_dir = assert_fs::TempDir::new()?.into_persistent(); 98 + let archive = working_dir.child("archive.tar"); 99 + archive.assert(predicate::path::missing()); 100 + 101 + let mut compress = Command::cargo_bin("cmprss")?; 102 + compress 103 + .current_dir(&working_dir) 104 + .arg("tar") 105 + .arg("--ignore-pipes") 106 + .arg(file.path()); 107 + compress.assert().success(); 108 + archive.assert(predicate::path::is_file()); 109 + 110 + let mut extract = Command::cargo_bin("cmprss")?; 111 + extract 112 + .current_dir(&working_dir) 113 + .arg("tar") 114 + .arg("--ignore-pipes") 115 + .arg("--extract") 116 + .arg(archive.path()); 117 + extract.assert().success(); 118 + 119 + // Assert the files are identical 120 + working_dir 121 + .child("test.txt") 122 + .assert(predicate::path::eq_file(file.path())); 123 + 124 + Ok(()) 125 + } 126 + 127 + /// Tar roundtrip with multiple files inferring output 128 + /// Compressing: output = './archive.tar' 129 + /// Extracting: output = '.' 130 + /// 131 + /// ``` bash 132 + /// cmprss tar test.txt test2.txt 133 + /// cmprss tar --extract archive.tar 134 + /// ``` 135 + #[test] 136 + fn tar_roundtrip_implicit_two() -> Result<(), Box<dyn std::error::Error>> { 137 + let file = assert_fs::NamedTempFile::new("test.txt")?; 138 + file.write_str("garbage data for testing")?; 139 + let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 140 + file2.write_str("more garbage data for testing")?; 141 + let working_dir = assert_fs::TempDir::new()?.into_persistent(); 142 + let archive = working_dir.child("archive.tar"); 143 + archive.assert(predicate::path::missing()); 144 + 145 + let mut compress = Command::cargo_bin("cmprss")?; 146 + compress 147 + .current_dir(&working_dir) 148 + .arg("tar") 149 + .arg("--ignore-pipes") 150 + .arg(file.path()) 151 + .arg(file2.path()); 152 + compress.assert().success(); 153 + archive.assert(predicate::path::is_file()); 154 + 155 + let mut extract = Command::cargo_bin("cmprss")?; 156 + extract 157 + .current_dir(&working_dir) 158 + .arg("tar") 159 + .arg("--ignore-pipes") 160 + .arg("--extract") 161 + .arg(archive.path()); 162 + extract.assert().success(); 163 + 164 + // Assert the files are identical 165 + working_dir 166 + .child("test.txt") 167 + .assert(predicate::path::eq_file(file.path())); 168 + working_dir 169 + .child("test2.txt") 170 + .assert(predicate::path::eq_file(file2.path())); 34 171 35 172 Ok(()) 36 173 }