mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Merge pull request #211 from ouch-org/revert-208-test
Revert "Add an integration test"
This commit is contained in:
commit
cb6d65c79a
@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use std::{io::Write, iter::once, path::PathBuf};
|
use std::{iter::once, path::PathBuf};
|
||||||
|
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
use parse_display::Display;
|
use parse_display::Display;
|
||||||
@ -120,34 +120,3 @@ fn multiple_files(
|
|||||||
ouch!("d", archive, "-d", after);
|
ouch!("d", archive, "-d", after);
|
||||||
assert_same_directory(before, after, !matches!(ext, DirectoryExtension::Zip));
|
assert_same_directory(before, after, !matches!(ext, DirectoryExtension::Zip));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_compress_decompress() {
|
|
||||||
let dir = tempdir().unwrap();
|
|
||||||
let dir = dir.path();
|
|
||||||
let i1 = dir.join("i1");
|
|
||||||
std::fs::write(&i1, "ouch").unwrap();
|
|
||||||
let o1 = dir.join("o1.tar");
|
|
||||||
let out = dir.join("out");
|
|
||||||
std::fs::create_dir(&out).unwrap();
|
|
||||||
|
|
||||||
{
|
|
||||||
assert!(ouch_interactive!("c", &i1, &dir.join("o1.tar")).0.wait().unwrap().success());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let (_ouch, mut sin, sout) = ouch_interactive!("d", &o1, "-d", &out);
|
|
||||||
assert!(sout.recv().unwrap().starts_with("Do you want to overwrite"));
|
|
||||||
writeln!(&mut sin, "n").unwrap();
|
|
||||||
assert!(!out.join("i1").exists());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let (_ouch, mut sin, sout) = ouch_interactive!("d", &o1, "-d", &out);
|
|
||||||
assert!(sout.recv().unwrap().starts_with("Do you want to overwrite"));
|
|
||||||
writeln!(&mut sin, "Y").unwrap();
|
|
||||||
assert!(sout.recv().unwrap().ends_with("created."));
|
|
||||||
assert!(sout.recv().unwrap().ends_with("extracted. (4.00 B)"));
|
|
||||||
assert!(sout.recv().unwrap().starts_with("[INFO] Successfully decompressed archive"));
|
|
||||||
assert_eq!(sout.recv().unwrap(), "[INFO] Files unpacked: 1");
|
|
||||||
assert_eq!(std::fs::read(&dir.join("out/i1")).unwrap(), b"ouch");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,6 @@ use std::{io::Write, path::PathBuf};
|
|||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
|
||||||
/// Run ouch with cargo run
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! ouch {
|
macro_rules! ouch {
|
||||||
($($e:expr),*) => {
|
($($e:expr),*) => {
|
||||||
@ -14,40 +13,6 @@ macro_rules! ouch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run ouch with cargo run and returns (child process, stdin handle and stdout channel receiver)
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! ouch_interactive {
|
|
||||||
($($e:expr),*) => {
|
|
||||||
{
|
|
||||||
let mut p = ::std::process::Command::new("cargo")
|
|
||||||
.stdin(::std::process::Stdio::piped())
|
|
||||||
.stdout(::std::process::Stdio::piped())
|
|
||||||
.arg("run")
|
|
||||||
.arg("--")
|
|
||||||
$(.arg($e))*
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let sin = p.stdin.take().unwrap();
|
|
||||||
let mut sout = p.stdout.take().unwrap();
|
|
||||||
|
|
||||||
let (tx, rx) = ::std::sync::mpsc::channel();
|
|
||||||
::std::thread::spawn(move ||{
|
|
||||||
// This thread/loop is used so we can make the output more deterministic
|
|
||||||
let mut s = [0; 1024];
|
|
||||||
loop {
|
|
||||||
let n = ::std::io::Read::read(&mut sout, &mut s).unwrap();
|
|
||||||
let s = ::std::string::String::from_utf8(s[..n].to_vec()).unwrap();
|
|
||||||
for l in s.lines() {
|
|
||||||
tx.send(l.to_string()).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
(p, sin, rx)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// write random content to a file
|
// write random content to a file
|
||||||
pub fn write_random_content(file: &mut impl Write, rng: &mut impl RngCore) {
|
pub fn write_random_content(file: &mut impl Write, rng: &mut impl RngCore) {
|
||||||
let data = &mut Vec::with_capacity((rng.next_u32() % 8192) as usize);
|
let data = &mut Vec::with_capacity((rng.next_u32() % 8192) as usize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user