From c1f35ab538dbdf3002a6a9aa0932ada687160787 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 7 Jan 2020 15:15:38 +0000 Subject: 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. --- src/tests/run.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/tests/run.rs') diff --git a/src/tests/run.rs b/src/tests/run.rs index c59c660..22e7004 100644 --- a/src/tests/run.rs +++ b/src/tests/run.rs @@ -1,7 +1,7 @@ // run.rs // ************************************************************************* -// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) * +// * Copyright (C) 2019-2020 Daniel Mueller (deso@posteo.net) * // * * // * This program is free software: you can redistribute it and/or modify * // * it under the terms of the GNU General Public License as published by * @@ -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: ®ex::Regex, opt: &'static str) { let (rc, out, err) = Nitrocli::new().run(&[opt]); -- cgit v1.2.1