Skip to content

Commit

Permalink
Remove unnecessary test code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Dec 18, 2024
1 parent bea72f9 commit 0262e78
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ internal static class WellKnownTrackingNames
/// </summary>
public const string Execute = nameof(Execute);

/// <summary>
/// The filtered transform with just output diagnostics.
/// </summary>
public const string Diagnostics = nameof(Diagnostics);

/// <summary>
/// The filtered transform with just output sources.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,14 @@ public static void VerifySources(string source, (string Filename, string Source)
/// <param name="source">The input source to process.</param>
/// <param name="updatedSource">The updated source to process.</param>
/// <param name="executeReason">The reason for the first <c>"Execute"</c> step.</param>
/// <param name="diagnosticsReason">The reason for the <c>"Diagnostics"</c> step.</param>
/// <param name="outputReason">The reason for the <c>"Output"</c> step.</param>
/// <param name="diagnosticsSourceReason">The reason for the output step for the diagnostics.</param>
/// <param name="sourceReason">The reason for the final output source.</param>
/// <param name="languageVersion">The language version to use to run the test.</param>
public static void VerifyIncrementalSteps(
string source,
string updatedSource,
IncrementalStepRunReason executeReason,
IncrementalStepRunReason? diagnosticsReason,
IncrementalStepRunReason outputReason,
IncrementalStepRunReason? diagnosticsSourceReason,
IncrementalStepRunReason sourceReason,
LanguageVersion languageVersion = LanguageVersion.CSharp13)
{
Expand All @@ -110,61 +106,17 @@ public static void VerifyIncrementalSteps(

GeneratorRunResult result = driver.GetRunResult().Results.Single();

// Get the generated sources and validate them. We have two possible cases: if no diagnostics
// are produced, then just the output source node is triggered. Otherwise, we'll also have one
// output node which is used to emit the gathered diagnostics from the initial transform step.
if (diagnosticsSourceReason is not null)
{
Assert.AreEqual(
expected: 2,
actual:
result.TrackedOutputSteps
.SelectMany(outputStep => outputStep.Value)
.SelectMany(output => output.Outputs)
.Count());

// The "Diagnostics" name has one more parent compared to "Output", because it also
// has one extra Where(...) call on the node (used to filter out empty diagnostics).
Assert.AreEqual(
expected: diagnosticsSourceReason,
actual:
result.TrackedOutputSteps
.Single().Value
.Single(run => run.Inputs[0].Source.Inputs[0].Source.Name == "Diagnostics")
.Outputs.Single().Reason);

Assert.AreEqual(
expected: sourceReason,
actual:
result.TrackedOutputSteps
.Single().Value
.Single(run => run.Inputs[0].Source.Name == "Output")
.Outputs.Single().Reason);
}
else
{
(object Value, IncrementalStepRunReason Reason)[] sourceOuputs =
result.TrackedOutputSteps
.SelectMany(outputStep => outputStep.Value)
.SelectMany(output => output.Outputs)
.ToArray();

Assert.AreEqual(1, sourceOuputs.Length);
Assert.AreEqual(sourceReason, sourceOuputs[0].Reason);
}
// Get the generated sources and validate them
(object Value, IncrementalStepRunReason Reason)[] sourceOuputs =
result.TrackedOutputSteps
.SelectMany(outputStep => outputStep.Value)
.SelectMany(output => output.Outputs)
.ToArray();

Assert.AreEqual(1, sourceOuputs.Length);
Assert.AreEqual(sourceReason, sourceOuputs[0].Reason);
Assert.AreEqual(executeReason, result.TrackedSteps["Execute"].Single().Outputs[0].Reason);
Assert.AreEqual(outputReason, result.TrackedSteps["Output"].Single().Outputs[0].Reason);

// Check the diagnostics reason, which might not be present
if (diagnosticsReason is not null)
{
Assert.AreEqual(diagnosticsReason, result.TrackedSteps["Diagnostics"].Single().Outputs[0].Reason);
}
else
{
Assert.IsFalse(result.TrackedSteps.ContainsKey("Diagnostics"));
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public partial class MyControl : DependencyObject
source,
updatedSource,
executeReason: IncrementalStepRunReason.Modified,
diagnosticsReason: null,
outputReason: IncrementalStepRunReason.Modified,
diagnosticsSourceReason: null,
sourceReason: IncrementalStepRunReason.Modified);
}

Expand Down Expand Up @@ -87,9 +85,7 @@ public partial class MyControl : DependencyObject
source,
updatedSource,
executeReason: IncrementalStepRunReason.Unchanged,
diagnosticsReason: null,
outputReason: IncrementalStepRunReason.Cached,
diagnosticsSourceReason: null,
sourceReason: IncrementalStepRunReason.Cached);
}

Expand Down Expand Up @@ -130,9 +126,7 @@ public void Foo()
source,
updatedSource,
executeReason: IncrementalStepRunReason.Unchanged,
diagnosticsReason: null,
outputReason: IncrementalStepRunReason.Cached,
diagnosticsSourceReason: null,
sourceReason: IncrementalStepRunReason.Cached);
}
}

0 comments on commit 0262e78

Please sign in to comment.