Skip to content

Conversation

@dennisdoomen
Copy link
Member

@dennisdoomen dennisdoomen commented Mar 13, 2025

In a test like When_one_of_the_types_does_not_match_the_generic_type_it_should_throw_with_a_clear_explanation, a multi-line exception message like this

Expected exception message to match the equivalent of "Expected type to be "System.Int33" because they are of different type, but found "[System.Int32, System.String, System.Int32]".", but "Expected type to be "System.Int32" because they are of different type, but found "[System.Int32, System.String, System.Int32]"." does not.

after this PR, they will be rendered as

Expected exception message to match the equivalent of

    "Expected type to be "System.Int33" because they are of different type, but found "[System.Int32, System.String, System.Int32]".",

but

    "Expected type to be "System.Int32" because they are of different type, but found "[System.Int32, System.String, System.Int32]"."

does not.

@github-actions
Copy link

github-actions bot commented Mar 13, 2025

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@dennisdoomen dennisdoomen force-pushed the improve-exception-messages branch 8 times, most recently from a06ba55 to 9a6ee29 Compare March 20, 2025 19:54
@dennisdoomen dennisdoomen force-pushed the improve-exception-messages branch 3 times, most recently from 187131b to e02714b Compare March 25, 2025 23:52
@dennisdoomen dennisdoomen marked this pull request as ready for review March 25, 2025 23:53
@dennisdoomen dennisdoomen added this to the 8.3.0 milestone Mar 25, 2025
@coveralls
Copy link

coveralls commented Mar 26, 2025

Pull Request Test Coverage Report for Build 14133594137

Details

  • 68 of 71 (95.77%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 97.358%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/Primitives/StringContainsStrategy.cs 1 4 25.0%
Totals Coverage Status
Change from base Build 14090391235: -0.03%
Covered Lines: 12442
Relevant Lines: 12637

💛 - Coveralls

@dennisdoomen dennisdoomen requested review from Copilot and jnyrup March 26, 2025 16:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the rendering of exception messages by reformatting multi-line messages and refactoring string comparison and validation methods. Key changes include updating tests to assert multi‐line formatting, renaming and consolidating validation methods across multiple string comparison strategies, and adjusting the trimming behavior in the formatting component.

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Tests/FluentAssertions.Specs/Exceptions/OuterExceptionSpecs.cs Added tests to verify multi‐line, long, and short exception message rendering.
Src/FluentAssertions/Specialized/ExceptionAssertions.cs Refactored exception message assertion logic for clearer output.
Src/FluentAssertions/Primitives/StringWildcardMatchingStrategy.cs Renamed methods and updated formatting for multi‐line messages.
Src/FluentAssertions/Primitives/StringValidatorSupportingNull.cs Updated to call the new AssertForEquality method.
Src/FluentAssertions/Primitives/StringValidator.cs Replaced null validation with a call to AssertNeitherIsNull for better consistency.
Src/FluentAssertions/Primitives/StringStartStrategy.cs Renamed mismatch validation method and added null checks.
Src/FluentAssertions/Primitives/StringEqualityStrategy.cs Renamed methods and updated error message formatting.
Src/FluentAssertions/Primitives/StringEndStrategy.cs Modified error messages and integrated a new null check method.
Src/FluentAssertions/Primitives/StringContainsStrategy.cs Renamed methods and updated error message parameter ordering.
Src/FluentAssertions/Primitives/IStringComparisonStrategy.cs Updated the interface to match the new method names.
Src/FluentAssertions/Formatting/Line.cs Adjusted trimming behavior in ToString to explicitly remove trailing spaces.
Files not reviewed (1)
  • Tests/FluentAssertions.Specs/FluentAssertions.Specs.csproj: Language not supported
Comments suppressed due to low confidence (1)

Src/FluentAssertions/Primitives/StringContainsStrategy.cs:25

  • [nitpick] Verify that the parameter order in the error message is intentional; currently, 'subject' is passed as the first parameter and 'expected' as the second, which might lead to confusion compared to similar strategies.
                $"Expected {context:string} {0} to contain the equivalent of {1} {expectedOccurrence}{reason}, but found it {actual.Times()}."

@dennisdoomen dennisdoomen force-pushed the improve-exception-messages branch from e02714b to 14ae9cc Compare March 28, 2025 16:34
@dennisdoomen
Copy link
Member Author

@jnyrup did you not approve or reject the PR on purpose?

@dennisdoomen dennisdoomen merged commit 34e1a87 into fluentassertions:main Mar 28, 2025
8 checks passed
@dennisdoomen dennisdoomen deleted the improve-exception-messages branch March 28, 2025 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants