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 gzip {
13 use super::*;
14
15 mod roundtrip {
16 use super::*;
17
18 /// Gzip roundtrip using stdin
19 /// Compressing: input = stdin, output = test.txt.gz
20 /// Extracting: input = test.txt.gz, output = test.txt
21 ///
22 /// ``` bash
23 /// cat test.txt | cmprss gzip test.txt.gz
24 /// cmprss gzip --ignore-pipes --extract test.txt.gz
25 /// ```
26 #[test]
27 fn stdin() -> 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.gz");
31 archive.assert(predicate::path::missing());
32
33 // Pipe file to stdin
34 let mut compress = Command::cargo_bin("cmprss")?;
35 compress
36 .current_dir(&working_dir)
37 .arg("gzip")
38 .arg("test.txt.gz")
39 .stdin(Stdio::from(File::open(file.path())?));
40 compress.assert().success();
41 archive.assert(predicate::path::is_file());
42
43 let mut extract = Command::cargo_bin("cmprss")?;
44 extract
45 .current_dir(&working_dir)
46 .arg("gzip")
47 .arg("--ignore-pipes")
48 .arg("--extract")
49 .arg(archive.path());
50 extract.assert().success();
51
52 // Assert the files are identical
53 assert_files_equal(file.path(), &working_dir.child("test.txt"));
54
55 Ok(())
56 }
57
58 /// Gzip roundtrip using filename inference
59 /// Compressing: input = stdin, output = default filename (archive.gz)
60 /// Extracting: input = archive.gz, output = default filename (archive)
61 ///
62 /// ``` bash
63 /// cat test.txt | cmprss gzip
64 /// cmprss gzip --ignore-pipes --extract archive.gz
65 /// ```
66 #[test]
67 fn inferred_output_filenames() -> Result<(), Box<dyn std::error::Error>> {
68 let file = create_test_file("test.txt", "garbage data for testing")?;
69 let working_dir = create_working_dir()?;
70 let archive = working_dir.child("archive.gz"); // default filename
71 archive.assert(predicate::path::missing());
72
73 // Pipe file to stdin
74 let mut compress = Command::cargo_bin("cmprss")?;
75 compress
76 .current_dir(&working_dir)
77 .arg("gzip")
78 .arg("--ignore-stdout")
79 .stdin(Stdio::from(File::open(file.path())?));
80 compress.assert().success();
81 archive.assert(predicate::path::is_file());
82
83 let mut extract = Command::cargo_bin("cmprss")?;
84 extract
85 .current_dir(&working_dir)
86 .arg("gzip")
87 .arg("--ignore-pipes")
88 .arg("--extract")
89 .arg(archive.path());
90 extract.assert().success();
91
92 // Assert the files are identical
93 assert_files_equal(file.path(), &working_dir.child("archive"));
94
95 Ok(())
96 }
97 }
98}