Skip to content

Commit

Permalink
Make combination tests support recording when an exception is thrown (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Nov 2, 2024
1 parent a4b159a commit 527eedf
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
<Version>28.1.2</Version>
<Version>28.1.3</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
1, Smith St : {
target: {
Type: Exception,
Message: boom
},
key: recorded 1 Smith St
},
1, Wallace St: {
target: {
Type: Exception,
Message: boom
},
key: recorded 1 Wallace St
},
10, Smith St : {
target: 10 Smith St,
key: recorded 10 Smith St
},
10, Wallace St: {
target: 10 Wallace St,
key: recorded 10 Wallace St
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
1, Smith St : {
target: {
Type: Exception,
Message: boom
},
key: recorded 1 Smith St
},
1, Wallace St: {
target: {
Type: Exception,
Message: boom
},
key: recorded 1 Wallace St
},
10, Smith St : {
target: 10 Smith St,
key: recorded 10 Smith St
},
10, Wallace St: {
target: 10 Wallace St,
key: recorded 10 Wallace St
}
}
43 changes: 43 additions & 0 deletions src/Verify.Tests/CombinationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,49 @@ public Task RecordingTest()
params2);
}

[Fact]
public Task RecordingWithExceptionTest()
{
Recording.Start();
return Combination(captureExceptions: true)
.Verify(
(param1, param2) =>
{
Recording.Add("key", $"recorded {param1} {param2}");
if (param1 == 1)
{
throw new("boom");
}

return $"{param1} {param2}";
},
params1,
params2)
.IgnoreStackTrace();
}

[Fact]
public Task RecordingWithExceptionPausedTest()
{
Recording.Start();
return Combination(captureExceptions: true)
.Verify(
(param1, param2) =>
{
Recording.Add("key", $"recorded {param1} {param2}");
Recording.Pause();
if (param1 == 1)
{
throw new("boom");
}

return $"{param1} {param2}";
},
params1,
params2)
.IgnoreStackTrace();
}

[Fact]
public Task RecordingPausedTest()
{
Expand Down
25 changes: 23 additions & 2 deletions src/Verify/Combinations/CombinationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ Task<CombinationResults> RunWithVoid(Func<object?[], Task> method) =>
InnerRun(async keys =>
{
await method(keys);
if (Recording.IsRecording())
var paused = Recording.IsPaused();
if (Recording.IsRecording() || paused)
{
var appends = Recording.Values().ToList();
var value = new InfoBuilder("void", appends);
Recording.Clear();
if (paused)
{
Recording.Resume();
}
return (CombinationResult.ForValue(keys, value), null);
}
return (CombinationResult.ForVoid(keys), null);
Expand All @@ -64,7 +69,23 @@ async Task<CombinationResults> InnerRun(Func<object?[], Task<(CombinationResult
when (captureExceptions)
{
await CombinationSettings.RunExceptionCallbacks(keys, exception);
items.Add(CombinationResult.ForException(keys, exception));

var paused = Recording.IsPaused();
if (Recording.IsRecording() || paused)
{
var appends = Recording.Values().ToList();
var value = new InfoBuilder(exception, appends);
items.Add(CombinationResult.ForValue(keys, value));
Recording.Clear();
if (paused)
{
Recording.Resume();
}
}
else
{
items.Add(CombinationResult.ForException(keys, exception));
}
}

if (Increment())
Expand Down

0 comments on commit 527eedf

Please sign in to comment.