aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/tests
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-01-07 15:15:38 +0000
committerDaniel Mueller <deso@posteo.net>2020-01-08 09:21:09 -0800
commit8482335491aa55b0458ffedccd1fc110f092e38a (patch)
treec6d0605ad875eb7ff8bce76b5609df988a419d44 /nitrocli/src/tests
parent70199fb8c1cff9323c7b60a037f3c6193bb32e29 (diff)
downloadnitrocli-8482335491aa55b0458ffedccd1fc110f092e38a.tar.gz
nitrocli-8482335491aa55b0458ffedccd1fc110f092e38a.tar.bz2
Replace argparse with structopt
This patch changes the argument handling code to use structopt instead of argparse using the data structures we introduced in the last patch. As part of that transition we replace the old Error::ArgparseError variant with ClapError that stores a structopt::clap::Error. Because of that replacement, the format of the help messages changed, breaking some of the tests. Hence, this change adapts them accordingly. Also clap currently prints the version output to stdout, so we ignore the version_option test case for now.
Diffstat (limited to 'nitrocli/src/tests')
-rw-r--r--nitrocli/src/tests/config.rs7
-rw-r--r--nitrocli/src/tests/mod.rs7
-rw-r--r--nitrocli/src/tests/run.rs13
3 files changed, 21 insertions, 6 deletions
diff --git a/nitrocli/src/tests/config.rs b/nitrocli/src/tests/config.rs
index ea3a0e8..9ff3f73 100644
--- a/nitrocli/src/tests/config.rs
+++ b/nitrocli/src/tests/config.rs
@@ -39,9 +39,10 @@ $"#,
#[test_device]
fn set_wrong_usage(model: nitrokey::Model) {
let res = Nitrocli::with_model(model).handle(&["config", "set", "--numlock", "2", "-N"]);
- assert_eq!(
- res.unwrap_str_err(),
- "--numlock and --no-numlock are mutually exclusive"
+ let err = res.unwrap_str_err();
+ assert!(
+ err.contains("The argument '--numlock <numlock>' cannot be used with '--no-numlock'"),
+ err,
);
}
diff --git a/nitrocli/src/tests/mod.rs b/nitrocli/src/tests/mod.rs
index 5ebf285..ac420f2 100644
--- a/nitrocli/src/tests/mod.rs
+++ b/nitrocli/src/tests/mod.rs
@@ -50,6 +50,13 @@ where
{
fn unwrap_str_err(self) -> String {
match self.unwrap_err() {
+ crate::Error::ClapError(err) => {
+ if err.use_stderr() {
+ err.message
+ } else {
+ String::new()
+ }
+ }
crate::Error::Error(err) => err,
err => panic!("Unexpected error variant found: {:?}", err),
}
diff --git a/nitrocli/src/tests/run.rs b/nitrocli/src/tests/run.rs
index c59c660..767be47 100644
--- a/nitrocli/src/tests/run.rs
+++ b/nitrocli/src/tests/run.rs
@@ -27,7 +27,8 @@ fn no_command_or_option() {
assert_eq!(out, b"");
let s = String::from_utf8_lossy(&err).into_owned();
- assert!(s.starts_with("Usage:\n"), s);
+ assert!(s.starts_with("nitrocli"), s);
+ assert!(s.contains("USAGE:\n"), s);
}
#[test]
@@ -42,8 +43,10 @@ fn help_options() {
assert_eq!(err, b"");
let s = String::from_utf8_lossy(&out).into_owned();
- let expected = format!("Usage:\n nitrocli {}", args.join(" "));
- assert!(s.starts_with(&expected), s);
+ let mut args = args.to_vec();
+ args.insert(0, "nitrocli");
+ assert!(s.starts_with(&args.join("-")), s);
+ assert!(s.contains("USAGE:\n"), s);
}
fn test(args: &[&str]) {
@@ -84,7 +87,11 @@ fn help_options() {
}
#[test]
+#[ignore]
fn version_option() {
+ // clap sends the version output directly to stdout: https://github.com/clap-rs/clap/issues/1390
+ // Therefore we ignore this test for the time being.
+
fn test(re: &regex::Regex, opt: &'static str) {
let (rc, out, err) = Nitrocli::new().run(&[opt]);