-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Improve readability of assertion failure messages #838
Conversation
@thomhurst : I don't understand why the pipeline fails. |
It looks like one of the assertions has broken. If you go to the pipeline output, then scroll above the table you can expand each step to see it's full output. I'm seeing this:
|
TUnit.Assertions/AssertConditions/Connectors/OrAssertCondition.cs
Outdated
Show resolved
Hide resolved
Message = message; | ||
} | ||
|
||
public static AssertionResult FailIf(Func<bool> isFailed, string message) |
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.
Does this need to take a func? Looks like it invokes it immediately. Couldn't you just pass in the boolean result directly?
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 could probably get rid of it here, but not in the OrFailIf
method, as it would then throw, e.g. in
=> AssertionResult
.FailIf(
() => actualValue is null,
$"{ActualExpression ?? typeof(TActual).Name} is null")
.OrFailIf(
() => actualValue.Contains(inner, equalityComparer),
"it was found in the collection");
because both conditions are always evaluated and not just when all previous conditions didn't fail.
However having different method signatures for FailIf
and OrFailIf
looks strange to me...
|
||
return $"{value[..maxLength]}..."; | ||
|
||
return $"{value[..maxLength]}..."; |
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.
Any reason for the tab increase?
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.
No, it seems I got somehow tabs mixed within. Will have a general look at my files to use consistently spaces, as in the other files...
Thanks @vbreuss ! |
Fixes #764 as also discussed in this comment by
GetFailureMessage
withGetExpectation
which returns only the expectation from theBaseAssertCondition
Passes
method withGetResult
which returns not only a boolean value, but anAssertionResult
which also contains the failure message.This allows the assertion message to be combined to read like an english sentence, e.g.
instead of
it would read
Also added some tests for correctly throwing exceptions (see #294) where the new output reads e.g.