A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using System.Diagnostics;
6using osuTK.Graphics;
7
8namespace osu.Framework.Testing.Drawables.Steps
9{
10 public class AssertButton : StepButton
11 {
12 public Func<bool> Assertion;
13 public string ExtendedDescription;
14 public StackTrace CallStack;
15
16 public AssertButton(bool isSetupStep = false)
17 : base(isSetupStep)
18 {
19 Action += checkAssert;
20 LightColour = Color4.OrangeRed;
21 }
22
23 private void checkAssert()
24 {
25 if (Assertion())
26 Success();
27 else
28 throw new TracedException($"{Text} {ExtendedDescription}", CallStack);
29 }
30
31 public override string ToString() => "Assert: " + base.ToString();
32
33 private class TracedException : Exception
34 {
35 private readonly StackTrace trace;
36
37 public TracedException(string description, StackTrace trace)
38 : base(description)
39 {
40 this.trace = trace;
41 }
42
43 public override string StackTrace => trace.ToString();
44 }
45 }
46}