Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further testing to oof cli #38

Merged
merged 4 commits into from
Jun 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
attempt to assert
  • Loading branch information
Fabricio Dematte committed May 31, 2021
commit 09e9036301f1fd873f6a84cb7bdf62dfd68c3cef
34 changes: 31 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn canonicalize(path: impl AsRef<Path>) -> crate::Result<PathBuf> {
} else {
Err(io_err.into())
}
},
}
}
}

Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {

let command = Command::Compress { files, compressed_output_path };
ParsedArgs { command, flags }
},
}
// Defaults to decompression when there is no subcommand
None => {
flags_info.push(arg_flag!('o', "output"));
Expand All @@ -130,9 +130,37 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {

let command = Command::Decompress { files, output_folder };
ParsedArgs { command, flags }
},
}
_ => unreachable!("You should match each subcommand passed."),
};

Ok(parsed_args)
}

#[cfg(test)]
mod tests {

use super::*;
use std::process::Command;

fn gen_args(text: &str) -> Vec<OsString> {
let args = text.split_whitespace();
args.map(OsString::from).collect()
}

#[test]
fn test_something() {
let args = gen_args("ouch foo.zip bar.zip");
let result = parse_args_from(args).unwrap(); // ERROR: file `ouch` not found
marcospb19 marked this conversation as resolved.
Show resolved Hide resolved

assert!(false)
}

#[test]
fn test_command_execution() {
let args = gen_args("foo bar");
let cmd = Command::new("ouch").args(args).output().unwrap(); // ErrorKind: File not Found

assert!(false)
}
}