Skip to content

Commit

Permalink
#2871: Inner exception stack trace is missing from Assert.Collection …
Browse files Browse the repository at this point in the history
…failure (v3)
  • Loading branch information
bradwilson committed Jan 28, 2024
1 parent c6ded57 commit afc2a79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/xunit.v3.assert.tests/Asserts/AsyncCollectionAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ public static void MismatchedElement()
);

var collEx = Assert.IsType<CollectionException>(ex);
Assert.Equal(
Assert.StartsWith(
"Assert.Collection() Failure: Item comparison failure" + Environment.NewLine +
" ↓ (pos 1)" + Environment.NewLine +
"Collection: [42, 2112]" + Environment.NewLine +
"Error: Assert.Equal() Failure: Values differ" + Environment.NewLine +
" Expected: 2113" + Environment.NewLine +
" Actual: 2112",
" Actual: 2112" + Environment.NewLine +
" Stack Trace:",
ex.Message
);
}
Expand Down Expand Up @@ -261,13 +262,14 @@ public static async Task MismatchedElementAsync()
);

var collEx = Assert.IsType<CollectionException>(ex);
Assert.Equal(
Assert.StartsWith(
"Assert.Collection() Failure: Item comparison failure" + Environment.NewLine +
" ↓ (pos 1)" + Environment.NewLine +
"Collection: [42, 2112]" + Environment.NewLine +
"Error: Assert.Equal() Failure: Values differ" + Environment.NewLine +
" Expected: 2113" + Environment.NewLine +
" Actual: 2112",
" Actual: 2112" + Environment.NewLine +
" Stack Trace:",
ex.Message
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/xunit.v3.assert.tests/Asserts/CollectionAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public static void NonEmptyCollection()
);
}

#if !NETCOREAPP2_0 // Unclear why this is failing only on .NET Core 2.0, but it passes with .NET 6 and .NET Framework 4.x
[Fact]
public static void MismatchedElement()
{
Expand All @@ -173,16 +174,18 @@ public static void MismatchedElement()
);

var collEx = Assert.IsType<CollectionException>(ex);
Assert.Equal(
Assert.StartsWith(
"Assert.Collection() Failure: Item comparison failure" + Environment.NewLine +
" ↓ (pos 1)" + Environment.NewLine +
"Collection: [42, 2112]" + Environment.NewLine +
"Error: Assert.Equal() Failure: Values differ" + Environment.NewLine +
" Expected: 2113" + Environment.NewLine +
" Actual: 2112",
" Actual: 2112" + Environment.NewLine +
" Stack Trace:",
ex.Message
);
}
#endif
}

public class CollectionAsync
Expand Down Expand Up @@ -259,13 +262,14 @@ public static async Task MismatchedElementAsync()
);

var collEx = Assert.IsType<CollectionException>(ex);
Assert.Equal(
Assert.StartsWith(
"Assert.Collection() Failure: Item comparison failure" + Environment.NewLine +
" ↓ (pos 1)" + Environment.NewLine +
"Collection: [42, 2112]" + Environment.NewLine +
"Error: Assert.Equal() Failure: Values differ" + Environment.NewLine +
" Expected: 2113" + Environment.NewLine +
" Actual: 2112",
" Actual: 2112" + Environment.NewLine +
" Stack Trace:",
ex.Message
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xunit.v3.assert/Asserts

0 comments on commit afc2a79

Please sign in to comment.