mirror of
https://github.com/ouch-org/ouch.git
synced 2025-07-22 17:40:17 +00:00
cli: More tests
This commit is contained in:
parent
65bc13e8fa
commit
e04aba8d53
@ -2,7 +2,7 @@ use std::{fmt, path::PathBuf};
|
|||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
UnknownExtensionError(String),
|
UnknownExtensionError(String),
|
||||||
MissingExtensionError(String),
|
MissingExtensionError(String),
|
||||||
|
61
src/test.rs
61
src/test.rs
@ -1,8 +1,11 @@
|
|||||||
|
use std::{convert::TryFrom};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod cli {
|
mod cli {
|
||||||
|
|
||||||
use std::{convert::TryFrom};
|
|
||||||
|
|
||||||
|
use std::convert::TryFrom;
|
||||||
use crate::cli::clap_app;
|
use crate::cli::clap_app;
|
||||||
use crate::cli::Command;
|
use crate::cli::Command;
|
||||||
use crate::file::File;
|
use crate::file::File;
|
||||||
@ -10,6 +13,7 @@ mod cli {
|
|||||||
use crate::extensions::CompressionExtension::*;
|
use crate::extensions::CompressionExtension::*;
|
||||||
use crate::error::OuchResult;
|
use crate::error::OuchResult;
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decompress_files_into_folder() -> OuchResult<()> {
|
fn decompress_files_into_folder() -> OuchResult<()> {
|
||||||
let matches = clap_app().
|
let matches = clap_app().
|
||||||
@ -40,7 +44,7 @@ mod cli {
|
|||||||
fn decompress_files() -> OuchResult<()> {
|
fn decompress_files() -> OuchResult<()> {
|
||||||
let matches = clap_app().
|
let matches = clap_app().
|
||||||
get_matches_from(
|
get_matches_from(
|
||||||
vec!["ouch", "-i", "file.zip"]
|
vec!["ouch", "-i", "file.zip", "file.tar"]
|
||||||
);
|
);
|
||||||
let command_from_matches = Command::try_from(matches)?;
|
let command_from_matches = Command::try_from(matches)?;
|
||||||
|
|
||||||
@ -53,6 +57,10 @@ mod cli {
|
|||||||
"file.zip".into(),
|
"file.zip".into(),
|
||||||
Zip,
|
Zip,
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"file.tar".into(),
|
||||||
|
Tar,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
output: None,
|
output: None,
|
||||||
@ -61,4 +69,51 @@ mod cli {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compress_files() -> OuchResult<()> {
|
||||||
|
let matches = clap_app().
|
||||||
|
get_matches_from(
|
||||||
|
vec!["ouch", "-i", "file", "file2.jpeg", "file3.ok", "-o", "file.tar"]
|
||||||
|
);
|
||||||
|
let command_from_matches = Command::try_from(matches)?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
command_from_matches,
|
||||||
|
Command { command_type: Compression(vec!["file".into(), "file2.jpeg".into(), "file3.ok".into()]), output: Some(File::WithExtension(("file.tar".into(), Tar))) }
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod cli_errors {
|
||||||
|
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use crate::cli::clap_app;
|
||||||
|
use crate::cli::Command;
|
||||||
|
use crate::file::File;
|
||||||
|
use crate::cli::CommandType::*;
|
||||||
|
use crate::extensions::CompressionExtension::*;
|
||||||
|
use crate::error::OuchResult;
|
||||||
|
use crate::error::Error;
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compress_files() -> OuchResult<()> {
|
||||||
|
let matches = clap_app().
|
||||||
|
get_matches_from(
|
||||||
|
vec!["ouch", "-i", "a_file", "file2.jpeg", "file3.ok"]
|
||||||
|
);
|
||||||
|
let res = Command::try_from(matches);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
Err(Error::InputsMustHaveBeenDecompressible("a_file".into()))
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user