diff --git a/Cargo.toml b/Cargo.toml index 9b9e07b5..df920cff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "clap" version = "0.4.10" authors = ["Kevin K. "] -exclude = ["docs/*", "examples/*"] +exclude = ["docs/*", "examples/*", "tests/*"] description = "A Command Line Argument Parser written in Rust" repository = "https://github.com/kbknapp/clap-rs.git" documentation = "http://kbknapp.github.io/clap-rs/docs/clap/index.html" diff --git a/src/lib.rs b/src/lib.rs index 078a9a6e..986feb51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,45 +14,4 @@ mod args; #[cfg(test)] mod tests { use super::*; - - #[test] - #[should_panic] - fn unique_arg_names(){ - App::new("some").args(vec![ - Arg::new("arg").short("a"), - Arg::new("arg").short("b") - ]); - } - #[test] - #[should_panic] - fn unique_arg_shorts(){ - App::new("some").args(vec![ - Arg::new("arg1").short("a"), - Arg::new("arg2").short("a") - ]); - } - #[test] - #[should_panic] - fn unique_arg_longs(){ - App::new("some").args(vec![ - Arg::new("arg1").long("long"), - Arg::new("arg2").long("long") - ]); - } - #[test] - fn create_app(){ - App::new("some").about("about").author("author").version("1.0"); - } - #[test] - fn create_arg_flag(){ - Arg::new("some").short("a").long("long").help("help with some arg").multiple(true); - } - #[test] - fn create_arg_pos(){ - Arg::new("some").index(1).help("help with some arg").required(true); - } - #[test] - fn create_arg_opt(){ - Arg::new("some").short("s").long("some").takes_value(true).help("help with some arg").required(true); - } } diff --git a/tests/lib.rs b/tests/lib.rs new file mode 100644 index 00000000..a8e2a025 --- /dev/null +++ b/tests/lib.rs @@ -0,0 +1,95 @@ +extern crate clap; + +use clap::{App, Arg, SubCommand}; + +#[test] +fn create_app() { + let _ = App::new("test").version("1.0").author("kevin").about("does awesome things").get_matches(); +} +#[test] +fn add_multiple_arg() { + let _ = App::new("test") + .args( vec![ + Arg::new("test").short("s"), + Arg::new("test2").short("l")]) + .get_matches(); +} + +#[test] +fn create_flag() { + let _ = App::new("test") + .arg(Arg::new("test") + .short("t") + .long("test") + .help("testing testing")) + .get_matches(); +} +#[test] +fn create_positional() { + let _ = App::new("test") + .arg(Arg::new("test") + .index(1) + .help("testing testing")) + .get_matches(); +} +#[test] +fn create_option() { + let _ = App::new("test") + .arg(Arg::new("test") + .short("t") + .long("test") + .takes_value(true) + .help("testing testing")) + .get_matches(); +} +#[test] +fn create_subcommand() { + let _ = App::new("test") + .subcommand(SubCommand::new("some") + .arg(Arg::new("test") + .short("t") + .long("test") + .takes_value(true) + .help("testing testing"))) + .arg(Arg::new("other").long("other")) + .get_matches(); +} +#[test] +fn create_multiple_subcommands() { + let _ = App::new("test") + .subcommands(vec![ SubCommand::new("some") + .arg(Arg::new("test") + .short("t") + .long("test") + .takes_value(true) + .help("testing testing")), + SubCommand::new("add") + .arg(Arg::new("roster").short("r"))]) + .arg(Arg::new("other").long("other")) + .get_matches(); +} + +#[test] +#[should_panic] +fn unique_arg_names(){ + App::new("some").args(vec![ + Arg::new("arg").short("a"), + Arg::new("arg").short("b") + ]); +} +#[test] +#[should_panic] +fn unique_arg_shorts(){ + App::new("some").args(vec![ + Arg::new("arg1").short("a"), + Arg::new("arg2").short("a") + ]); +} +#[test] +#[should_panic] +fn unique_arg_longs(){ + App::new("some").args(vec![ + Arg::new("arg1").long("long"), + Arg::new("arg2").long("long") + ]); +} \ No newline at end of file