2021-07-01 19:57:37 +05:30
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
//-----------------------------------------
|
|
|
|
// test invalid arguments
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_missing_output_option<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: OutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
|
|
|
let stderr = run_fail(P::path(), &["-i", input.to_str().unwrap()])?;
|
|
|
|
assert!(stderr.contains(P::missing_output_arg()));
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_missing_output_option {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn missing_output_option() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_missing_output_option::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_output_file_not_found<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: OutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
let stderr = run_fail(
|
2021-07-06 07:21:27 +05:30
|
|
|
P::path(),
|
2021-07-01 19:57:37 +05:30
|
|
|
&["-i", input.to_str().unwrap(), "-o", "no-such-file"],
|
|
|
|
)?;
|
2021-07-06 07:21:27 +05:30
|
|
|
assert!(stderr.contains(<P as OutputProgram>::file_not_found()));
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_output_file_not_found {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn output_file_not_found() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_output_file_not_found::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_output_cannot_be_a_directory<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: OutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
|
|
|
let stderr = run_fail(P::path(), &["-i", input.to_str().unwrap(), "-o", "/tmp"])?;
|
|
|
|
assert!(stderr.contains("Not a block device or regular file"));
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_output_cannot_be_a_directory {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn output_cannot_be_a_directory() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_output_cannot_be_a_directory::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_unwritable_output_file<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: OutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
let output = td.mk_path("meta.bin");
|
|
|
|
let _file = file_utils::create_sized_file(&output, 4096);
|
|
|
|
duct::cmd!("chmod", "-w", &output).run()?;
|
|
|
|
|
|
|
|
let stderr = run_fail(
|
2021-07-06 07:21:27 +05:30
|
|
|
P::path(),
|
2021-07-01 19:57:37 +05:30
|
|
|
&[
|
|
|
|
"-i",
|
|
|
|
input.to_str().unwrap(),
|
|
|
|
"-o",
|
|
|
|
output.to_str().unwrap(),
|
|
|
|
],
|
|
|
|
)?;
|
|
|
|
assert!(stderr.contains("Permission denied"));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_unwritable_output_file {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn unwritable_output_file() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_unwritable_output_file::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// test invalid content
|
|
|
|
|
|
|
|
// currently thin/cache_restore only
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_tiny_output_file<'a, P>() -> Result<()>
|
2021-07-01 19:57:37 +05:30
|
|
|
where
|
2021-07-06 07:21:27 +05:30
|
|
|
P: BinaryOutputProgram<'a>,
|
2021-07-01 19:57:37 +05:30
|
|
|
{
|
|
|
|
let mut td = TestDir::new()?;
|
2021-07-06 07:21:27 +05:30
|
|
|
let input = P::mk_valid_input(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
let output = td.mk_path("meta.bin");
|
|
|
|
let _file = file_utils::create_sized_file(&output, 4096);
|
|
|
|
|
|
|
|
let stderr = run_fail(
|
2021-07-06 07:21:27 +05:30
|
|
|
P::path(),
|
2021-07-01 19:57:37 +05:30
|
|
|
&[
|
|
|
|
"-i",
|
|
|
|
input.to_str().unwrap(),
|
|
|
|
"-o",
|
|
|
|
output.to_str().unwrap(),
|
|
|
|
],
|
|
|
|
)?;
|
|
|
|
assert!(stderr.contains("Output file too small"));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_tiny_output_file {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn tiny_output_file() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_tiny_output_file::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------
|