mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Moved tests to tests/ directory and crate
This commit is contained in:
parent
d5d1554b5e
commit
0f7bc363ce
3 changed files with 96 additions and 42 deletions
|
@ -3,7 +3,7 @@
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "0.4.10"
|
version = "0.4.10"
|
||||||
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
||||||
exclude = ["docs/*", "examples/*"]
|
exclude = ["docs/*", "examples/*", "tests/*"]
|
||||||
description = "A Command Line Argument Parser written in Rust"
|
description = "A Command Line Argument Parser written in Rust"
|
||||||
repository = "https://github.com/kbknapp/clap-rs.git"
|
repository = "https://github.com/kbknapp/clap-rs.git"
|
||||||
documentation = "http://kbknapp.github.io/clap-rs/docs/clap/index.html"
|
documentation = "http://kbknapp.github.io/clap-rs/docs/clap/index.html"
|
||||||
|
|
41
src/lib.rs
41
src/lib.rs
|
@ -14,45 +14,4 @@ mod args;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
95
tests/lib.rs
Normal file
95
tests/lib.rs
Normal file
|
@ -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")
|
||||||
|
]);
|
||||||
|
}
|
Loading…
Reference in a new issue