From 8a73ade5b23cdd9daf384b605eac77dea880c4c8 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sat, 5 Nov 2022 11:46:22 -0600 Subject: [PATCH] fixed unit tests --- Terminal.Gui/Core/Application.cs | 3 +++ UnitTests/ApplicationTests.cs | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 88a840566..f9954d0bf 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -1279,6 +1279,9 @@ namespace Terminal.Gui { // Run() will eventually cause Application.Top to be set, via Begin() and SetCurrentAsTop() Run (top, errorHandler); } else { + if (!_initialized && driver == null) { + throw new ArgumentException ("Init has not been called; a valid driver and mainloop must be provided"); + } // Note in this case, we don't verify the type of the Toplevel created by new T(). Init (() => new T (), Driver == null ? driver : Driver, Driver == null ? mainLoopDriver : null, resetState: false); Run (Top, errorHandler); diff --git a/UnitTests/ApplicationTests.cs b/UnitTests/ApplicationTests.cs index bb3dd4233..da16c3dff 100644 --- a/UnitTests/ApplicationTests.cs +++ b/UnitTests/ApplicationTests.cs @@ -257,7 +257,7 @@ namespace Terminal.Gui.Core { Application.RequestStop (); }; - // Run when already initialized with a Driver will work + // Init has been called and we're passing no driver to Run. This is ok. Application.Run (errorHandler: null); Shutdown (); @@ -268,15 +268,14 @@ namespace Terminal.Gui.Core { } [Fact] - public void Run_T_NoInit_ThrowsInDefaultDriver () + public void Run_T_NoInit_Throws () { Application.Iteration = () => { Application.RequestStop (); }; - // Note that Init has NOT been called and we're passing no driver - // The platform-default driver will be selected and it will barf - Assert.ThrowsAny (() => Application.Run (errorHandler: null, driver: null, mainLoopDriver: null)); + // Init has NOT been called and we're passing no driver to Run. This is an error. + Assert.Throws (() => Application.Run (errorHandler: null, driver: null, mainLoopDriver: null)); Shutdown (); @@ -292,8 +291,7 @@ namespace Terminal.Gui.Core { Application.RequestStop (); }; - // Note that Init has NOT been called and we're passing no driver - // The platform-default driver will be selected and it will barf + // Init has NOT been called and we're passing a valid driver to Run. This is ok. Application.Run (errorHandler: null, new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true))); Shutdown ();