From 3960655a4286d69038857413b3d47c3fef4bb813 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 11 Nov 2024 23:50:50 +0900 Subject: [PATCH] Further improve stacktrace output --- .../Testing/Drawables/Steps/AssertButton.cs | 4 +++- .../Drawables/Steps/TracedException.cs | 21 ------------------- .../Drawables/Steps/UntilStepButton.cs | 4 +++- osu.Framework/Testing/TestScene.cs | 11 +++++----- 4 files changed, 12 insertions(+), 28 deletions(-) delete mode 100644 osu.Framework/Testing/Drawables/Steps/TracedException.cs diff --git a/osu.Framework/Testing/Drawables/Steps/AssertButton.cs b/osu.Framework/Testing/Drawables/Steps/AssertButton.cs index a57d2eb628..d910acb964 100644 --- a/osu.Framework/Testing/Drawables/Steps/AssertButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/AssertButton.cs @@ -3,7 +3,9 @@ using System; using System.Diagnostics; +using System.Runtime.ExceptionServices; using System.Text; +using NUnit.Framework; using osuTK.Graphics; namespace osu.Framework.Testing.Drawables.Steps @@ -38,7 +40,7 @@ private void checkAssert() if (GetFailureMessage != null) builder.Append($": {GetFailureMessage()}"); - throw new TracedException(builder.ToString(), CallStack); + throw ExceptionDispatchInfo.SetRemoteStackTrace(new AssertionException(builder.ToString()), CallStack.ToString()); } } diff --git a/osu.Framework/Testing/Drawables/Steps/TracedException.cs b/osu.Framework/Testing/Drawables/Steps/TracedException.cs deleted file mode 100644 index bd2284e96b..0000000000 --- a/osu.Framework/Testing/Drawables/Steps/TracedException.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) ppy Pty Ltd . 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(); - } -} diff --git a/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs b/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs index b3c6bd6722..89447a9512 100644 --- a/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs @@ -3,7 +3,9 @@ using System; using System.Diagnostics; +using System.Runtime.ExceptionServices; using System.Text; +using NUnit.Framework; using osu.Framework.Graphics; using osuTK.Graphics; @@ -60,7 +62,7 @@ private void checkAssert() if (GetFailureMessage != null) builder.Append($": {GetFailureMessage()}"); - throw new TracedException(builder.ToString(), CallStack); + throw ExceptionDispatchInfo.SetRemoteStackTrace(new AssertionException(builder.ToString()), CallStack.ToString()); } Action?.Invoke(); diff --git a/osu.Framework/Testing/TestScene.cs b/osu.Framework/Testing/TestScene.cs index 9bdf41f8ba..c781cd9619 100644 --- a/osu.Framework/Testing/TestScene.cs +++ b/osu.Framework/Testing/TestScene.cs @@ -331,7 +331,7 @@ protected void AddUntilStep([CanBeNull] string description, [NotNull] Func { Text = description ?? @"Until", IsSetupStep = addStepsAsSetupSteps, - CallStack = new StackTrace(1), + CallStack = new StackTrace(1, true), Assertion = waitUntilTrueDelegate, }); } @@ -344,7 +344,7 @@ protected void AddUntilStep([CanBeNull] string description, [NotNull] ActualV { Text = description ?? @"Until", IsSetupStep = addStepsAsSetupSteps, - CallStack = new StackTrace(1), + CallStack = new StackTrace(1, true), Assertion = () => { lastResult = constraint().Resolve().ApplyTo(actualValue()); @@ -390,12 +390,13 @@ protected void AddAssert([NotNull] string description, [NotNull] Func asse Text = description, IsSetupStep = addStepsAsSetupSteps, ExtendedDescription = extendedDescription, - CallStack = new StackTrace(1), + CallStack = new StackTrace(1, true), Assertion = assert, }); } - protected void AddAssert([NotNull] string description, [NotNull] ActualValueDelegate actualValue, [NotNull] Func constraint, [CanBeNull] string extendedDescription = null) + protected void AddAssert([NotNull] string description, [NotNull] ActualValueDelegate actualValue, [NotNull] Func constraint, + [CanBeNull] string extendedDescription = null) { ConstraintResult lastResult = null; @@ -404,7 +405,7 @@ protected void AddAssert([NotNull] string description, [NotNull] ActualValueD Text = description, IsSetupStep = addStepsAsSetupSteps, ExtendedDescription = extendedDescription, - CallStack = new StackTrace(1), + CallStack = new StackTrace(1, true), Assertion = () => { lastResult = constraint().Resolve().ApplyTo(actualValue());