chore(Tests): had to remove external clap-test crate...sad face

This commit is contained in:
Kevin K 2016-05-09 22:46:09 -04:00
parent 6c7b2da856
commit b42ca0b5ab
14 changed files with 245 additions and 59 deletions

View file

@ -1,5 +1,5 @@
<a name="v2.4.2"></a>
### v2.4.2 (2016-05-10)
<a name="v2.4.3"></a>
### v2.4.3 (2016-05-10)
#### Bug Fixes
@ -15,7 +15,15 @@
* moves positionals to standard <> formatting ([03dfe5ce](https://github.com/kbknapp/clap-rs/commit/03dfe5ceff1d63f172788ff688567ddad9fe119b))
* default help subcommand string has been shortened ([5b7fe8e4](https://github.com/kbknapp/clap-rs/commit/5b7fe8e4161e43ab19e2e5fcf55fbe46791134e9), closes [#494](https://github.com/kbknapp/clap-rs/issues/494))
<a name="v2.4.2"></a>
### v2.4.3 (2016-05-10)
* Ghost Release
<a name="v2.4.1"></a>
### v2.4.3 (2016-05-10)
* Ghost Release
<a name="v2.4.0"></a>
## v2.4.0 (2016-05-02)

View file

@ -1,7 +1,7 @@
[package]
name = "clap"
version = "2.4.2"
version = "2.4.3"
authors = ["Kevin K. <kbknapp@gmail.com>"]
exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
description = "A simple to use, efficient, and full featured Command Line Argument Parser"
@ -22,7 +22,7 @@ clippy = { version = "=0.0.64", optional = true }
unicode-width = { version = "~0.1.3", optional = true }
[dev-dependencies]
clap-test = "0.1.1"
regex = "~0.1.69"
[features]
default = ["suggestions", "color", "wrap_help"]

View file

@ -38,7 +38,7 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
## What's New
Here's what's new in v2.4.2
Here's what's new in v2.4.3
* Bug Fixes
* Usage strings get de-deuplicated when there are args which are also part ``ArgGroup`s`

165
clap-test.rs Normal file
View file

@ -0,0 +1,165 @@
#[allow(unused_imports, dead_code)]
mod test {
use std::str;
use std::io::Write;
use regex::Regex;
use clap::{App, Arg, SubCommand, ArgGroup};
pub fn complex_app() -> App<'static, 'static> {
let args = "-o --option=[opt]... 'tests options'
[positional] 'tests positionals'";
let opt3_vals = ["fast", "slow"];
let pos3_vals = ["vi", "emacs"];
App::new("clap-test")
.version("v1.4.8")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.args_from_usage(args)
.arg(Arg::from_usage("-f --flag... 'tests flags'")
.global(true))
.args(&[
Arg::from_usage("[flag2] -F 'tests flags with exclusions'").conflicts_with("flag").requires("long-option-2"),
Arg::from_usage("--long-option-2 [option2] 'tests long options with exclusions'").conflicts_with("option").requires("positional2"),
Arg::from_usage("[positional2] 'tests positionals with exclusions'"),
Arg::from_usage("-O --Option [option3] 'specific vals'").possible_values(&opt3_vals),
Arg::from_usage("[positional3]... 'tests specific values'").possible_values(&pos3_vals),
Arg::from_usage("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
Arg::from_usage("--multvalsmo... [one] [two] 'Tests mutliple values, and mult occs'"),
Arg::from_usage("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
Arg::from_usage("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
])
.subcommand(SubCommand::with_name("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
.arg_from_usage("-o --option [scoption]... 'tests options'")
.arg_from_usage("[scpositional] 'tests positionals'"))
}
pub fn check_err_output(a: App, args: &str, out: &str, use_stderr: bool) {
let res = a.get_matches_from_safe(args.split(' ').collect::<Vec<_>>());
let re = Regex::new("\x1b[^m]*m").unwrap();
let mut w = vec![];
let err = res.unwrap_err();
err.write_to(&mut w).unwrap();
let err_s = str::from_utf8(&w).unwrap();
assert_eq!(re.replace_all(err_s, ""), out);
assert_eq!(use_stderr, err.use_stderr());
}
pub fn check_help(mut a: App, out: &str) {
// We call a get_matches method to cause --help and --version to be built
let _ = a.get_matches_from_safe_borrow(vec![""]);
// Now we check the output of print_help()
let mut help = vec![];
a.write_help(&mut help).ok().expect("failed to print help");
assert_eq!(str::from_utf8(&help).unwrap(), out);
}
pub fn check_complex_output(args: &str, out: &str) {
let mut w = vec![];
let matches = complex_app().get_matches_from(args.split(' ').collect::<Vec<_>>());
if matches.is_present("flag") {
writeln!(w, "flag present {} times", matches.occurrences_of("flag")).unwrap();
} else {
writeln!(w, "flag NOT present").unwrap();
}
if matches.is_present("option") {
if let Some(v) = matches.value_of("option") {
writeln!(w, "option present {} times with value: {}",matches.occurrences_of("option"), v).unwrap();
}
if let Some(ov) = matches.values_of("option") {
for o in ov {
writeln!(w, "An option: {}", o).unwrap();
}
}
} else {
writeln!(w, "option NOT present").unwrap();
}
if let Some(p) = matches.value_of("positional") {
writeln!(w, "positional present with value: {}", p).unwrap();
} else {
writeln!(w, "positional NOT present").unwrap();
}
if matches.is_present("flag2") {
writeln!(w, "flag2 present").unwrap();
writeln!(w, "option2 present with value of: {}", matches.value_of("long-option-2").unwrap()).unwrap();
writeln!(w, "positional2 present with value of: {}", matches.value_of("positional2").unwrap()).unwrap();
} else {
writeln!(w, "flag2 NOT present").unwrap();
writeln!(w, "option2 maybe present with value of: {}", matches.value_of("long-option-2").unwrap_or("Nothing")).unwrap();
writeln!(w, "positional2 maybe present with value of: {}", matches.value_of("positional2").unwrap_or("Nothing")).unwrap();
}
let _ = match matches.value_of("Option3").unwrap_or("") {
"fast" => writeln!(w, "option3 present quickly"),
"slow" => writeln!(w, "option3 present slowly"),
_ => writeln!(w, "option3 NOT present")
};
let _ = match matches.value_of("positional3").unwrap_or("") {
"vi" => writeln!(w, "positional3 present in vi mode"),
"emacs" => writeln!(w, "positional3 present in emacs mode"),
_ => writeln!(w, "positional3 NOT present")
};
if matches.is_present("option") {
if let Some(v) = matches.value_of("option") {
writeln!(w, "option present {} times with value: {}",matches.occurrences_of("option"), v).unwrap();
}
if let Some(ov) = matches.values_of("option") {
for o in ov {
writeln!(w, "An option: {}", o).unwrap();
}
}
} else {
writeln!(w, "option NOT present").unwrap();
}
if let Some(p) = matches.value_of("positional") {
writeln!(w, "positional present with value: {}", p).unwrap();
} else {
writeln!(w, "positional NOT present").unwrap();
}
if matches.is_present("subcmd") {
writeln!(w, "subcmd present").unwrap();
if let Some(matches) = matches.subcommand_matches("subcmd") {
if matches.is_present("flag") {
writeln!(w, "flag present {} times", matches.occurrences_of("flag")).unwrap();
} else {
writeln!(w, "flag NOT present").unwrap();
}
if matches.is_present("option") {
if let Some(v) = matches.value_of("option") {
writeln!(w, "scoption present with value: {}", v).unwrap();
}
if let Some(ov) = matches.values_of("option") {
for o in ov {
writeln!(w, "An scoption: {}", o).unwrap();
}
}
} else {
writeln!(w, "scoption NOT present").unwrap();
}
if let Some(p) = matches.value_of("scpositional") {
writeln!(w, "scpositional present with value: {}", p).unwrap();
}
}
} else {
writeln!(w, "subcmd NOT present").unwrap();
}
let res = str::from_utf8(&w).unwrap();
assert_eq!(res, out);
}
}

View file

@ -8,7 +8,6 @@ digraph dependencies {
N6[label="unicode-width",style=dashed];
N7[label="vec_map"];
N8[label="yaml-rust",style=dashed,color=red];
N9[label="clap-test",style=dashed,color=blue];
N10[label="aho-corasick",color=blue,style=dashed];
N11[label="memchr",color=blue,style=dashed];
N12[label="regex",color=blue,style=dashed];
@ -33,14 +32,12 @@ digraph dependencies {
N0 -> N6[label="",style=dashed];
N0 -> N7[label=""];
N0 -> N8[label="",style=dashed,color=red];
N0 -> N9[label="",style=dashed,color=blue];
N0 -> N12[label="",style=dashed,color=blue];
N3 -> N13[label="",style=dashed,color=blue];
N3 -> N14[label="",style=dashed,color=blue];
N3 -> N15[label="",style=dashed,color=blue];
N3 -> N16[label="",style=dashed,color=blue];
N3 -> N17[label="",style=dashed,color=blue];
N9 -> N0[label="",style=dashed,color=blue];
N9 -> N12[label="",style=dashed,color=blue];
N10 -> N11[label="",style=dashed,color=blue];
N11 -> N4[label="",style=dashed,color=blue];
N12 -> N10[label="",style=dashed,color=blue];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 98 KiB

View file

@ -1,5 +1,7 @@
extern crate clap_test;
extern crate clap;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, Arg, ErrorKind, ArgGroup};
@ -77,10 +79,10 @@ fn group_conflict_2() {
#[test]
fn conflict_output() {
clap_test::check_err_output(clap_test::complex_app(), "clap-test val1 --flag --long-option-2 val2 -F", CONFLICT_ERR, true);
test::check_err_output(test::complex_app(), "clap-test val1 --flag --long-option-2 val2 -F", CONFLICT_ERR, true);
}
#[test]
fn conflict_output_rev() {
clap_test::check_err_output(clap_test::complex_app(), "clap-test val1 -F --long-option-2 val2 --flag", CONFLICT_ERR_REV, true);
test::check_err_output(test::complex_app(), "clap-test val1 -F --long-option-2 val2 --flag", CONFLICT_ERR_REV, true);
}

View file

@ -1,5 +1,7 @@
extern crate clap;
extern crate clap_test;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, Arg, ArgGroup, ErrorKind};
@ -100,7 +102,7 @@ fn req_group_usage_string() {
.args(&["base", "delete"])
.required(true));
clap_test::check_err_output(app, "clap-test",
test::check_err_output(app, "clap-test",
"error: The following required arguments were not provided:
<base|--delete>
@ -120,7 +122,7 @@ fn req_group_with_conflict_usage_string() {
.args(&["base", "delete"])
.required(true));
clap_test::check_err_output(app, "clap-test --delete base",
test::check_err_output(app, "clap-test --delete base",
"error: The argument '--delete' cannot be used with 'base'
USAGE:
@ -139,7 +141,7 @@ fn req_group_with_conflict_rev_usage_string() {
.args(&["base", "delete"])
.required(true));
clap_test::check_err_output(app, "clap-test --delete base",
test::check_err_output(app, "clap-test --delete base",
"error: The argument '--delete' cannot be used with 'base'
USAGE:

View file

@ -1,5 +1,7 @@
extern crate clap_test;
extern crate clap;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, SubCommand, ErrorKind};
@ -105,7 +107,7 @@ fn help_subcommand() {
#[test]
fn subcommand_short_help() {
let m = clap_test::complex_app()
let m = test::complex_app()
.get_matches_from_safe(vec!["clap-test", "subcmd", "-h"]);
assert!(m.is_err());
@ -114,7 +116,7 @@ fn subcommand_short_help() {
#[test]
fn subcommand_long_help() {
let m = clap_test::complex_app()
let m = test::complex_app()
.get_matches_from_safe(vec!["clap-test", "subcmd", "--help"]);
assert!(m.is_err());
@ -123,7 +125,7 @@ fn subcommand_long_help() {
#[test]
fn subcommand_help_rev() {
let m = clap_test::complex_app()
let m = test::complex_app()
.get_matches_from_safe(vec!["clap-test", "help", "subcmd"]);
assert!(m.is_err());
@ -132,12 +134,12 @@ fn subcommand_help_rev() {
#[test]
fn complex_help_output() {
clap_test::check_help(clap_test::complex_app(), HELP);
test::check_help(test::complex_app(), HELP);
}
#[test]
fn complex_subcommand_help_output() {
let mut a = clap_test::complex_app();
let mut a = test::complex_app();
let _ = a.get_matches_from_safe_borrow(vec![""]);
let sc = a.p.subcommands.iter().filter(|s| s.p.meta.name == "subcmd").next().unwrap();
// Now we check the output of print_help()

View file

@ -1,5 +1,7 @@
extern crate clap_test;
extern crate clap;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, Arg};
@ -172,7 +174,7 @@ fn default_values_user_value() {
#[test]
fn did_you_mean() {
clap_test::check_err_output(clap_test::complex_app(), "clap-test --optio=foo",
test::check_err_output(test::complex_app(), "clap-test --optio=foo",
"error: Found argument '--optio' which wasn't expected, or isn't valid in this context
\tDid you mean --option ?

View file

@ -1,5 +1,7 @@
extern crate clap_test;
extern crate clap;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, Arg, ErrorKind};
@ -147,5 +149,5 @@ fn possible_values_of_option_multiple_fail() {
#[test]
fn possible_values_output() {
clap_test::check_err_output(clap_test::complex_app(), "clap-test -O slo", PV_ERROR, true);
test::check_err_output(test::complex_app(), "clap-test -O slo", PV_ERROR, true);
}

View file

@ -1,5 +1,7 @@
extern crate clap;
extern crate clap_test;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, Arg, ErrorKind, ArgGroup};
@ -299,7 +301,7 @@ fn required_unless_one_err() {
#[test]
fn missing_required_output() {
clap_test::check_err_output(clap_test::complex_app(), "clap-test -F",
test::check_err_output(test::complex_app(), "clap-test -F",
"error: The following required arguments were not provided:
<positional2>
--long-option-2 <option2>

View file

@ -1,5 +1,7 @@
extern crate clap_test;
extern crate clap;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, Arg, SubCommand};
@ -62,7 +64,7 @@ fn subcommand_multiple() {
#[test]
fn subcmd_did_you_mean_output() {
clap_test::check_err_output(clap_test::complex_app(), "clap-test subcm",
test::check_err_output(test::complex_app(), "clap-test subcm",
"error: The subcommand 'subcm' wasn't recognized
\tDid you mean 'subcmd' ?

View file

@ -1,6 +1,8 @@
extern crate clap_test;
#[macro_use]
extern crate clap;
extern crate regex;
include!("../clap-test.rs");
use clap::{App, Arg};
@ -176,7 +178,7 @@ fn add_multiple_arg() {
}
#[test]
fn flag_x2_opt() {
clap_test::check_complex_output("clap-test value -f -f -o some",
test::check_complex_output("clap-test value -f -f -o some",
"flag present 2 times
option present 1 times with value: some
An option: some
@ -195,135 +197,135 @@ subcmd NOT present
#[test]
fn long_opt_x2_pos() {
clap_test::check_complex_output("clap-test value --option some --option other", O2P);
test::check_complex_output("clap-test value --option some --option other", O2P);
}
#[test]
fn long_opt_eq_x2_pos() {
clap_test::check_complex_output("clap-test value --option=some --option=other", O2P);
test::check_complex_output("clap-test value --option=some --option=other", O2P);
}
#[test]
fn short_opt_x2_pos() {
clap_test::check_complex_output("clap-test value -o some -o other", O2P);
test::check_complex_output("clap-test value -o some -o other", O2P);
}
#[test]
fn short_opt_eq_x2_pos() {
clap_test::check_complex_output("clap-test value -o=some -o=other", O2P);
test::check_complex_output("clap-test value -o=some -o=other", O2P);
}
#[test]
fn short_flag_x2_comb_short_opt_pos() {
clap_test::check_complex_output("clap-test value -ff -o some", F2OP);
test::check_complex_output("clap-test value -ff -o some", F2OP);
}
#[test]
fn short_flag_short_opt_pos() {
clap_test::check_complex_output("clap-test value -f -o some", FOP);
test::check_complex_output("clap-test value -f -o some", FOP);
}
#[test]
fn long_flag_long_opt_pos() {
clap_test::check_complex_output("clap-test value --flag --option some", FOP);
test::check_complex_output("clap-test value --flag --option some", FOP);
}
#[test]
fn long_flag_long_opt_eq_pos() {
clap_test::check_complex_output("clap-test value --flag --option=some", FOP);
test::check_complex_output("clap-test value --flag --option=some", FOP);
}
#[test]
fn sc_long_flag_long_opt() {
clap_test::check_complex_output("clap-test subcmd value --flag --option some", SCFOP);
test::check_complex_output("clap-test subcmd value --flag --option some", SCFOP);
}
#[test]
fn sc_long_flag_short_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value --flag -o some", SCFOP);
test::check_complex_output("clap-test subcmd value --flag -o some", SCFOP);
}
#[test]
fn sc_long_flag_long_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value --flag --option=some", SCFOP);
test::check_complex_output("clap-test subcmd value --flag --option=some", SCFOP);
}
#[test]
fn sc_short_flag_long_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value -f --option some", SCFOP);
test::check_complex_output("clap-test subcmd value -f --option some", SCFOP);
}
#[test]
fn sc_short_flag_short_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value -f -o some", SCFOP);
test::check_complex_output("clap-test subcmd value -f -o some", SCFOP);
}
#[test]
fn sc_short_flag_short_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value -f -o=some", SCFOP);
test::check_complex_output("clap-test subcmd value -f -o=some", SCFOP);
}
#[test]
fn sc_short_flag_long_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value -f --option=some", SCFOP);
test::check_complex_output("clap-test subcmd value -f --option=some", SCFOP);
}
#[test]
fn sc_short_flag_x2_comb_long_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value -ff --option some", SCF2OP);
test::check_complex_output("clap-test subcmd value -ff --option some", SCF2OP);
}
#[test]
fn sc_short_flag_x2_comb_short_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value -ff -o some", SCF2OP);
test::check_complex_output("clap-test subcmd value -ff -o some", SCF2OP);
}
#[test]
fn sc_short_flag_x2_comb_long_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value -ff --option=some", SCF2OP);
test::check_complex_output("clap-test subcmd value -ff --option=some", SCF2OP);
}
#[test]
fn sc_short_flag_x2_comb_short_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value -ff -o=some", SCF2OP);
test::check_complex_output("clap-test subcmd value -ff -o=some", SCF2OP);
}
#[test]
fn sc_long_flag_x2_long_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value --flag --flag --option some", SCF2OP);
test::check_complex_output("clap-test subcmd value --flag --flag --option some", SCF2OP);
}
#[test]
fn sc_long_flag_x2_short_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value --flag --flag -o some", SCF2OP);
test::check_complex_output("clap-test subcmd value --flag --flag -o some", SCF2OP);
}
#[test]
fn sc_long_flag_x2_short_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value --flag --flag -o=some", SCF2OP);
test::check_complex_output("clap-test subcmd value --flag --flag -o=some", SCF2OP);
}
#[test]
fn sc_long_flag_x2_long_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value --flag --flag --option=some", SCF2OP);
test::check_complex_output("clap-test subcmd value --flag --flag --option=some", SCF2OP);
}
#[test]
fn sc_short_flag_x2_long_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value -f -f --option some", SCF2OP);
test::check_complex_output("clap-test subcmd value -f -f --option some", SCF2OP);
}
#[test]
fn sc_short_flag_x2_short_opt_pos() {
clap_test::check_complex_output("clap-test subcmd value -f -f -o some", SCF2OP);
test::check_complex_output("clap-test subcmd value -f -f -o some", SCF2OP);
}
#[test]
fn sc_short_flag_x2_short_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value -f -f -o=some", SCF2OP);
test::check_complex_output("clap-test subcmd value -f -f -o=some", SCF2OP);
}
#[test]
fn sc_short_flag_x2_long_opt_eq_pos() {
clap_test::check_complex_output("clap-test subcmd value -f -f --option=some", SCF2OP);
test::check_complex_output("clap-test subcmd value -f -f --option=some", SCF2OP);
}