libcnb.rs
libcnb.rs copied to clipboard
Support passing `String` to `assert_contains!` not just `&str`
With assert_eq!
I can do this:
assert_eq!(
context.pack_stdout,
formatdoc! {"
FOO
"}
);
However, doing the same with assert_contains!
, I get:
error[E0277]: expected a `FnMut<(char,)>` closure, found `String`
--> tests/integration.rs:16:13
|
16 | / assert_contains!(
17 | | context.pack_stdout,
18 | | formatdoc! {"
19 | | FOO
20 | | "}
21 | | );
| |_____________^ expected an `FnMut<(char,)>` closure, found `String`
|
= help: the trait `FnMut<(char,)>` is not implemented for `String`
= help: the following other types implement trait `Pattern<'a>`:
&'b String
&'b str
&'c &'b str
= note: required because of the requirements on the impl of `Pattern<'_>` for `String`
note: required by a bound in `core::str::<impl str>::contains`
--> /Users/emorley/.rustup/toolchains/beta-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/str/mod.rs:1054:28
|
1054 | pub fn contains<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
| ^^^^^^^^^^^ required by this bound in `core::str::<impl str>::contains`
= note: this error originates in the macro `assert_contains` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
Instead I have to convert the String
to a &str
for the formatdoc!
argument to assert_contains!
:
assert_contains!(
context.pack_stdout,
&formatdoc! {"
FOO
"}
);
It would be great if assert_contains!
supported this without the need to manually convert to a reference.
xref #477