From 4625be03bbebe74f5efa93a37f287e7911fbbbb4 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 17 Feb 2019 13:34:02 +0000 Subject: Add test case for --version option This change adds a test case for the -V/--version option to the suite of tests. --- nitrocli/src/tests/run.rs | 19 +++++++++++++++++++ nitrocli/src/tests/status.rs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/nitrocli/src/tests/run.rs b/nitrocli/src/tests/run.rs index 260a851..dda7473 100644 --- a/nitrocli/src/tests/run.rs +++ b/nitrocli/src/tests/run.rs @@ -45,3 +45,22 @@ fn help_option() { test("--help"); test("-h") } + +#[test] +fn version_option() { + fn test(re: ®ex::Regex, opt: &'static str) { + let (rc, out, err) = Nitrocli::new().run(&[opt]); + + assert_eq!(rc, 0); + assert_eq!(err, b""); + + let s = String::from_utf8_lossy(&out).into_owned(); + let _ = re; + assert!(re.is_match(&s), out); + } + + let re = regex::Regex::new(r"^nitrocli \d+.\d+.\d+(-[^-]+)*\n$").unwrap(); + + test(&re, "--version"); + test(&re, "-V"); +} diff --git a/nitrocli/src/tests/status.rs b/nitrocli/src/tests/status.rs index acd33dc..83ce61f 100644 --- a/nitrocli/src/tests/status.rs +++ b/nitrocli/src/tests/status.rs @@ -42,7 +42,7 @@ fn output(device: nitrokey::DeviceWrapper) -> crate::Result<()> { r#"^Status: model: (Pro|Storage) serial number: 0x[[:xdigit:]]{8} - firmware version: \d+.\d+ + firmware version: \d+\.\d+ user retry count: [0-3] admin retry count: [0-3] $"#, -- cgit v1.2.3