mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 00:27:13 +00:00
Adding tests
This commit is contained in:
parent
eedfdcdac9
commit
0cce6b8715
5 changed files with 90 additions and 11 deletions
|
@ -5,5 +5,5 @@ version = "0.0.1"
|
|||
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
||||
|
||||
[dependencies.clap]
|
||||
git = "file:/home/kevin/Projects/clap-rs"
|
||||
branch = "extrabox"
|
||||
git = "$FORK"
|
||||
branch = "$BRANCH"
|
||||
|
|
29
claptests/Makefile
Normal file
29
claptests/Makefile
Normal file
|
@ -0,0 +1,29 @@
|
|||
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
|
||||
|
||||
build:
|
||||
cargo update
|
||||
cargo build --release
|
||||
|
||||
test:
|
||||
cd "$(THIS_DIR)"
|
||||
cp Cargo.toml cargo.bak
|
||||
read -p "fork url: " FORK
|
||||
read -p "branch [master]: " BRANCH
|
||||
sed -e "s/\$FORK/$FORK" cargo.bak > Cargo.toml
|
||||
if [ "$BRANCH" == "" ]; then
|
||||
sed -i "s/\$BRANCH/master/" Cargo.toml
|
||||
else
|
||||
sed -i "s/\$BRNACH/$BRANCH/" Cargo.toml
|
||||
fi
|
||||
(make clean) || (make clean && false)
|
||||
(make build) || (make clean && false)
|
||||
./run_tests.py || (make clean && false)
|
||||
echo "All tests pass!"
|
||||
mv cargo.bak Cargo.toml
|
||||
make clean
|
||||
|
||||
|
||||
clean:
|
||||
cd "$(THIS_DIR)"
|
||||
cargo clean
|
21
claptests/good_help
Normal file
21
claptests/good_help
Normal file
|
@ -0,0 +1,21 @@
|
|||
claptests 0.0.1
|
||||
Kevin K. <kbknapp@gmail.com>
|
||||
tests clap library
|
||||
|
||||
USAGE:
|
||||
claptests [FLAGS] [OPTIONS] [POSITIONAL] [SUBCOMMANDS]
|
||||
|
||||
FLAGS:
|
||||
-f,--flag tests flags
|
||||
-v,--version Prints version information
|
||||
-h,--help Prints this message
|
||||
|
||||
OPTIONS:
|
||||
-o ,--option=option tests options
|
||||
|
||||
POSITIONAL ARGUMENTS:
|
||||
positional tests positionals
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Prints this message
|
||||
subcmd tests subcommands
|
38
claptests/run_test.py
Executable file
38
claptests/run_test.py
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
failed = False
|
||||
|
||||
def pass_fail(good, check):
|
||||
print(good)
|
||||
if check == good:
|
||||
return "Pass"
|
||||
failed = True
|
||||
return "Fail"
|
||||
|
||||
def main():
|
||||
cmd_help = [['./target/release/claptests', '-h'],
|
||||
['./target/release/claptests', '--help'],
|
||||
['./target/release/claptests', 'help']]
|
||||
proc = subprocess.Popen(cmd_help[0], stdout=subprocess.PIPE)
|
||||
proc.wait()
|
||||
out = proc.communicate()[0].decode('utf-8')
|
||||
print("Help Flag:")
|
||||
print("\tshort: {}".format(pass_fail(GOOD_HELP_HASH, out)))
|
||||
proc = subprocess.Popen(cmd_help[1], stdout=subprocess.PIPE)
|
||||
proc.wait()
|
||||
out = proc.communicate()[0].decode('utf-8')
|
||||
print("\tlong: {}".format(pass_fail(GOOD_HELP_HASH, out)))
|
||||
proc = subprocess.Popen(cmd_help[2], stdout=subprocess.PIPE)
|
||||
proc.wait()
|
||||
out = proc.communicate()[0].decode('utf-8')
|
||||
print("\tlong: {}".format(pass_fail(GOOD_HELP_HASH, out)))
|
||||
|
||||
if failed:
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
|
@ -481,15 +481,6 @@ impl<'a, 'v, 'ab, 'u> App<'a, 'v, 'ab, 'u>{
|
|||
if !pos_only {
|
||||
if let Some(nvo) = needs_val_of {
|
||||
if let Some(ref opt) = self.opts.get(nvo) {
|
||||
// if self.blacklist.contains(opt.name) {
|
||||
// self.report_error(
|
||||
// format!("The argument {} is mutually exclusive with one or more other arguments",
|
||||
// if let Some(long) = opt.long {
|
||||
// format!("--{}",long)
|
||||
// }else{
|
||||
// format!("-{}",opt.short.unwrap())
|
||||
// }),true, true);
|
||||
// }
|
||||
if let Some(ref mut o) = matches.opts.get_mut(opt.name) {
|
||||
o.values.push(arg.clone());
|
||||
o.occurrences = if opt.multiple { o.occurrences + 1 } else { 1 };
|
||||
|
|
Loading…
Reference in a new issue