CrabUI
Loading...
Searching...
No Matches
Commands.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6using System.Runtime.CompilerServices;
7using System.IO;
8
9using Barotrauma;
10using Microsoft.Xna.Framework;
11using Microsoft.Xna.Framework.Input;
12using Microsoft.Xna.Framework.Graphics;
13using HarmonyLib;
14using CrabUI;
15
16namespace CrabUITest
17{
18 public partial class CUITest
19 {
20 public static List<DebugConsole.Command> AddedCommands = new List<DebugConsole.Command>();
21 public static void AddCommands()
22 {
23 AddedCommands.Add(new DebugConsole.Command("cuiunittest", "", CUIUnitTest,
24 () => new string[][] {
25 UnitTest.FindAllTests().Values.Select(T => T.Name).Append("all").ToArray()
26 }));
27
28 AddedCommands.Add(new DebugConsole.Command("cuitest", "", CUITestCommand,
29 () => new string[][] {
30 CUITest.automaticTestRunner.GetClassMethodPairs().Append("end").Append("all").ToArray()
31 }));
32
33 AddedCommands.Add(new DebugConsole.Command("cuistash", "", CUIStash,
34 () => new string[][] {
35 CUITest.automaticTestRunner.GetClassMethodPairs().Append("clear").ToArray()
36 }));
37
38 AddedCommands.Add(new DebugConsole.Command("cuimodtest", "", CUIModTest,
39 () => new string[][] {
40 CUITest.fakeModRunner.FindAllFakeMods().Append("end").ToArray()
41 }));
42
43
44 AddedCommands.Add(new DebugConsole.Command("cuicoverage", "", CUICoverage));
45
46
47
48 DebugConsole.Commands.InsertRange(0, AddedCommands);
49 }
50
51 public static void CUIUnitTest(string[] args)
52 {
53 if (args.Length == 0) { CUITest.Log("mb name?"); return; }
54 UnitTest.Run(args[0], args.ElementAtOrDefault(1));
55 }
56
57 public static void CUIStash(string[] args)
58 {
59 if (args.Length == 0) { CUITest.Log("mb name?"); return; }
60
61 if (String.Equals(args[0], "clear", StringComparison.OrdinalIgnoreCase))
62 {
63 CUITest.automaticTestRunner.ClearStash();
64 return;
65 }
66
67 CUITest.automaticTestRunner.StashTest(args[0]);
68 }
69
70 public static void CUITestCommand(string[] args)
71 {
72 if (args.Length == 0) { CUITest.Log("mb name?"); return; }
73
74 if (String.Equals(args[0], "end", StringComparison.OrdinalIgnoreCase))
75 {
76 CUITest.automaticTestRunner.StopTest();
77 return;
78 }
79
80 if (String.Equals(args[0], "all", StringComparison.OrdinalIgnoreCase))
81 {
82 CUITest.automaticTestRunner.RunAllTests();
83 return;
84 }
85
86 CUITest.automaticTestRunner.RunTest(args[0]);
87 }
88
89 public static void CUIModTest(string[] args)
90 {
91 if (args.Length == 0) { CUITest.Log("mb name?"); return; }
92
93 if (String.Equals(args[0], "end", StringComparison.OrdinalIgnoreCase))
94 {
95 CUITest.fakeModRunner.StopTest();
96 return;
97 }
98
99 CUITest.fakeModRunner.RunTest(args[0]);
100 }
101
102 public static void CUICoverage(string[] args)
103 {
104 ComponentTest.PrintCoverage();
105 }
106
107 public static void RemoveCommands()
108 {
109 AddedCommands.ForEach(c => DebugConsole.Commands.Remove(c));
110 AddedCommands.Clear();
111 }
112
113 // public static void PermitCommands(Identifier command, ref bool __result)
114 // {
115 // if (AddedCommands.Any(c => c.Names.Contains(command.Value))) __result = true;
116 // }
117 }
118}
Testing the overall behavior of a component.
Definition CUIWater.cs:19