this repo has no description
0
fork

Configure Feed

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

at main 176 lines 6.2 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 snappy { 13 use super::*; 14 15 mod roundtrip { 16 use super::*; 17 18 /// Snappy roundtrip using explicit filenames 19 /// Compressing: input = test.txt, output = test.txt.sz 20 /// Extracting: input = test.txt.sz, output = test.txt 21 /// 22 /// ``` bash 23 /// cmprss snappy test.txt test.txt.sz 24 /// cmprss snappy --extract --ignore-pipes test.txt.sz 25 /// ``` 26 #[test] 27 fn explicit() -> Result<(), Box<dyn std::error::Error>> { 28 let file = create_test_file("test.txt", "garbage data for testing")?; 29 let working_dir = create_working_dir()?; 30 let archive = working_dir.child("test.txt.sz"); 31 archive.assert(predicate::path::missing()); 32 33 let mut compress = Command::cargo_bin("cmprss")?; 34 compress 35 .current_dir(&working_dir) 36 .arg("snappy") 37 .arg(file.path()) 38 .arg(archive.path()); 39 compress.assert().success(); 40 archive.assert(predicate::path::is_file()); 41 42 let mut extract = Command::cargo_bin("cmprss")?; 43 extract 44 .current_dir(&working_dir) 45 .arg("snappy") 46 .arg("--ignore-pipes") 47 .arg("--extract") 48 .arg(archive.path()); 49 extract.assert().success(); 50 51 // Assert the files are identical 52 assert_files_equal(file.path(), &working_dir.child("test.txt")); 53 54 Ok(()) 55 } 56 57 /// Snappy roundtrip via the `sz` alias 58 /// Compressing: input = test.txt, output = test.txt.sz 59 /// Extracting: input = test.txt.sz, output = out.txt 60 /// 61 /// ``` bash 62 /// cmprss sz test.txt test.txt.sz 63 /// cmprss sz --extract test.txt.sz out.txt 64 /// ``` 65 #[test] 66 fn alias() -> Result<(), Box<dyn std::error::Error>> { 67 let file = create_test_file("test.txt", "garbage data for the alias test")?; 68 let working_dir = create_working_dir()?; 69 let archive = working_dir.child("test.txt.sz"); 70 71 let mut compress = Command::cargo_bin("cmprss")?; 72 compress 73 .current_dir(&working_dir) 74 .arg("sz") 75 .arg(file.path()) 76 .arg(archive.path()); 77 compress.assert().success(); 78 archive.assert(predicate::path::is_file()); 79 80 let output = working_dir.child("out.txt"); 81 let mut extract = Command::cargo_bin("cmprss")?; 82 extract 83 .current_dir(&working_dir) 84 .arg("sz") 85 .arg("--extract") 86 .arg(archive.path()) 87 .arg(output.path()); 88 extract.assert().success(); 89 90 assert_files_equal(file.path(), output.path()); 91 92 Ok(()) 93 } 94 95 /// Snappy roundtrip using stdin 96 /// Compressing: input = stdin, output = test.txt.sz 97 /// Extracting: input = stdin(test.txt.sz), output = out.txt 98 /// 99 /// ``` bash 100 /// cat test.txt | cmprss snappy test.txt.sz 101 /// cat test.txt.sz | cmprss snappy --extract out.txt 102 /// ``` 103 #[test] 104 fn stdin() -> Result<(), Box<dyn std::error::Error>> { 105 let file = create_test_file("test.txt", "garbage data for testing")?; 106 let working_dir = create_working_dir()?; 107 let archive = working_dir.child("test.txt.sz"); 108 archive.assert(predicate::path::missing()); 109 110 let mut compress = Command::cargo_bin("cmprss")?; 111 compress 112 .current_dir(&working_dir) 113 .arg("snappy") 114 .arg("test.txt.sz") 115 .stdin(Stdio::from(File::open(file.path())?)); 116 compress.assert().success(); 117 archive.assert(predicate::path::is_file()); 118 119 let mut extract = Command::cargo_bin("cmprss")?; 120 extract 121 .current_dir(&working_dir) 122 .arg("snappy") 123 .stdin(Stdio::from(File::open(archive.path())?)) 124 .arg("--extract") 125 .arg("out.txt"); 126 extract.assert().success(); 127 128 // Assert the files are identical 129 assert_files_equal(file.path(), &working_dir.child("out.txt")); 130 131 Ok(()) 132 } 133 134 /// Snappy roundtrip using stdout 135 /// Compressing: input = test.txt, output = stdout 136 /// Extracting: input = test.txt.sz, output = stdout 137 /// 138 /// ``` bash 139 /// cmprss snappy test.txt > test.txt.sz 140 /// cmprss snappy --extract test.txt.sz > out.txt 141 /// ``` 142 #[test] 143 fn stdout() -> Result<(), Box<dyn std::error::Error>> { 144 let file = create_test_file("test.txt", "garbage data for testing")?; 145 let working_dir = create_working_dir()?; 146 let archive = working_dir.child("test.txt.sz"); 147 archive.assert(predicate::path::missing()); 148 149 let mut compress = Command::cargo_bin("cmprss")?; 150 compress 151 .current_dir(&working_dir) 152 .arg("snappy") 153 .arg(file.path()) 154 .stdout(Stdio::from(File::create(archive.path())?)); 155 compress.assert().success(); 156 archive.assert(predicate::path::is_file()); 157 158 let output = working_dir.child("out.txt"); 159 output.assert(predicate::path::missing()); 160 161 let mut extract = Command::cargo_bin("cmprss")?; 162 extract 163 .current_dir(&working_dir) 164 .arg("snappy") 165 .arg("--extract") 166 .arg(archive.path()) 167 .stdout(Stdio::from(File::create(output.path())?)); 168 extract.assert().success(); 169 output.assert(predicate::path::is_file()); 170 171 assert_files_equal(file.path(), output.path()); 172 173 Ok(()) 174 } 175 } 176}