Skip to content

Commit

Permalink
Add some more main argument-parsing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
  • Loading branch information
rye committed Aug 31, 2021
1 parent 739411a commit 5ae19fe
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@ fn main() -> eb::ExecutionResult {

#[cfg(test)]
mod tests {
use super::{app, max};

fn t_matches_from<'a>(argv: &[&str]) -> clap::ArgMatches<'a> {
let app = app();
let app = super::app();
app.get_matches_from(argv)
}

mod max {
use super::*;
use super::{super::max, t_matches_from};

#[test]
fn max_none() {
Expand All @@ -142,7 +140,7 @@ mod tests {

#[test]
fn max_short_valid() {
let argv = ["eb", "-x", "10"];
let argv = ["eb", "-x", "10", "cmd"];
let matches = t_matches_from(&argv);
let max = max(&matches);

Expand All @@ -151,7 +149,7 @@ mod tests {

#[test]
fn max_short_invalid() {
let argv = ["eb", "-x", "notanumber"];
let argv = ["eb", "-x", "notanumber", "cmd"];
let matches = t_matches_from(&argv);
let max = max(&matches);

Expand All @@ -163,4 +161,56 @@ mod tests {
);
}
}

mod command {
use super::{super::command, t_matches_from};

#[test]
fn command_none() {
let argv = ["eb"];
let matches = t_matches_from(&argv);
let command = command(&matches);

assert!(command.is_none());
// TODO Test the actual population of `command` here.
// Gated behind https://github.com/rust-lang/rust/issues/44434.
}

#[test]
fn command_no_other_args_some() {
let argv = ["eb", "cmd"];
let matches = t_matches_from(&argv);
let command = command(&matches);

assert!(command.is_some());
// TODO Test the actual population of `command` here.
// Gated behind https://github.com/rust-lang/rust/issues/44434.
}

#[test]
fn command_some_max_pre() {
let argv = ["eb", "-x", "10", "cmd"];
let matches = t_matches_from(&argv);
let command = command(&matches);
let max = super::super::max(&matches);

assert!(command.is_some());
// TODO Test the actual population of `command` here.
// Gated behind https://github.com/rust-lang/rust/issues/44434.
assert_eq!(max, Ok(Some(10_u32)));
}

#[test]
fn command_some_max_post_none() {
let argv = ["eb", "cmd", "-x", "10"];
let matches = t_matches_from(&argv);
let command = command(&matches);
let max = super::super::max(&matches);

assert!(command.is_some());
// TODO Test the actual population of `command` here.
// Gated behind https://github.com/rust-lang/rust/issues/44434.
assert_eq!(max, Ok(None));
}
}
}

0 comments on commit 5ae19fe

Please sign in to comment.