Browse Source

fixed unit tests

Charlie Kindel 2 năm trước cách đây
mục cha
commit
8a73ade5b2
2 tập tin đã thay đổi với 8 bổ sung7 xóa
  1. 3 0
      Terminal.Gui/Core/Application.cs
  2. 5 7
      UnitTests/ApplicationTests.cs

+ 3 - 0
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);

+ 5 - 7
UnitTests/ApplicationTests.cs

@@ -257,7 +257,7 @@ namespace Terminal.Gui.Core {
 				Application.RequestStop ();
 			};
 			
-			// Run<TestToplevel> when already initialized with a Driver will work
+			// Init has been called and we're passing no driver to Run<TestTopLevel>. This is ok.
 			Application.Run<TestToplevel> (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<Exception> (() => Application.Run<TestToplevel> (errorHandler: null, driver: null, mainLoopDriver: null));
+			// Init has NOT been called and we're passing no driver to Run<TestToplevel>. This is an error.
+			Assert.Throws<ArgumentException> (() => Application.Run<TestToplevel> (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<TestTopLevel>. This is ok.
 			Application.Run<TestToplevel> (errorHandler: null, new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
 
 			Shutdown ();