Browse Source

Fixes #2474. PushMockKeyPress/ReadKey requires extra keypress to work (sometimes).

BDisp 1 year ago
parent
commit
5889439815

+ 1 - 1
Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs

@@ -353,7 +353,7 @@ public class FakeDriver : ConsoleDriver {
 		_keyUpHandler = keyUpHandler;
 		_keyUpHandler = keyUpHandler;
 
 
 		// Note: Net doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
 		// Note: Net doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
-		(mainLoop.MainLoopDriver as FakeMainLoop).KeyPressed += (consoleKey) => ProcessInput (consoleKey);
+		(mainLoop.MainLoopDriver as FakeMainLoop).KeyPressed = (consoleKey) => ProcessInput (consoleKey);
 	}
 	}
 
 
 	void ProcessInput (ConsoleKeyInfo consoleKey)
 	void ProcessInput (ConsoleKeyInfo consoleKey)

+ 8 - 7
UnitTests/UICatalog/ScenarioTests.cs

@@ -74,16 +74,17 @@ namespace UICatalog.Tests {
 					// BUGBUG: (#2474) For some reason ReadKey is not returning the QuitKey for some Scenarios
 					// BUGBUG: (#2474) For some reason ReadKey is not returning the QuitKey for some Scenarios
 					// by adding this Space it seems to work.
 					// by adding this Space it seems to work.
 					// See #2474 for why this is commented out
 					// See #2474 for why this is commented out
-					//Assert.Equal (Application.QuitKey, args.KeyEvent.Key);
-					args.Handled = false;
+					Assert.Equal (Application.QuitKey, args.KeyEvent.Key);
 				};
 				};
 
 
 				uint abortTime = 500;
 				uint abortTime = 500;
 				// If the scenario doesn't close within 500ms, this will force it to quit
 				// If the scenario doesn't close within 500ms, this will force it to quit
 				Func<MainLoop, bool> forceCloseCallback = (MainLoop loop) => {
 				Func<MainLoop, bool> forceCloseCallback = (MainLoop loop) => {
-					Application.RequestStop ();
-					// See #2474 for why this is commented out
-					//Assert.Fail ($"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
+					if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0) {
+						Application.RequestStop ();
+						// See #2474 for why this is commented out
+						Assert.Fail ($"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
+					}
 					return false;
 					return false;
 				};
 				};
 				//output.WriteLine ($"  Add timeout to force quit after {abortTime}ms");
 				//output.WriteLine ($"  Add timeout to force quit after {abortTime}ms");
@@ -91,9 +92,9 @@ namespace UICatalog.Tests {
 
 
 				Application.Iteration += () => {
 				Application.Iteration += () => {
 					//output.WriteLine ($"  iteration {++iterations}");
 					//output.WriteLine ($"  iteration {++iterations}");
-					if (FakeConsole.MockKeyPresses.Count == 0) {
+					if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0) {
 						Application.RequestStop ();
 						Application.RequestStop ();
-						//Assert.Fail ($"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey}. Force quit.");
+						Assert.Fail ($"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey}. Force quit.");
 					}
 					}
 				};
 				};