You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of the string predicates accept an argument that can vary at runtime (usually as Into<String>) but str::diff asks instead for an argument that is Into<Cow<'static, str>>, which is not satisfied by strings created at runtime. This means I can't do something like
use std::str;use assert_cmd::Command;use predicates::prelude::*;fnmy_program() -> Command{Command::cargo_bin("my_program").unwrap()}#[test]fnhelp_options(){let help_output =
my_program().arg("--help").assert().success().stderr("").get_output().to_owned();my_program().arg("-h").assert().success().stderr("").stdout(predicate::str::diff(
str::from_utf8(&help_output.stdout).unwrap()));}
I don't see why this couldn't be made to work, but with the current implementation it's a compile-time error:
error[E0277]: the trait bound `std::borrow::Cow<'static, str>: std::convert::From<std::vec::Vec<u8>>` is not satisfied
--> my_crate/tests/cli_tests.rs:26:38
|
26 | .stdout(predicate::str::diff(help_status.get_output().stdout));
| -------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<std::vec::Vec<u8>>` is not implemented for `std::borrow::Cow<'static, str>`
| |
| required by a bound introduced by this call
|
Huh, can't remember why I did that but it doesn't mean you can't pass in strings at runtime but that you must transfer ownership. A Cow can be both a borrowed and an owned string.
Most of the string predicates accept an argument that can vary at runtime (usually as
Into<String>
) butstr::diff
asks instead for an argument that isInto<Cow<'static, str>>
, which is not satisfied by strings created at runtime. This means I can't do something likeI don't see why this couldn't be made to work, but with the current implementation it's a compile-time error:
Meta
predicates-rs version: 3.0.3
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: