A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using NUnit.Framework.Interfaces;
5using NUnit.Framework.Internal;
6
7namespace UnityEngine.TestTools.TestRunner.Callbacks
8{
9 internal class TestResultRenderer
10 {
11 private static class Styles
12 {
13 public static readonly GUIStyle SucceedLabelStyle;
14 public static readonly GUIStyle FailedLabelStyle;
15 public static readonly GUIStyle FailedMessagesStyle;
16
17 static Styles()
18 {
19 SucceedLabelStyle = new GUIStyle("label");
20 SucceedLabelStyle.normal.textColor = Color.green;
21 SucceedLabelStyle.fontSize = 48;
22
23 FailedLabelStyle = new GUIStyle("label");
24 FailedLabelStyle.normal.textColor = Color.red;
25 FailedLabelStyle.fontSize = 32;
26
27 FailedMessagesStyle = new GUIStyle("label");
28 FailedMessagesStyle.wordWrap = false;
29 FailedMessagesStyle.richText = true;
30 }
31 }
32
33 private readonly List<ITestResult> m_FailedTestCollection;
34
35 private bool m_ShowResults;
36 private Vector2 m_ScrollPosition;
37
38 public TestResultRenderer(ITestResult testResults)
39 {
40 m_FailedTestCollection = new List<ITestResult>();
41 GetFailedTests(testResults);
42 }
43
44 private void GetFailedTests(ITestResult testResults)
45 {
46 if (testResults is TestCaseResult)
47 {
48 if (testResults.ResultState.Status == TestStatus.Failed)
49 m_FailedTestCollection.Add(testResults);
50 }
51 else if (testResults.HasChildren)
52 {
53 foreach (var testResultsChild in testResults.Children)
54 {
55 GetFailedTests(testResultsChild);
56 }
57 }
58 }
59
60 private const int k_MaxStringLength = 15000;
61
62 public void ShowResults()
63 {
64 m_ShowResults = true;
65 Cursor.visible = true;
66 }
67
68 public void Draw()
69 {
70 if (!m_ShowResults) return;
71 if (m_FailedTestCollection.Count == 0)
72 {
73 GUILayout.Label("All test(s) succeeded", Styles.SucceedLabelStyle, GUILayout.Width(600));
74 }
75 else
76 {
77 int count = m_FailedTestCollection.Count;
78 GUILayout.Label(count + " tests failed!", Styles.FailedLabelStyle);
79
80 m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition, GUILayout.ExpandWidth(true));
81 var text = "";
82
83 text += "<b><size=18>Code-based tests</size></b>\n";
84 text += string.Join("\n", m_FailedTestCollection
85 .Select(result => result.Name + " " + result.ResultState + "\n" + result.Message)
86 .ToArray());
87
88 if (text.Length > k_MaxStringLength)
89 text = text.Substring(0, k_MaxStringLength);
90
91 GUILayout.TextArea(text, Styles.FailedMessagesStyle);
92 GUILayout.EndScrollView();
93 }
94 if (GUILayout.Button("Close"))
95 Application.Quit();
96 }
97 }
98}