-
Notifications
You must be signed in to change notification settings - Fork 732
Some assertions are not including variable names in assertion message #1435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dennisdoomen
left a comment
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.
That's quite an impressive PR. To be fair, I would not have invested the time to support all the misuse of the language in your examples. But that's the awesomeness of the community ❤
| } | ||
|
|
||
| [Fact] | ||
| public void When_variable_is_not_captured_it_should_use_the_variable_name() |
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 don't get this scenario.
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.
It was added when I started with Mono.Cecil. That time such test was important, now it is not. I will just remove this test and maybe similar ones
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've removed this one - but I'm not sure what the similar ones that can be removed are
| } | ||
|
|
||
| [Fact] | ||
| public void When_field_is_the_caller_it_should_use_the_field_name() |
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 it's better to change the term caller into subject or something like that.
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.
Done
| } | ||
|
|
||
| [Fact] | ||
| public void When_method_name_contains_get_it_should_not_remove_the_prefix() |
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.
🤔 Why is this an expected scenario?
🙃 The name is rather difficult to read since you refer to some literal term. I would rephrase contains_get to contains_getter_prefix to keep it readable.
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.
The whole test could be removed because the current code base just rely on symbols, no need to distinguish properties and methods
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.
Done
|
|
||
| // Assert | ||
| act.Should().Throw<XunitException>() | ||
| .WithMessage("*Expected foo.GetFoo(test1).GetFooStatic(\"test\"+2).GetFoo(foo.Field) to be <null>*"); |
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 it would be better to only capture the GetFoo(fool.Field), but I guess it's going to be too hard to figure that out.
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 it is not that hard. We could look for the last dot which is not part of arguments list. The reason why I didn't do it like you suggest is that I saw the current behaviour better. Just let me know if you think it is worth doing. I can do it right here (guess it is better) or implement it as a separate PR.
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.
@dennisdoomen I would be OK with leaving this as is as long as you are - I kind of like the extra context (although if it were too long via chained method calls, it could we unwieldy - then again with EF this could end up showing .ToList() which wouldn't be helpful).
| } | ||
|
|
||
| [Fact] | ||
| public void When_method_contains_parameters_it_should_add_them_to_caller() |
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.
🔧 The proper term is arguments, not parameters.
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.
Done
| Result Handle(char symbol); | ||
| } | ||
|
|
||
| private class QuotesHandler : IHandler |
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 it might be a good idea to move the CallerIdentifier and all this new code into a folder CallerIdentification. Especially because we also prefer to have separate files per class over private classes.
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.
Done
| } | ||
|
|
||
| var sb = new CallerStatementBuilder(); | ||
| CallerStatementBuilder.Result state; |
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.
🔧 If your enum needs to be prefixed by another class, treating it as a nested type is not a good idea.
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.
Done
|
|
||
| public override string ToString() => statement.ToString(); | ||
|
|
||
| public enum Result |
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 don't understand the different values. E.g. what's the difference between Done and Handled? Maybe adding some XML comments will help.
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.
Yes, I remember that I was not happy by this thing. The answer is in this method:
public Result Append(string symbols)
{
Result result = Result.InProgress;
using var symbolEnumerator = symbols.GetEnumerator();
while (symbolEnumerator.MoveNext() && result != Result.Done)
{
result = Result.InProgress;
using var handlerEnumerator = handlers.GetEnumerator();
while (handlerEnumerator.MoveNext() && result == Result.InProgress)
{
result = handlerEnumerator.Current.Handle(symbolEnumerator.Current);
}
}
return result;
}I have 2 cycles and 2 flags for exit. I will try to refactor it somehow, anyway I need to move some things as suggested above.
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.
@Serg046 Did you have any thoughts/suggestions you could share on this? I don't mind making the changes, there's just a lot going on 😛
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.
@mdentremont, the only suggestion is to refactor it somehow. I just remember that processing was line by line where Handled means that the line is processed and we need to switch next.
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.
Ah no worries. I don't think it's all that bad as it stands - it takes a second to wrap your head around, but then it's decently straightforward.
If you have any refactoring ideas you'd like to apply, maybe just make them in a future PR 👍
| return isQuoteContext ? Result.Handled : Result.InProgress; | ||
| } | ||
|
|
||
| private bool IsAtEscaped() |
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.
🔧 As mentioned before, I would rename this to IsVerbatim
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.
Done
| if (statement.Length > 1) | ||
| { | ||
| var idx = statement.Length - 1; | ||
| return statement[idx--] == '$' |
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.
❌ Please don't mix increments like these. People always forget in what order things happen.
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.
Done
|
@Serg046 did you give up on this? |
|
I am just waiting for the holidays. If you still think we could merge something like this, I will complete it soon. |
|
@jnyrup what do you think? |
|
I think it looks quite interesting. I just haven't taken the time to digest this fully. I was mostly concerned about other PRs keeping caller identification lazy. |
|
Is there still interest in this PR? I would love to see #1353 fixed! |
If somebody is willing to finalize the PR, then yes. |
- Remove unneeded test - Fix wording & variable names
Merge develop & address most PR feedback for issue fluentassertions#1353
dennisdoomen
left a comment
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.
👍🏻 Impressive piece of work
❌ Please make everything related to caller identification internal.
| return isQuoteContext ? HandlerResult.Handled : HandlerResult.InProgress; | ||
| } | ||
|
|
||
| private bool IsVerbatim() |
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.
@$"" is also a valid interpolated verbatim string.
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 that's what it is doing?
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.
Ahh sorry, I meant that $@"" is also a valid interpolated verbatim string.
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.
ahh OK - I'll try to get this resolved today hopefully.
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.
Done
docs/_pages/releases.md
Outdated
| * Better parameter checking of `MethodInfoSelectorAssertions` - [#1569](https://github.com/fluentassertions/fluentassertions/pull/1569) | ||
| * Better parameter checking of `XDocumentAssertions`, `XElementAssertions` and `XAttributeAssertions` - [#1564](https://github.com/fluentassertions/fluentassertions/pull/1564) | ||
| * In a chained assertion API call, a second call to `ForCondition` should not even evaluate its lambda when the previous assertion failed - [#1587](https://github.com/fluentassertions/fluentassertions/pull/1587) | ||
| * Improved caller name determination by supporting multiple lines, comments and semicolons - [#1435](https://github.com/fluentassertions/fluentassertions/pull/1435). |
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.
Beta 1 has shipped, this will be part of 6.0.0 xxx
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.
Done
Done |
- Add docs - IHandler => IParsingStrategy - Pass StringBuilder/statement in Parse method rather than handing it to strategy constructors (easier to follow) - Handled => GoToNextSymbol - strategies => priorityOrderedParsingStrategies to make it more clear that the order is important
- Having "WithMessage("*..*")" was causing failing tests to pass (this
seems odd, maybe WithMessage isn't working correctly?)
- note: a trailing whitespace character was auto-trimmed by my IDE, I left the change because it felt dirty :P
|
@dennisdoomen @jnyrup Thanks so much for the feedback you two! While addressing the feedback, I noticed that the tests that did I also noticed some edge cases while reading through the code, so I added new tests to confirm my suspicions (the tests failed). I've made a decent amount of refactoring, and have also fixed all of the broken tests (and of course addressed as much of the review feedback as I could, and replied where I couldn't). Cheers! |
- This is why we added NotifyEndOfLineReached()
- Use guard clauses & extract naming variables
Address more review feedback
dennisdoomen
left a comment
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.
Some unit tests are failing...
- I'm somewhat grasping for straws on this one, my IDE wants to suppress using ReSharper commments, and won't offer to suppress in this manner
Issue 1353 (hopefully the last set of changes)
| internal class ShouldCallParsingStrategy : IParsingStrategy | ||
| { | ||
| private const string ShouldCall = ".Should()"; | ||
| private const string ShouldCall = ".Should("; |
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.
Is there any disadvantage to using .Should( over .Should()?
I imagine Should is only called with an argument in our tests when we fake timing.
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.
It think it seems reasonable. This way it also still works if somebody were to overload .Should via an extension method (not sure why they would though).
IMPORTANT
AcceptApiChanges.ps1/AcceptApiChanges.sh.Fixes #1353