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