Skip to content

Commit 527eedf

Browse files
authored
Make combination tests support recording when an exception is thrown (#1340)
1 parent a4b159a commit 527eedf

5 files changed

Lines changed: 115 additions & 3 deletions

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
5-
<Version>28.1.2</Version>
5+
<Version>28.1.3</Version>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<LangVersion>preview</LangVersion>
88
<AssemblyVersion>1.0.0</AssemblyVersion>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
1, Smith St : {
3+
target: {
4+
Type: Exception,
5+
Message: boom
6+
},
7+
key: recorded 1 Smith St
8+
},
9+
1, Wallace St: {
10+
target: {
11+
Type: Exception,
12+
Message: boom
13+
},
14+
key: recorded 1 Wallace St
15+
},
16+
10, Smith St : {
17+
target: 10 Smith St,
18+
key: recorded 10 Smith St
19+
},
20+
10, Wallace St: {
21+
target: 10 Wallace St,
22+
key: recorded 10 Wallace St
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
1, Smith St : {
3+
target: {
4+
Type: Exception,
5+
Message: boom
6+
},
7+
key: recorded 1 Smith St
8+
},
9+
1, Wallace St: {
10+
target: {
11+
Type: Exception,
12+
Message: boom
13+
},
14+
key: recorded 1 Wallace St
15+
},
16+
10, Smith St : {
17+
target: 10 Smith St,
18+
key: recorded 10 Smith St
19+
},
20+
10, Wallace St: {
21+
target: 10 Wallace St,
22+
key: recorded 10 Wallace St
23+
}
24+
}

src/Verify.Tests/CombinationTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,49 @@ public Task RecordingTest()
107107
params2);
108108
}
109109

110+
[Fact]
111+
public Task RecordingWithExceptionTest()
112+
{
113+
Recording.Start();
114+
return Combination(captureExceptions: true)
115+
.Verify(
116+
(param1, param2) =>
117+
{
118+
Recording.Add("key", $"recorded {param1} {param2}");
119+
if (param1 == 1)
120+
{
121+
throw new("boom");
122+
}
123+
124+
return $"{param1} {param2}";
125+
},
126+
params1,
127+
params2)
128+
.IgnoreStackTrace();
129+
}
130+
131+
[Fact]
132+
public Task RecordingWithExceptionPausedTest()
133+
{
134+
Recording.Start();
135+
return Combination(captureExceptions: true)
136+
.Verify(
137+
(param1, param2) =>
138+
{
139+
Recording.Add("key", $"recorded {param1} {param2}");
140+
Recording.Pause();
141+
if (param1 == 1)
142+
{
143+
throw new("boom");
144+
}
145+
146+
return $"{param1} {param2}";
147+
},
148+
params1,
149+
params2)
150+
.IgnoreStackTrace();
151+
}
152+
110153
[Fact]
111154
public Task RecordingPausedTest()
112155
{

src/Verify/Combinations/CombinationRunner.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ Task<CombinationResults> RunWithVoid(Func<object?[], Task> method) =>
3737
InnerRun(async keys =>
3838
{
3939
await method(keys);
40-
if (Recording.IsRecording())
40+
var paused = Recording.IsPaused();
41+
if (Recording.IsRecording() || paused)
4142
{
4243
var appends = Recording.Values().ToList();
4344
var value = new InfoBuilder("void", appends);
4445
Recording.Clear();
46+
if (paused)
47+
{
48+
Recording.Resume();
49+
}
4550
return (CombinationResult.ForValue(keys, value), null);
4651
}
4752
return (CombinationResult.ForVoid(keys), null);
@@ -64,7 +69,23 @@ async Task<CombinationResults> InnerRun(Func<object?[], Task<(CombinationResult
6469
when (captureExceptions)
6570
{
6671
await CombinationSettings.RunExceptionCallbacks(keys, exception);
67-
items.Add(CombinationResult.ForException(keys, exception));
72+
73+
var paused = Recording.IsPaused();
74+
if (Recording.IsRecording() || paused)
75+
{
76+
var appends = Recording.Values().ToList();
77+
var value = new InfoBuilder(exception, appends);
78+
items.Add(CombinationResult.ForValue(keys, value));
79+
Recording.Clear();
80+
if (paused)
81+
{
82+
Recording.Resume();
83+
}
84+
}
85+
else
86+
{
87+
items.Add(CombinationResult.ForException(keys, exception));
88+
}
6889
}
6990

7091
if (Increment())

0 commit comments

Comments
 (0)