Răsfoiți Sursa

Merge branch 'v2_develop' into copilot/port-parallelizable-unit-tests

Tig 1 lună în urmă
părinte
comite
ebe2080346

+ 17 - 0
Terminal.Gui/App/ApplicationImpl.cs

@@ -103,6 +103,23 @@ public class ApplicationImpl : IApplication
 
     private void CreateDriver (string? driverName)
     {
+        // When running unit tests, always use FakeDriver unless explicitly specified
+        if (ConsoleDriver.RunningUnitTests && 
+            string.IsNullOrEmpty (driverName) && 
+            _componentFactory is null)
+        {
+            Logging.Logger.LogDebug ("Unit test safeguard: forcing FakeDriver (RunningUnitTests=true, driverName=null, componentFactory=null)");
+            _coordinator = CreateSubcomponents (() => new FakeComponentFactory ());
+            _coordinator.StartAsync ().Wait ();
+
+            if (Application.Driver == null)
+            {
+                throw new ("Application.Driver was null even after booting MainLoopCoordinator");
+            }
+
+            return;
+        }
+
         PlatformID p = Environment.OSVersion.Platform;
 
         // Check component factory type first - this takes precedence over driverName

+ 26 - 0
Tests/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs

@@ -230,4 +230,30 @@ public class ConsoleDriverTests
     //
     // [Fact]
     // public void FakeDriver_IsValidInput_Correct_Surrogate_Sequence ()
+
+    /// <summary>
+    /// Tests that when ConsoleDriver.RunningUnitTests is true, Application.Init() without
+    /// parameters uses FakeDriver instead of platform-specific drivers.
+    /// This prevents intermittent failures on macOS where kernel32.dll might be referenced.
+    /// </summary>
+    [Fact]
+    public void Application_Init_Without_Params_Uses_FakeDriver_When_RunningUnitTests ()
+    {
+        // Arrange
+        ConsoleDriver.RunningUnitTests = true;
+        Application.ResetState (true);
+
+        // Act
+        Application.Init ();
+
+        // Assert
+        Assert.NotNull (Application.Driver);
+        // In the modern v2 architecture, the driver will be a ConsoleDriverFacade wrapping FakeDriver
+        // The key is that it's not attempting to use Windows/Unix platform-specific drivers
+        Assert.True (Application.Initialized);
+
+        // Cleanup
+        Application.Shutdown ();
+        Application.ResetState (true);
+    }
 }