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 (v2)
  • Loading branch information
bradwilson committed Jan 28, 2024
1 parent 5ef7b75 commit cab6a3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/xunit.assert/Asserts
10 changes: 6 additions & 4 deletions test/test.xunit.assert/Asserts/AsyncCollectionAssertsTests.cs
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 test/test.xunit.assert/Asserts/CollectionAssertsTests.cs
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

0 comments on commit cab6a3e

Please sign in to comment.