-
Notifications
You must be signed in to change notification settings - Fork 21
Conversation
RE Your API.
RE Conflicts I'm torn. We're at a cross roads of a major refactor of the code / API (#74 or #75) and it'd be nice to avoid conflicts with those PRs because they were big. On the other hand, I don't want to discourage contributions or completely hold up assert_cli while we figure out what is going on. |
RE Conflicts: |
Then github's search failed me. Could you provide a link?
https://github.com/killercup/assert_cli/pull/85/files#diff-b8e1279b7e534c886db53e49d60c14a5R495 In that, one specified (sigh the refactor really cleans up this code) |
ohh, I was just following the "pattern" that has there in the 1st place, contains is fuzzy as it isn't as specific (can match with many different output's as long as they contain the input string) as is, which is analogous to my match and matches_ntimes is more like is, at least that was the interpretation i got from that. Can you point me which branch is the most "recent", by that I mean the one you want this feature implemented in, maybe I can make a PR for that branch instead and rework my code around it. Also what do you thing about not taking the regex::Regex param an take it as a String and avoid making the calling code have to instantiate the regex itself. |
Sorry for the delay; I got caught up in other projects
#74 has both a refactor and API change. I'm thinking of splitting these up so its easier to get changes in while we worry about the API. I could probably have that done by end of day tomorrow. Would you want to adjust your work to be on top of that?
That can be handy., On the other hand, I was playing with the idea of having the I had this idea before I looked at the docs. I assumed the regex crate had something like python's, with distinct Thoughts? |
Yes, that way we can get these features in for current users and only introduce the braking API changes later. Regarding your last point, I think different functions is the best option as they document intent and will also use strings as params to allow for simple refactoring. Looking forward to implement against the new code base :) |
Feel free to provide feedback on #87 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI We'd prefer it for commit histories to be cleaned up before we merge them. Don't worry about it now but once this is fully ready and review comments are done, we'd appreciate it if you could clean them up.
Keep in mind that github doesn't always send notifications for forced pushes, so you'll need to let us know when its pushed so we can go in and merge.
fn verify(&self, got: &[u8]) -> Result<()> { | ||
let conversion = String::from_utf8_lossy(got); | ||
let got = conversion.as_ref(); | ||
if self.times == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on using a sentinel value (0
) compared to using Option
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good suggestion, It's just some bad habit's take a while to leave :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ask not to point out bad habits because sometimes the line is blurry. In another project, I have one behavior when a Vec
is empty and another when it has items. I'm not using an Option
for it because it doesn't feel like it'd jive quite right with the API.
@@ -386,6 +463,16 @@ mod errors { | |||
description("Output predicate failed") | |||
display("{}\noutput=```{}```", msg, got) | |||
} | |||
/* Adding a single error more makes this break, using the bottom one temporarily |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what way does this break?
Granted, at some point we should probably move beyond error-chain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of stack space, this is a known bug in error-chain. I'm gonna look up some docs for this problem.
/// .stdout().matches("[0-9]{2}") | ||
/// .unwrap(); | ||
/// ``` | ||
pub fn matches(mut self, output: String) -> Assert { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should we accept a regex?
- Should we accept a byte slice and a byte regex?
If we decide on yes, it doesn't mean you have to do them (I don't want to bar for contributions to be perfection) but we need to at least create issues for them and keep them in mind with the design of the API / implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yes, at least a regex, a byte regex not so much IMHO, however, I see no problem in setting us up for later by implementing an abstraction layer here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, here the current usage code is more like .matches(String::from("[0-9]")
as such, i will probably use str instead of string (just borrow).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For str vs String, you can always make it accept both
/// .stdout().matches_ntimes("[0-9]{1}", 2) | ||
/// .unwrap(); | ||
/// ``` | ||
pub fn matches_ntimes(output: String, nmatches: u32) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(longer term brain storming, feel free to ignore me)
Ideally, in the long run I'd like to do this through a more builder-like approach .matches("pattern").times(10)
. contains
could also implement this. It'd provide a nice way to keep the upfront API "small". We're already talking about doing this for other features.
The interesting challenge is deciding how to implement that.
The nasty "unsafe" option is for Output
to have a .times()
function. I say "unsafe" because the call is meaningless in some cases (like .is
).
Another option is to move away from having people interact with Output
and instead have people construct the predicates directly and we'll do an Into<ContentPredicate>
. This will end up more like killercup's proposed API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something that can be very useful but out of the scope of this PR, for now, match_ntimes(V, N)
is a good enough solution, we might as well open an improvement for later to refactor and abstract into times(N)
.
FYI with #98 we are switching to generic predicates. In assert-rs/predicates-rs#18 I'm adding regex to the generic predicates. It doesn't contain repetitions but I have noted that in assert-rs/predicates-rs#12 . |
Addressed in https://github.com/assert-rs/assert_cmd |
Looking for feedback on this PR, Fixes #81
Added functionality to test against regex::Regex.
Also leaves room to implement predicate matching.
Added two new functions to the API
pub fn matches(mut self, output: regex::Regex) -> Assert
pub fn matches_ntimes(mut self, output: regex::Regex, nmatches: u32) -> Assert
You can see an example of the API in use in my own crate's branch: https://github.com/Mike-Neto/img_diff/tree/assert-cli-regex
Test's are not verified as i'm on Windows and 7 test's are failing from master (only those 7 keep failing).
Clippy and Rustfmt are not run yet as I'm just looking for feedback on the implementation itself.
cargo test
succeedscargo +nightly clippy
succeedscargo +nightly fmt
succeeds