|
3 | 3 | using RuriLib.Models.Debugger; |
4 | 4 | using System; |
5 | 5 | using System.IO; |
6 | | -using System.Runtime.CompilerServices; |
7 | 6 | using System.Threading.Tasks; |
8 | 7 | using Xunit; |
9 | 8 |
|
@@ -98,16 +97,60 @@ public async Task Run_WithInvalidProxy_ResetsStatusToIdle() |
98 | 97 | Assert.Equal(ConfigDebuggerStatus.Idle, debugger.Status); |
99 | 98 | } |
100 | 99 |
|
101 | | - private static ConfigDebugger CreateDebugger(DebuggerOptions? options = null) |
102 | | - => new(new Config |
| 100 | + [Fact] |
| 101 | + public async Task Run_LegacyConfigInStepByStepMode_WaitsForExplicitStep() |
| 102 | + { |
| 103 | + var cancellationToken = TestContext.Current.CancellationToken; |
| 104 | + |
| 105 | + using var debugger = CreateDebugger(new Config |
103 | 106 | { |
104 | | - Id = "test" |
105 | | - }, options ?? new DebuggerOptions(), new BotLogger()); |
| 107 | + Id = "legacy-test", |
| 108 | + Mode = ConfigMode.Legacy, |
| 109 | + LoliScript = "PRINT \"first\"\nPRINT \"second\"" |
| 110 | + }, new DebuggerOptions |
| 111 | + { |
| 112 | + TestData = "test", |
| 113 | + WordlistType = "Default", |
| 114 | + StepByStep = true |
| 115 | + }); |
| 116 | + |
| 117 | + debugger.RuriLibSettings = CreateSettingsService(); |
| 118 | + debugger.RNGProvider = new global::RuriLib.Providers.RandomNumbers.DefaultRNGProvider(); |
| 119 | + debugger.PluginRepo = CreatePluginRepository(); |
| 120 | + |
| 121 | + var waitingForStep = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); |
| 122 | + debugger.StatusChanged += (_, status) => |
| 123 | + { |
| 124 | + if (status == ConfigDebuggerStatus.WaitingForStep) |
| 125 | + { |
| 126 | + waitingForStep.TrySetResult(); |
| 127 | + } |
| 128 | + }; |
| 129 | + |
| 130 | + var runTask = debugger.Run(); |
| 131 | + |
| 132 | + await waitingForStep.Task.WaitAsync(TimeSpan.FromSeconds(5), cancellationToken); |
| 133 | + |
| 134 | + Assert.Equal(ConfigDebuggerStatus.WaitingForStep, debugger.Status); |
| 135 | + Assert.Contains(debugger.Logger.Entries, e => e.Message == "\"first\""); |
| 136 | + Assert.DoesNotContain(debugger.Logger.Entries, e => e.Message == "\"second\""); |
| 137 | + Assert.True(debugger.TryTakeStep()); |
| 138 | + |
| 139 | + await runTask.WaitAsync(TimeSpan.FromSeconds(5), cancellationToken); |
| 140 | + |
| 141 | + Assert.Equal(ConfigDebuggerStatus.Idle, debugger.Status); |
| 142 | + Assert.Contains(debugger.Logger.Entries, e => e.Message == "\"second\""); |
| 143 | + } |
| 144 | + |
| 145 | + private static ConfigDebugger CreateDebugger(DebuggerOptions? options = null) |
| 146 | + => CreateDebugger(new Config { Id = "test" }, options); |
| 147 | + |
| 148 | + private static ConfigDebugger CreateDebugger(Config config, DebuggerOptions? options = null) |
| 149 | + => new(config, options ?? new DebuggerOptions(), new BotLogger()); |
106 | 150 |
|
107 | 151 | private static global::RuriLib.Services.RuriLibSettingsService CreateSettingsService() |
108 | 152 | => new(Path.Combine(Path.GetTempPath(), $"ob2-config-debugger-tests-{Guid.NewGuid():N}")); |
109 | 153 |
|
110 | 154 | private static global::RuriLib.Services.PluginRepository CreatePluginRepository() |
111 | | - => (global::RuriLib.Services.PluginRepository)RuntimeHelpers |
112 | | - .GetUninitializedObject(typeof(global::RuriLib.Services.PluginRepository)); |
| 155 | + => new(Path.Combine(Path.GetTempPath(), $"ob2-plugin-repo-tests-{Guid.NewGuid():N}")); |
113 | 156 | } |
0 commit comments