From 90d563b7964f3ace2d253f2915cddcb12cae8de9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 27 Aug 2026 09:02:35 +0200 Subject: [PATCH] Walk the step tree with the helper the repo already has Three copies of the same pre-order walk across two test files become TreeTraversal.PreOrder, and the stepper fixture builds its decompiler through the file-name constructor instead of assembling the type system by hand. Assisted-by: Claude:claude-opus-5[1m]:Claude Code --- .../DebugStepRecordingTests.cs | 27 +++---------------- .../Helpers/StepperTesting.cs | 6 ++--- ILSpy.Tests/Views/DebugStepsTests.cs | 13 +-------- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/DebugStepRecordingTests.cs b/ICSharpCode.Decompiler.Tests/DebugStepRecordingTests.cs index cbdda8c8c..e3139ebb2 100644 --- a/ICSharpCode.Decompiler.Tests/DebugStepRecordingTests.cs +++ b/ICSharpCode.Decompiler.Tests/DebugStepRecordingTests.cs @@ -23,6 +23,7 @@ using System.Linq; using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.DebugSteps; using ICSharpCode.Decompiler.IL; +using ICSharpCode.Decompiler.Util; using ICSharpCode.Decompiler.IL.Transforms; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Tests.Helpers; @@ -56,7 +57,7 @@ namespace ICSharpCode.Decompiler.Tests decompiler.DecompileTypeAsString(SampleType); - Assert.That(Descriptions(decompiler.Stepper.Steps), Has.Some.Contains(RecordedStep)); + Assert.That(TreeTraversal.PreOrder(decompiler.Stepper.Steps, n => n.Children).Select(n => n.Description), Has.Some.Contains(RecordedStep)); } /// @@ -72,7 +73,7 @@ namespace ICSharpCode.Decompiler.Tests decompiler.DecompileTypeAsString(SampleType); - Assert.That(Descriptions(decompiler.Stepper.Steps), Has.None.Contains(RecordedStep)); + Assert.That(TreeTraversal.PreOrder(decompiler.Stepper.Steps, n => n.Children).Select(n => n.Description), Has.None.Contains(RecordedStep)); } /// @@ -301,7 +302,7 @@ namespace ICSharpCode.Decompiler.Tests var decompiler = CreateRecordingDecompiler(); decompiler.ILTransforms.Add(detachedStep); decompiler.DecompileTypeAsString(SampleType); - int haltAt = AllNodes(decompiler.Stepper.Steps).Single(n => n.Description.Contains(DetachedStep)).BeginStep; + int haltAt = TreeTraversal.PreOrder(decompiler.Stepper.Steps, n => n.Children).Single(n => n.Description.Contains(DetachedStep)).BeginStep; var replay = CreateRecordingDecompiler(); var replayStep = new DetachedFunctionILTransform("CleanUpFileName"); @@ -321,26 +322,6 @@ namespace ICSharpCode.Decompiler.Tests return decompiler.Stepper.Steps.Single(n => n.Description.EndsWith("." + methodName, StringComparison.Ordinal)); } - static IEnumerable AllNodes(IEnumerable nodes) - { - foreach (var node in nodes) - { - yield return node; - foreach (var child in AllNodes(node.Children)) - yield return child; - } - } - - static IEnumerable Descriptions(IEnumerable nodes) - { - foreach (var node in nodes) - { - yield return node.Description; - foreach (var description in Descriptions(node.Children)) - yield return description; - } - } - static CSharpDecompiler CreateRecordingDecompiler() { var decompiler = StepperTesting.CreateDecompiler(); diff --git a/ICSharpCode.Decompiler.Tests/Helpers/StepperTesting.cs b/ICSharpCode.Decompiler.Tests/Helpers/StepperTesting.cs index c203b3017..23d018d86 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/StepperTesting.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/StepperTesting.cs @@ -37,10 +37,8 @@ namespace ICSharpCode.Decompiler.Tests.Helpers public static CSharpDecompiler CreateDecompiler() { - var module = new PEFile("ICSharpCode.Decompiler.dll"); - var settings = new DecompilerSettings(); - var typeSystem = new DecompilerTypeSystem(module, new UniversalAssemblyResolver(null, false, null), settings); - return new CSharpDecompiler(typeSystem, settings); + return new CSharpDecompiler("ICSharpCode.Decompiler.dll", + new UniversalAssemblyResolver(null, false, null), new DecompilerSettings()); } /// diff --git a/ILSpy.Tests/Views/DebugStepsTests.cs b/ILSpy.Tests/Views/DebugStepsTests.cs index ceee15076..5cd21895e 100644 --- a/ILSpy.Tests/Views/DebugStepsTests.cs +++ b/ILSpy.Tests/Views/DebugStepsTests.cs @@ -223,21 +223,10 @@ public class DebugStepsTests var ilTransformNames = CSharpDecompiler.GetILTransforms() .Select(transform => transform.GetType().Name) .ToHashSet(); - AllDescriptions(csharp.Stepper.Steps).Should().NotContain( + ICSharpCode.Decompiler.Util.TreeTraversal.PreOrder(csharp.Stepper.Steps, n => n.Children).Select(n => n.Description).Should().NotContain( description => ilTransformNames.Contains(StripStepNumber(description)), "a closed pane leaves the IL transforms unrecorded"); csharp.Stepper.Steps.Should().BeEmpty("a closed pane leaves the whole pipeline unrecorded"); - - static System.Collections.Generic.IEnumerable AllDescriptions( - System.Collections.Generic.IEnumerable nodes) - { - foreach (var node in nodes) - { - yield return node.Description; - foreach (var description in AllDescriptions(node.Children)) - yield return description; - } - } } [AvaloniaTest]