Skip to content

Commit

Permalink
Use string literals for assert messages
Browse files Browse the repository at this point in the history
Fix compiler warnings for dynamic assert messages seen with rustc 1.51.
  • Loading branch information
robinkrahl authored and d-e-s-o committed Apr 17, 2021
1 parent 86737a2 commit 7b181e9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn mutually_exclusive_set_options() {
assert_eq!(out, b"");

let err = String::from_utf8(err).unwrap();
assert!(err.contains("cannot be used with"), err);
assert!(err.contains("cannot be used with"), "{}", err);
}

test("-c", "-C");
Expand All @@ -36,7 +36,7 @@ $"#,

let out = Nitrocli::new().model(model).handle(&["config", "get"])?;

assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}

Expand All @@ -50,6 +50,7 @@ fn set_wrong_usage(model: nitrokey::Model) {

assert!(
err.contains("The argument '--num-lock <num-lock>' cannot be used with '--no-num-lock'"),
"{}",
err,
);
}
Expand All @@ -70,6 +71,6 @@ $"#,
.unwrap();

let out = ncli.handle(&["config", "get"])?;
assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}
6 changes: 3 additions & 3 deletions src/tests/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ $"#,

let mut ncli = Nitrocli::new().model(model);
let out = ncli.handle(&["status"])?;
assert!(make_re(None).is_match(&out), out);
assert!(make_re(None).is_match(&out), "{}", out);

let _ = ncli.handle(&["encrypted", "open"])?;
let out = ncli.handle(&["status"])?;
assert!(make_re(Some(true)).is_match(&out), out);
assert!(make_re(Some(true)).is_match(&out), "{}", out);

let _ = ncli.handle(&["encrypted", "close"])?;
let out = ncli.handle(&["status"])?;
assert!(make_re(Some(false)).is_match(&out), out);
assert!(make_re(Some(false)).is_match(&out), "{}", out);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fn connected(model: nitrokey::Model) -> anyhow::Result<()> {
.unwrap();

let out = Nitrocli::new().model(model).handle(&["list"])?;
assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}
2 changes: 1 addition & 1 deletion src/tests/otp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn status(model: nitrokey::Model) -> anyhow::Result<()> {
let _ = ncli.handle(&["otp", "set", "0", "the-name", "123456", "-f", "hex"])?;

let out = ncli.handle(&["otp", "status"])?;
assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/pws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn status(model: nitrokey::Model) -> anyhow::Result<()> {
let _ = ncli.handle(&["pws", "set", "0", "the-name", "the-login", "123456"])?;

let out = ncli.handle(&["pws", "status"])?;
assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}

Expand Down
18 changes: 11 additions & 7 deletions src/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fn no_command_or_option() {
assert_eq!(out, b"");

let s = String::from_utf8_lossy(&err).into_owned();
assert!(s.starts_with("nitrocli"), s);
assert!(s.contains("USAGE:\n"), s);
assert!(s.starts_with("nitrocli"), "{}", s);
assert!(s.contains("USAGE:\n"), "{}", s);
}

#[test]
Expand All @@ -42,8 +42,8 @@ fn help_options() {
let s = String::from_utf8_lossy(&out).into_owned();
let mut args = args.to_vec();
args.insert(0, "nitrocli");
assert!(s.starts_with(&args.join("-")), s);
assert!(s.contains("USAGE:\n"), s);
assert!(s.starts_with(&args.join("-")), "{}", s);
assert!(s.contains("USAGE:\n"), "{}", s);
}

fn test(args: &[&str]) {
Expand Down Expand Up @@ -97,7 +97,7 @@ fn version_option() {

let s = String::from_utf8_lossy(&out).into_owned();
let _ = re;
assert!(re.is_match(&s), out);
assert!(re.is_match(&s), "{}", s);
}

let re = regex::Regex::new(r"^nitrocli \d+.\d+.\d+(-[^-]+)* using libnitrokey .*\n$").unwrap();
Expand Down Expand Up @@ -302,7 +302,11 @@ print("success")
let path = ext_dir.path().as_os_str().to_os_string();
// Make sure that the extension appears in the help text.
let out = Nitrocli::new().path(&path).handle(&["--help"])?;
assert!(out.contains("ext Run the ext extension\n"), out);
assert!(
out.contains("ext Run the ext extension\n"),
"{}",
out
);
// And, of course, that we can invoke it.
let out = Nitrocli::new().path(&path).handle(&["ext"])?;
assert_eq!(out, "success\n");
Expand Down Expand Up @@ -370,7 +374,7 @@ fn extension_arguments(model: nitrokey::Model) -> anyhow::Result<()> {
let path = ext_dir.path().as_os_str().to_os_string();
let out = Nitrocli::new().model(model).path(path).handle(&args)?;

assert!(check(&out), out);
assert!(check(&out), "{}", out);
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $"#,
.unwrap();

let out = Nitrocli::new().model(model).handle(&["status"])?;
assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}

Expand All @@ -53,7 +53,7 @@ $"#,
.unwrap();

let out = Nitrocli::new().model(model).handle(&["status"])?;
assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}

Expand All @@ -80,6 +80,6 @@ $"#,
.unwrap();

let out = Nitrocli::new().model(model).handle(&["status"])?;
assert!(re.is_match(&out), out);
assert!(re.is_match(&out), "{}", out);
Ok(())
}

0 comments on commit 7b181e9

Please sign in to comment.