diff --git a/src/args.rs b/src/args.rs index 2c41012..006a715 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,5 +1,8 @@ use clap::{App, AppSettings, ArgMatches}; +#[cfg(test)] +use clap::Result; + fn build() -> App<'static, 'static> { return App::new(crate_name!()) @@ -17,3 +20,8 @@ fn build() -> App<'static, 'static> { pub fn get_matches() -> ArgMatches<'static> { return build().get_matches(); } + +#[cfg(test)] +pub fn get_matches_for(args : Vec) -> Result> { + return build().get_matches_from_safe(args); +} diff --git a/src/tests/args.rs b/src/tests/args.rs index 2a034ec..d44b261 100644 --- a/src/tests/args.rs +++ b/src/tests/args.rs @@ -1,6 +1,7 @@ use args; #[test] -fn it_works() { - assert_eq!(4, 4); +fn error_if_no_subcommand() { + let out = args::get_matches_for(vec!("mdp".into())); + assert!(out.is_err()); }