浏览代码

WIP: Almost there!

Refactored tests and code to align with the modern instance-based
application model. Key changes include:

- Disabled Sixel rendering in `OutputBase.cs` due to dependency on
  legacy static `Application` object.
- Hardcoded `force16Colors` to `false` in `WindowsOutput.cs` with a
  `BUGBUG` note.
- Updated `ApplicationImplTests` to use `ApplicationImpl.SetInstance`
  and return `ApplicationImpl.Instance`.
- Refactored `ApplicationModelFencingTests` to use `Application.Create()`
  and added `ResetModelUsageTracking()` for model switching.
- Removed legacy `DriverTests` and reintroduced updated versions with
  cross-platform driver tests.
- Reverted `ArrangementTests` and `ShortcutTests` to use legacy static
  `ApplicationImpl.Instance`.
- Reintroduced driver tests in `DriverTests.cs` with modern `Application.Create()`
  and added `TestTop` for driver content verification.
- General cleanup, including removal of outdated code and addition of
  `BUGBUG` notes for temporary workarounds.
Tig 3 周之前
父节点
当前提交
ad6925a13a

+ 10 - 8
Terminal.Gui/Drivers/OutputBase.cs

@@ -90,14 +90,16 @@ public abstract class OutputBase
             }
         }
 
-        foreach (SixelToRender s in Application.Sixel)
-        {
-            if (!string.IsNullOrWhiteSpace (s.SixelData))
-            {
-                SetCursorPositionImpl (s.ScreenPosition.X, s.ScreenPosition.Y);
-                Console.Out.Write (s.SixelData);
-            }
-        }
+        // BUGBUG: The Sixel impl depends on the legacy static Application object
+        // BUGBUG: Disabled for now
+        //foreach (SixelToRender s in  Application.Sixel)
+        //{
+        //    if (!string.IsNullOrWhiteSpace (s.SixelData))
+        //    {
+        //        SetCursorPositionImpl (s.ScreenPosition.X, s.ScreenPosition.Y);
+        //        Console.Out.Write (s.SixelData);
+        //    }
+        //}
 
         SetCursorVisibility (savedVisibility ?? CursorVisibility.Default);
         _cachedCursorVisibility = savedVisibility;

+ 2 - 1
Terminal.Gui/Drivers/WindowsDriver/WindowsOutput.cs

@@ -357,7 +357,8 @@ internal partial class WindowsOutput : OutputBase, IOutput
     {
         // BUGBUG: This is bad. It does not work if the app was crated without
         // BUGBUG: Apis.
-        bool force16Colors = ApplicationImpl.Instance.Force16Colors;
+        // bool force16Colors = ApplicationImpl.Instance.Force16Colors;
+        bool force16Colors = false;
 
         if (force16Colors)
         {

+ 3 - 1
Tests/UnitTests/Application/ApplicationImplTests.cs

@@ -27,7 +27,9 @@ public class ApplicationImplTests
         m.Setup (f => f.CreateOutput ()).Returns (consoleOutput.Object);
         m.Setup (f => f.CreateSizeMonitor (It.IsAny<IOutput> (), It.IsAny<IOutputBuffer> ())).Returns (Mock.Of<ISizeMonitor> ());
 
-        return new ApplicationImpl (m.Object);
+        // TODO: Move these tests to Parallelizable tests 
+        ApplicationImpl.SetInstance(new ApplicationImpl (m.Object));
+        return ApplicationImpl.Instance;
     }
 
     [Fact]

+ 11 - 3
Tests/UnitTests/Application/ApplicationModelFencingTests.cs

@@ -17,7 +17,7 @@ public class ApplicationModelFencingTests
     public void Create_ThenInstanceAccess_ThrowsInvalidOperationException ()
     {
         // Create a modern instance-based application
-        IApplication app = ApplicationImpl.Instance; // Force legacy
+        IApplication app = Application.Create ();
         app.Init ("fake");
 
         // Attempting to initialize using the legacy static model should throw
@@ -31,6 +31,8 @@ public class ApplicationModelFencingTests
 
         // Clean up
         app.Shutdown ();
+        ApplicationImpl.ResetModelUsageTracking ();
+
     }
 
     [Fact]
@@ -43,7 +45,7 @@ public class ApplicationModelFencingTests
         // Attempting to create and initialize with modern instance-based model should throw
         InvalidOperationException ex = Assert.Throws<InvalidOperationException> (() =>
         {
-            IApplication app = ApplicationImpl.Instance; // Force legacy
+            IApplication app = Application.Create ();
             app.Init ("fake");
         });
 
@@ -52,6 +54,7 @@ public class ApplicationModelFencingTests
 
         // Clean up
         staticInstance.Shutdown ();
+        ApplicationImpl.ResetModelUsageTracking ();
     }
 
     [Fact]
@@ -72,13 +75,14 @@ public class ApplicationModelFencingTests
 
         // Clean up
         staticInstance.Shutdown ();
+        ApplicationImpl.ResetModelUsageTracking ();
     }
 
     [Fact]
     public void Create_ThenInit_ThrowsInvalidOperationException ()
     {
         // Create a modern instance-based application
-        IApplication app = ApplicationImpl.Instance; // Force legacy
+        IApplication app = Application.Create ();
         app.Init ("fake");
 
         // Attempting to initialize using the legacy static model should throw
@@ -92,6 +96,7 @@ public class ApplicationModelFencingTests
 
         // Clean up
         app.Shutdown ();
+        ApplicationImpl.ResetModelUsageTracking ();
     }
 
     [Fact]
@@ -110,6 +115,7 @@ public class ApplicationModelFencingTests
         app1.Shutdown ();
         app2.Shutdown ();
         app3.Shutdown ();
+        ApplicationImpl.ResetModelUsageTracking ();
     }
 
     [Fact]
@@ -126,6 +132,7 @@ public class ApplicationModelFencingTests
 
         // Clean up
         instance1.Shutdown ();
+        ApplicationImpl.ResetModelUsageTracking ();
     }
 
     [Fact]
@@ -150,5 +157,6 @@ public class ApplicationModelFencingTests
         IApplication app2 = Application.Create ();
         Assert.NotNull (app2);
         app2.Shutdown ();
+        ApplicationImpl.ResetModelUsageTracking ();
     }
 }

+ 0 - 63
Tests/UnitTests/Drivers/DriverTests.cs

@@ -1,63 +0,0 @@
-#nullable enable
-using Xunit.Abstractions;
-
-namespace UnitTests.DriverTests;
-
-public class DriverTests (ITestOutputHelper output)
-{
-    private readonly ITestOutputHelper _output = output;
-
-    [Theory]
-    [InlineData ("fake")]
-    [InlineData ("windows")]
-    [InlineData ("dotnet")]
-    [InlineData ("unix")]
-    public void All_Drivers_Init_Shutdown_Cross_Platform (string driverName)
-    {
-        IApplication? app = Application.Create ();
-        app.Init (driverName);
-        app.Shutdown ();
-    }
-
-    [Theory]
-    [InlineData ("fake")]
-    [InlineData ("windows")]
-    [InlineData ("dotnet")]
-    [InlineData ("unix")]
-    public void All_Drivers_Run_Cross_Platform (string driverName)
-    {
-        IApplication? app = Application.Create ();
-        app.Init (driverName);
-        app.StopAfterFirstIteration = true;
-        app.Run ().Dispose ();
-        app.Shutdown ();
-    }
-
-    [Theory]
-    [InlineData ("fake")]
-    [InlineData ("windows")]
-    [InlineData ("dotnet")]
-    [InlineData ("unix")]
-    public void All_Drivers_LayoutAndDraw_Cross_Platform (string driverName)
-    {
-        IApplication? app = Application.Create ();
-        app.Init (driverName);
-        app.StopAfterFirstIteration = true;
-        app.Run<TestTop> ().Dispose ();
-
-        DriverAssert.AssertDriverContentsWithFrameAre (driverName!, _output, app.Driver);
-
-        app.Shutdown ();
-    }
-}
-
-public class TestTop : Toplevel
-{
-    /// <inheritdoc/>
-    public override void BeginInit ()
-    {
-        Text = Driver!.GetName ()!;
-        BorderStyle = LineStyle.None;
-        base.BeginInit ();
-    }
-}

+ 3 - 3
Tests/UnitTests/View/ArrangementTests.cs

@@ -17,7 +17,7 @@ public class ArrangementTests (ITestOutputHelper output)
             Width = 80,
             Height = 25
         };
-        superView.App = Application.Create ();
+        superView.App = ApplicationImpl.Instance;
 
         var movableView = new View
         {
@@ -82,7 +82,7 @@ public class ArrangementTests (ITestOutputHelper output)
 
         var superView = new View
         {
-            App = Application.Create (),
+            App = ApplicationImpl.Instance,
             Width = 80,
             Height = 25
         };
@@ -148,7 +148,7 @@ public class ArrangementTests (ITestOutputHelper output)
         // This test verifies MouseGrabHandler properly releases when switching between views
 
         var superView = new View { Width = 80, Height = 25 };
-        superView.App = Application.Create ();
+        superView.App = ApplicationImpl.Instance;
 
         var view1 = new View
         {

+ 1 - 1
Tests/UnitTests/Views/ShortcutTests.cs

@@ -349,7 +349,7 @@ public class ShortcutTests
     [InlineData (KeyCode.F1, 0)]
     public void KeyDown_App_Scope_Invokes_Accept (KeyCode key, int expectedAccept)
     {
-        Application.TopRunnable = new () { App = Application.Create () };
+        Application.TopRunnable = new () { App = ApplicationImpl.Instance };
 
         var shortcut = new Shortcut
         {

+ 55 - 1
Tests/UnitTestsParallelizable/Drivers/DriverTests.cs

@@ -3,7 +3,7 @@ using Xunit.Abstractions;
 
 namespace UnitTests_Parallelizable.DriverTests;
 
-public class DriverTests : FakeDriverBase
+public class DriverTests (ITestOutputHelper output) : FakeDriverBase
 {
     [Theory]
     [InlineData (null, true)]
@@ -49,4 +49,58 @@ public class DriverTests : FakeDriverBase
 
         driver.End ();
     }
+
+    [Theory]
+    [InlineData ("fake")]
+    [InlineData ("windows")]
+    [InlineData ("dotnet")]
+    [InlineData ("unix")]
+    public void All_Drivers_Init_Shutdown_Cross_Platform (string driverName)
+    {
+        IApplication? app = Application.Create ();
+        app.Init (driverName);
+        app.Shutdown ();
+    }
+
+    [Theory]
+    [InlineData ("fake")]
+    [InlineData ("windows")]
+    [InlineData ("dotnet")]
+    [InlineData ("unix")]
+    public void All_Drivers_Run_Cross_Platform (string driverName)
+    {
+        IApplication? app = Application.Create ();
+        app.Init (driverName);
+        app.StopAfterFirstIteration = true;
+        app.Run ().Dispose ();
+        app.Shutdown ();
+    }
+
+    [Theory]
+    [InlineData ("fake")]
+    [InlineData ("windows")]
+    [InlineData ("dotnet")]
+    [InlineData ("unix")]
+    public void All_Drivers_LayoutAndDraw_Cross_Platform (string driverName)
+    {
+        IApplication? app = Application.Create ();
+        app.Init (driverName);
+        app.StopAfterFirstIteration = true;
+        app.Run<TestTop> ().Dispose ();
+
+        DriverAssert.AssertDriverContentsWithFrameAre (driverName!, output, app.Driver);
+
+        app.Shutdown ();
+    }
+}
+
+public class TestTop : Toplevel
+{
+    /// <inheritdoc/>
+    public override void BeginInit ()
+    {
+        Text = Driver!.GetName ()!;
+        BorderStyle = LineStyle.None;
+        base.BeginInit ();
+    }
 }