Skip to content

Commit

Permalink
Give UntilStepButton a proper stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Nov 11, 2024
1 parent 94bd9c2 commit 42a01b9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public TestSceneStepButton()
{
Text = nameof(UntilStepButton),
IsSetupStep = false,
Assertion = () => true
Assertion = () => true,
CallStack = new StackTrace()
},
new StepSlider<int>(nameof(StepSlider<int>), 0, 10, 5),
}
Expand Down
14 changes: 0 additions & 14 deletions osu.Framework/Testing/Drawables/Steps/AssertButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using System.Text;
using NUnit.Framework;
using osuTK.Graphics;

namespace osu.Framework.Testing.Drawables.Steps
Expand Down Expand Up @@ -44,18 +43,5 @@ private void checkAssert()
}

public override string ToString() => "Assert: " + base.ToString();

private class TracedException : AssertionException
{
private readonly StackTrace trace;

public TracedException(string description, StackTrace trace)
: base(description)
{
this.trace = trace;
}

public override string StackTrace => trace.ToString();
}
}
}
21 changes: 21 additions & 0 deletions osu.Framework/Testing/Drawables/Steps/TracedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics;
using NUnit.Framework;

namespace osu.Framework.Testing.Drawables.Steps
{
internal class TracedException : AssertionException
{
private readonly StackTrace trace;

public TracedException(string description, StackTrace trace)
: base(description)
{
this.trace = trace;
}

public override string StackTrace => trace.ToString();
}
}
4 changes: 2 additions & 2 deletions osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using System.Text;
using NUnit.Framework;
using osu.Framework.Graphics;
using osuTK.Graphics;

Expand All @@ -14,6 +13,7 @@ public partial class UntilStepButton : StepButton
{
private static readonly int max_attempt_milliseconds = FrameworkEnvironment.NoTestTimeout ? int.MaxValue : 10000;

public required StackTrace CallStack { get; init; }
public required Func<bool> Assertion { get; init; }
public Func<string>? GetFailureMessage { get; init; }
public new Action? Action { get; set; }
Expand Down Expand Up @@ -60,7 +60,7 @@ private void checkAssert()
if (GetFailureMessage != null)
builder.Append($": {GetFailureMessage()}");

throw new AssertionException(builder.ToString());
throw new TracedException(builder.ToString(), CallStack);
}

Action?.Invoke();
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Testing/TestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ protected void AddUntilStep([CanBeNull] string description, [NotNull] Func<bool>
{
Text = description ?? @"Until",
IsSetupStep = addStepsAsSetupSteps,
CallStack = new StackTrace(1),
Assertion = waitUntilTrueDelegate,
});
}
Expand All @@ -343,6 +344,7 @@ protected void AddUntilStep<T>([CanBeNull] string description, [NotNull] ActualV
{
Text = description ?? @"Until",
IsSetupStep = addStepsAsSetupSteps,
CallStack = new StackTrace(1),
Assertion = () =>
{
lastResult = constraint().Resolve().ApplyTo(actualValue());
Expand Down

0 comments on commit 42a01b9

Please sign in to comment.