Skip to content

Commit b7baada

Browse files
committed
TUnit configureawait false
1 parent 3cc6c0c commit b7baada

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

src/AutoCtor.Tests/ExampleTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public async Task CodeCompilesProperly(CodeFileTheoryData theoryData)
4646

4747
await Assert.That(outputCompilation.GetDiagnostics(TestHelper.CancellationToken)
4848
.Where(d => !theoryData.IgnoredCompileDiagnostics.Contains(d.Id)))
49-
.IsEmpty();
49+
.IsEmpty()
50+
.ConfigureAwait(false);
5051
}
5152

5253
#if ROSLYN_4_4

src/AutoCtor.Tests/GeneratedAttributeTests.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ public async Task AttributeCompilesProperly()
3939
var outputCompilationDiagnostics = outputCompilation
4040
.GetDiagnostics(TestHelper.CancellationToken);
4141

42-
await Assert.That(diagnostics).IsEmpty();
43-
await Assert.That(outputCompilationDiagnostics).IsEmpty();
42+
await Assert.That(diagnostics).IsEmpty()
43+
.ConfigureAwait(false);
44+
await Assert.That(outputCompilationDiagnostics).IsEmpty()
45+
.ConfigureAwait(false);
4446
}
4547

4648
[Test]
@@ -66,8 +68,10 @@ public async Task PreserveAttributesTest()
6668
var outputCompilationDiagnostics = outputCompilation
6769
.GetDiagnostics(TestHelper.CancellationToken);
6870

69-
await Assert.That(diagnostics).IsEmpty();
70-
await Assert.That(outputCompilationDiagnostics).IsEmpty();
71+
await Assert.That(diagnostics).IsEmpty()
72+
.ConfigureAwait(false);
73+
await Assert.That(outputCompilationDiagnostics).IsEmpty()
74+
.ConfigureAwait(false);
7175
}
7276

7377
[Test]
@@ -102,7 +106,9 @@ public async Task EnsureGeneratedAttributesAreNotExternallyVisible()
102106
var outputCompilationDiagnostics = outputCompilation
103107
.GetDiagnostics(TestHelper.CancellationToken);
104108

105-
await Assert.That(diagnostics).IsEmpty();
106-
await Assert.That(outputCompilationDiagnostics).IsEmpty();
109+
await Assert.That(diagnostics).IsEmpty()
110+
.ConfigureAwait(false);
111+
await Assert.That(outputCompilationDiagnostics).IsEmpty()
112+
.ConfigureAwait(false);
107113
}
108114
}

src/AutoCtor.Tests/Issue73.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ public async Task CodeCompilesWithoutErrors()
4141
.GetDiagnostics(TestHelper.CancellationToken)
4242
.Where(d => !ignoredWarnings.Contains(d.Id));
4343

44-
await Assert.That(diagnostics).IsEmpty();
45-
await Assert.That(outputCompilationDiagnostics).IsEmpty();
44+
await Assert.That(diagnostics).IsEmpty()
45+
.ConfigureAwait(false);
46+
await Assert.That(outputCompilationDiagnostics).IsEmpty()
47+
.ConfigureAwait(false);
4648
}
4749

4850
private static CompilationBuilder Common()

src/AutoCtor.Tests/Utilities/ExampleTestsHelper.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public static async Task AssertRunsEqual(
5454
using var _ = Assert.Multiple();
5555

5656
// Both runs should have the same tracked steps
57-
await Assert.That(trackedSteps1).IsNotEmpty();
58-
await Assert.That(trackedSteps2.Keys).IsEquivalentTo(trackedSteps1.Keys);
57+
await Assert.That(trackedSteps1).IsNotEmpty()
58+
.ConfigureAwait(false);
59+
await Assert.That(trackedSteps2.Keys).IsEquivalentTo(trackedSteps1.Keys)
60+
.ConfigureAwait(false);
5961

6062
// Get the IncrementalGeneratorRunStep collection for each run
6163
foreach (var (trackingName, runSteps1) in trackedSteps1)
@@ -72,17 +74,18 @@ await AssertStepsEqual(runSteps1, runSteps2)
7274
static Dictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> GetTrackedSteps(
7375
GeneratorDriverRunResult runResult, IEnumerable<string> trackingNames)
7476
=> runResult
75-
.Results[0] // We're only running a single generator, so this is safe
76-
.TrackedSteps // Get the pipeline outputs
77-
.Where(step => trackingNames.Contains(step.Key)) // filter to known steps
78-
.ToDictionary(x => x.Key, x => x.Value); // Convert to a dictionary
77+
.Results[0] // We're only running a single generator, so this is safe
78+
.TrackedSteps // Get the pipeline outputs
79+
.Where(step => trackingNames.Contains(step.Key)) // filter to known steps
80+
.ToDictionary(x => x.Key, x => x.Value); // Convert to a dictionary
7981
}
8082

8183
private static async Task AssertStepsEqual(
8284
ImmutableArray<IncrementalGeneratorRunStep> runSteps1,
8385
ImmutableArray<IncrementalGeneratorRunStep> runSteps2)
8486
{
85-
await Assert.That(runSteps2.Length).IsEqualTo(runSteps2.Length);
87+
await Assert.That(runSteps2.Length).IsEqualTo(runSteps2.Length)
88+
.ConfigureAwait(false);
8689

8790
for (var i = 0; i < runSteps1.Length; i++)
8891
{
@@ -93,7 +96,8 @@ private static async Task AssertStepsEqual(
9396
var outputs1 = runStep1.Outputs.Select(x => x.Value);
9497
var outputs2 = runStep2.Outputs.Select(x => x.Value);
9598

96-
await Assert.That(outputs2).IsEquivalentTo(outputs1);
99+
await Assert.That(outputs2).IsEquivalentTo(outputs1)
100+
.ConfigureAwait(false);
97101

98102
// Therefore, on the second run the results should always be cached or unchanged!
99103
// - Unchanged is when the _input_ has changed, but the output hasn't
@@ -102,7 +106,8 @@ private static async Task AssertStepsEqual(
102106
[IncrementalStepRunReason.Cached, IncrementalStepRunReason.Unchanged];
103107
foreach (var (_, reason) in runStep2.Outputs)
104108
{
105-
await Assert.That(reason).IsIn(acceptableReasons);
109+
await Assert.That(reason).IsIn(acceptableReasons)
110+
.ConfigureAwait(false);
106111
}
107112
}
108113
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
public static class TestHelper
1+
using System.Runtime.CompilerServices;
2+
using TUnit.Assertions.Core;
3+
4+
public static class TestHelper
25
{
36
public static CancellationToken CancellationToken =>
47
TestContext.Current?.Execution?.CancellationToken ?? CancellationToken.None;
8+
9+
public static ConfiguredTaskAwaitable<TValue?> ConfigureAwait<TValue>(this Assertion<TValue> assertion, bool continueOnCapturedContext)
10+
{
11+
return assertion.AssertAsync().ConfigureAwait(continueOnCapturedContext);
12+
}
513
}

0 commit comments

Comments
 (0)