From a04a1988cc0a7d556b72ccaf1a94aca04ccebd75 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 7 Jun 2025 15:30:57 +0100 Subject: [PATCH 01/13] Fixes 4132. .editorconfig has ambiguous configuration with same files --- .editorconfig | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9faacb6d8f..95013c2490 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1881,8 +1881,3 @@ tab_width = 4 indent_style = space indent_size = 2 tab_width = 2 - -[*.{appxmanifest,axaml,axml,build,config,cs,csproj,dbml,discomap,dtd,jsproj,lsproj,njsproj,nuspec,paml,proj,props,resw,resx,StyleCop,targets,tasks,vb,vbproj,xaml,xamlx,xml,xoml,xsd}] -indent_style = space -indent_size = 4 -tab_width = 4 From 0d17f085d960aadd6a123db0aadf7c124db071a0 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 7 Jun 2025 23:30:57 +0100 Subject: [PATCH 02/13] Add UnitTests.AOT project and necessary adjustments --- Terminal.Gui/Terminal.Gui.csproj | 7 +- Terminal.sln | 6 ++ Tests/UnitTests.AOT/UnitTests.AOT.csproj | 96 ++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 Tests/UnitTests.AOT/UnitTests.AOT.csproj diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index 0646dce055..0e1856adee 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -82,6 +82,7 @@ + @@ -162,9 +163,9 @@ --> - - - + + + diff --git a/Terminal.sln b/Terminal.sln index 4c84370978..6a2b839ce1 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -75,6 +75,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerminalGuiFluentTestingXun EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerminalGuiFluentTestingXunit.Generator", "Tests\TerminalGuiFluentTestingXunit.Generator\TerminalGuiFluentTestingXunit.Generator.csproj", "{199F27D8-A905-4DDC-82CA-1FE1A90B1788}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests.AOT", "Tests\UnitTests.AOT\UnitTests.AOT.csproj", "{F9E1362D-29EC-4C77-9E83-BCEA54553CCD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -141,6 +143,10 @@ Global {199F27D8-A905-4DDC-82CA-1FE1A90B1788}.Debug|Any CPU.Build.0 = Debug|Any CPU {199F27D8-A905-4DDC-82CA-1FE1A90B1788}.Release|Any CPU.ActiveCfg = Release|Any CPU {199F27D8-A905-4DDC-82CA-1FE1A90B1788}.Release|Any CPU.Build.0 = Release|Any CPU + {F9E1362D-29EC-4C77-9E83-BCEA54553CCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9E1362D-29EC-4C77-9E83-BCEA54553CCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9E1362D-29EC-4C77-9E83-BCEA54553CCD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9E1362D-29EC-4C77-9E83-BCEA54553CCD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Tests/UnitTests.AOT/UnitTests.AOT.csproj b/Tests/UnitTests.AOT/UnitTests.AOT.csproj new file mode 100644 index 0000000000..58d56dc1d7 --- /dev/null +++ b/Tests/UnitTests.AOT/UnitTests.AOT.csproj @@ -0,0 +1,96 @@ + + + + + + 2.0 + 2.0 + 2.0 + 2.0 + + + false + + true + true + AOT + + true + true + portable + $(DefineConstants);JETBRAINS_ANNOTATIONS;CONTRACTS_FULL + enable + true + true + + + true + $(DefineConstants);DEBUG_IDISPOSABLE + + + true + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + PreserveNewest + + + + + + + + + + False + + + [UICatalog]* + + + + + + + + + + False + + + + + + + + + + + + + + + + + \ No newline at end of file From 3d727a78c1f4b8955064fcb22b7222cbcab28fbd Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 7 Jun 2025 23:31:58 +0100 Subject: [PATCH 03/13] Fix inexistent folder --- Tests/UnitTests/UnitTests.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/UnitTests/UnitTests.csproj b/Tests/UnitTests/UnitTests.csproj index f1558775d2..50eb52466f 100644 --- a/Tests/UnitTests/UnitTests.csproj +++ b/Tests/UnitTests/UnitTests.csproj @@ -57,9 +57,6 @@ - - - False From 2e94f52bb83558d61002eb47751eac55642913b2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 7 Jun 2025 23:33:47 +0100 Subject: [PATCH 04/13] Add more debug properties settings to the NativeAot project --- .../NativeAot/Properties/launchSettings.json | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Examples/NativeAot/Properties/launchSettings.json b/Examples/NativeAot/Properties/launchSettings.json index a7872f0012..de322f52f2 100644 --- a/Examples/NativeAot/Properties/launchSettings.json +++ b/Examples/NativeAot/Properties/launchSettings.json @@ -3,11 +3,35 @@ "NativeAot": { "commandName": "Project" }, + "NativeAot --driver NetDriver": { + "commandName": "Project", + "commandLineArgs": "--driver NetDriver" + }, + "NativeAot --driver v2win": { + "commandName": "Project", + "commandLineArgs": "--driver v2win -dl Trace" + }, + "NativeAot --driver v2net": { + "commandName": "Project", + "commandLineArgs": "--driver v2net -dl Trace" + }, "WSL : NativeAot": { "commandName": "Executable", "executablePath": "wsl", "commandLineArgs": "dotnet NativeAot.dll", "distributionName": "" + }, + "WSL: NativeAot --driver NetDriver": { + "commandName": "Executable", + "executablePath": "wsl", + "commandLineArgs": "dotnet NativeAot.dll --driver NetDriver", + "distributionName": "" + }, + "WSL: NativeAot --driver v2net": { + "commandName": "Executable", + "executablePath": "wsl", + "commandLineArgs": "dotnet NativeAot.dll --driver v2net -dl Trace", + "distributionName": "" } } } \ No newline at end of file From 196712beacfbc2bc640dc69743181a79950009b8 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 8 Jun 2025 00:19:32 +0100 Subject: [PATCH 05/13] Add UnitTests.AOT to the unit-tests.yml --- .github/workflows/unit-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 6fb66961c9..a562562954 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -54,6 +54,10 @@ jobs: # mv -v Tests/UnitTests/TestResults/*/*.* TestResults/UnitTests/ + - name: Run UnitTests.AOT + run: | + dotnet test Tests/UnitTests.AOT --no-build --verbosity normal --collect:"XPlat Code Coverage" --settings Tests/UnitTests.AOT/coverlet.runsettings --diag:logs/UnitTests.AOT/${{ runner.os }}/logs.txt --blame --blame-crash --blame-hang --blame-hang-timeout 60s --blame-crash-collect-always -- xunit.stopOnFail=true + - name: Upload Test Logs if: always() uses: actions/upload-artifact@v4 From afd6cfa0b452e718fb1de9271abd5ab1d63aea05 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 8 Jun 2025 00:34:13 +0100 Subject: [PATCH 06/13] Add coverlet.runsettings file --- Tests/UnitTests.AOT/coverlet.runsettings | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Tests/UnitTests.AOT/coverlet.runsettings diff --git a/Tests/UnitTests.AOT/coverlet.runsettings b/Tests/UnitTests.AOT/coverlet.runsettings new file mode 100644 index 0000000000..fd3b5ceca9 --- /dev/null +++ b/Tests/UnitTests.AOT/coverlet.runsettings @@ -0,0 +1,23 @@ + + + + + + + opencover + [UnitTests]*,[UnitTests.AOT]*,[UICatalog]*,[coverlet.*.tests?]*,[*]Coverlet.Core* + + + + + false + true + true + true + false + TestResults/ + + + + + \ No newline at end of file From c0a68c3847de002d5c24eba6c5e51ccf9b26598e Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 8 Jun 2025 00:40:00 +0100 Subject: [PATCH 07/13] Exclude *.runsettings from link --- Tests/UnitTests.AOT/UnitTests.AOT.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/UnitTests.AOT/UnitTests.AOT.csproj b/Tests/UnitTests.AOT/UnitTests.AOT.csproj index 58d56dc1d7..91aaac6506 100644 --- a/Tests/UnitTests.AOT/UnitTests.AOT.csproj +++ b/Tests/UnitTests.AOT/UnitTests.AOT.csproj @@ -84,7 +84,7 @@ - + From 9b1452c85860fbb4bbd53957d8690ef02f3da73a Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 8 Jun 2025 00:46:38 +0100 Subject: [PATCH 08/13] Add SkipIfAOTFactAttribute class to skip UnitTests.AOT from running Moq unit tests --- .../AnsiRequestSchedulerTests.cs | 14 +++++----- .../ConsoleDrivers/V2/ApplicationV2Tests.cs | 26 +++++++++---------- .../V2/MainLoopCoordinatorTests.cs | 2 +- .../ConsoleDrivers/V2/MainLoopTTests.cs | 2 +- .../V2/WindowSizeMonitorTests.cs | 7 ++--- Tests/UnitTests/SkipIfAOTFactAttribute.cs | 11 ++++++++ .../UnitTests/View/Draw/ClearViewportTests.cs | 10 +++---- 7 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 Tests/UnitTests/SkipIfAOTFactAttribute.cs diff --git a/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs b/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs index 3dcfaeedd7..718827cdf8 100644 --- a/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs @@ -17,7 +17,7 @@ public AnsiRequestSchedulerTests () _scheduler = new AnsiRequestScheduler (_parserMock.Object, () => _staticNow); } - [Fact] + [SkipIfAOTFact] public void SendOrSchedule_SendsDeviceAttributeRequest_WhenNoOutstandingRequests () { // Arrange @@ -43,7 +43,7 @@ public void SendOrSchedule_SendsDeviceAttributeRequest_WhenNoOutstandingRequests Assert.True (result); // Should send immediately _parserMock.Verify (); } - [Fact] + [SkipIfAOTFact] public void SendOrSchedule_QueuesRequest_WhenOutstandingRequestExists () { // Arrange @@ -67,7 +67,7 @@ public void SendOrSchedule_QueuesRequest_WhenOutstandingRequestExists () } - [Fact] + [SkipIfAOTFact] public void RunSchedule_ThrottleNotExceeded_AllowSend () { // Arrange @@ -99,7 +99,7 @@ public void RunSchedule_ThrottleNotExceeded_AllowSend () _parserMock.Verify (); } - [Fact] + [SkipIfAOTFact] public void RunSchedule_ThrottleExceeded_QueueRequest () { // Arrange @@ -145,7 +145,7 @@ public void RunSchedule_ThrottleExceeded_QueueRequest () _parserMock.Verify (); } - [Fact] + [SkipIfAOTFact] public void EvictStaleRequests_RemovesStaleRequest_AfterTimeout () { // Arrange @@ -190,7 +190,7 @@ public void EvictStaleRequests_RemovesStaleRequest_AfterTimeout () _parserMock.Verify (); } - [Fact] + [SkipIfAOTFact] public void RunSchedule_DoesNothing_WhenQueueIsEmpty () { // Act @@ -201,7 +201,7 @@ public void RunSchedule_DoesNothing_WhenQueueIsEmpty () Assert.Empty (_scheduler.QueuedRequests); } - [Fact] + [SkipIfAOTFact] public void SendOrSchedule_ManagesIndependentTerminatorsCorrectly () { // Arrange diff --git a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs index 6fa4c0f1b5..528be6c1b4 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs @@ -22,7 +22,7 @@ private ApplicationV2 NewApplicationV2 () Mock.Of); } - [Fact] + [SkipIfAOTFact] public void Init_CreatesKeybindings () { var orig = ApplicationImpl.Instance; @@ -43,7 +43,7 @@ public void Init_CreatesKeybindings () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void Init_DriverIsFacade () { var orig = ApplicationImpl.Instance; @@ -65,7 +65,7 @@ public void Init_DriverIsFacade () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void Init_ExplicitlyRequestWin () { var orig = ApplicationImpl.Instance; @@ -107,7 +107,7 @@ public void Init_ExplicitlyRequestWin () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void Init_ExplicitlyRequestNet () { var orig = ApplicationImpl.Instance; @@ -192,7 +192,7 @@ public void NoInitThrowOnRun () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void InitRunShutdown_Top_Set_To_Null_After_Shutdown () { var orig = ApplicationImpl.Instance; @@ -231,7 +231,7 @@ public void InitRunShutdown_Top_Set_To_Null_After_Shutdown () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void InitRunShutdown_Running_Set_To_False () { var orig = ApplicationImpl.Instance; @@ -276,7 +276,7 @@ public void InitRunShutdown_Running_Set_To_False () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void InitRunShutdown_End_Is_Called () { var orig = ApplicationImpl.Instance; @@ -341,7 +341,7 @@ public void InitRunShutdown_End_Is_Called () } - [Fact] + [SkipIfAOTFact] public void InitRunShutdown_QuitKey_Quits () { var orig = ApplicationImpl.Instance; @@ -388,7 +388,7 @@ public void InitRunShutdown_QuitKey_Quits () } - [Fact] + [SkipIfAOTFact] public void InitRunShutdown_Generic_IdleForExit () { var orig = ApplicationImpl.Instance; @@ -413,7 +413,7 @@ public void InitRunShutdown_Generic_IdleForExit () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void Shutdown_Closing_Closed_Raised () { var orig = ApplicationImpl.Instance; @@ -471,7 +471,7 @@ private bool IdleExit () return true; } - [Fact] + [SkipIfAOTFact] public void Shutdown_Called_Repeatedly_DoNotDuplicateDisposeOutput () { var orig = ApplicationImpl.Instance; @@ -498,7 +498,7 @@ public void Shutdown_Called_Repeatedly_DoNotDuplicateDisposeOutput () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void Init_Called_Repeatedly_WarnsAndIgnores () { var orig = ApplicationImpl.Instance; @@ -534,7 +534,7 @@ public void Init_Called_Repeatedly_WarnsAndIgnores () ApplicationImpl.ChangeInstance (orig); } - [Fact] + [SkipIfAOTFact] public void Open_Calls_ContinueWith_On_UIThread () { var orig = ApplicationImpl.Instance; diff --git a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs index 4c2a32e6fc..a4d64e0598 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs @@ -5,7 +5,7 @@ namespace UnitTests.ConsoleDrivers.V2; public class MainLoopCoordinatorTests { - [Fact] + [SkipIfAOTFact] public async Task TestMainLoopCoordinator_InputCrashes_ExceptionSurfacesMainThread () { diff --git a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs index 727c105536..e5e213b391 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs @@ -6,7 +6,7 @@ namespace UnitTests.ConsoleDrivers.V2; public class MainLoopTTests { - [Fact] + [SkipIfAOTFact] public void MainLoopT_NotInitialized_Throws() { var m = new MainLoop (); diff --git a/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs index 8b7c7a7b64..81a5ad2543 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs @@ -3,7 +3,7 @@ namespace UnitTests.ConsoleDrivers.V2; public class WindowSizeMonitorTests { - [Fact] + [SkipIfAOTFact] public void TestWindowSizeMonitor_RaisesEventWhenChanges () { var consoleOutput = new Mock (); @@ -37,7 +37,7 @@ public void TestWindowSizeMonitor_RaisesEventWhenChanges () Assert.Equal (new Size (20, 20), result [1].Size); } - [Fact] + [SkipIfAOTFact] public void TestWindowSizeMonitor_DoesNotRaiseEventWhen_NoChanges () { var consoleOutput = new Mock (); @@ -70,7 +70,4 @@ public void TestWindowSizeMonitor_DoesNotRaiseEventWhen_NoChanges () Assert.Single (result); Assert.Equal (new Size (30, 20), result [0].Size); } - - - } diff --git a/Tests/UnitTests/SkipIfAOTFactAttribute.cs b/Tests/UnitTests/SkipIfAOTFactAttribute.cs new file mode 100644 index 0000000000..98b15385e4 --- /dev/null +++ b/Tests/UnitTests/SkipIfAOTFactAttribute.cs @@ -0,0 +1,11 @@ +namespace UnitTests; + +public class SkipIfAOTFactAttribute : FactAttribute +{ + public SkipIfAOTFactAttribute () + { +#if AOT + Skip = "Test skipped in AOT project due to Moq incompatibility."; +#endif + } +} diff --git a/Tests/UnitTests/View/Draw/ClearViewportTests.cs b/Tests/UnitTests/View/Draw/ClearViewportTests.cs index 5aa69954fe..e140e8eb1b 100644 --- a/Tests/UnitTests/View/Draw/ClearViewportTests.cs +++ b/Tests/UnitTests/View/Draw/ClearViewportTests.cs @@ -26,7 +26,7 @@ protected override bool OnClearingViewport () protected override void OnClearedViewport () { OnClearedViewportCalled++; } } - [Fact] + [SkipIfAOTFact] public void DoClearViewport_ViewportIsTransparent_DoesNotClear () { // Arrange @@ -41,7 +41,7 @@ public void DoClearViewport_ViewportIsTransparent_DoesNotClear () Assert.Equal (0, view.Object.OnClearedViewportCalled); } - [Fact] + [SkipIfAOTFact] public void DoClearViewport_OnClearingViewportReturnsTrue_DoesNotClear () { // Arrange @@ -55,7 +55,7 @@ public void DoClearViewport_OnClearingViewportReturnsTrue_DoesNotClear () Assert.Equal (0, view.Object.OnClearedViewportCalled); } - [Fact] + [SkipIfAOTFact] public void DoClearViewport_ClearingViewportEventCancelled_DoesNotClear () { // Arrange @@ -69,7 +69,7 @@ public void DoClearViewport_ClearingViewportEventCancelled_DoesNotClear () Assert.Equal (0, view.Object.OnClearedViewportCalled); } - [Fact] + [SkipIfAOTFact] public void DoClearViewport_ClearsViewport () { // Arrange @@ -82,7 +82,7 @@ public void DoClearViewport_ClearsViewport () Assert.Equal (1, view.Object.OnClearedViewportCalled); } - [Fact] + [SkipIfAOTFact] public void DoClearViewport_RaisesClearingViewportEvent () { // Arrange From 7c626969a83b6ac04a9e687c39e6c1eee3fb8c68 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 8 Jun 2025 01:05:07 +0100 Subject: [PATCH 09/13] Changing something to re-run got actions --- Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs index 528be6c1b4..01dbcb6c1c 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs @@ -7,7 +7,6 @@ namespace UnitTests.ConsoleDrivers.V2; public class ApplicationV2Tests { - private ApplicationV2 NewApplicationV2 () { var netInput = new Mock (); @@ -161,6 +160,7 @@ private void SetupRunInputMockMethodToBlock (Mock winInput) }) .Verifiable (Times.Once); } + private void SetupRunInputMockMethodToBlock (Mock netInput) { netInput.Setup (r => r.Run (It.IsAny ())) @@ -340,7 +340,6 @@ public void InitRunShutdown_End_Is_Called () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] public void InitRunShutdown_QuitKey_Quits () { @@ -387,7 +386,6 @@ public void InitRunShutdown_QuitKey_Quits () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] public void InitRunShutdown_Generic_IdleForExit () { From 7f070a70b9e3ee9b7ad3d81367933d917a2c6c8d Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 9 Jun 2025 14:53:16 -0600 Subject: [PATCH 10/13] Tweaked FactSkipIfAOTAttribute --- Terminal.sln.DotSettings | 1 + .../AnsiRequestSchedulerTests.cs | 14 +++++----- .../ConsoleDrivers/V2/ApplicationV2Tests.cs | 26 +++++++++---------- .../V2/MainLoopCoordinatorTests.cs | 2 +- .../ConsoleDrivers/V2/MainLoopTTests.cs | 2 +- .../V2/WindowSizeMonitorTests.cs | 4 +-- Tests/UnitTests/FactSkipIfAOTAttribute.cs | 17 ++++++++++++ Tests/UnitTests/SkipIfAOTFactAttribute.cs | 11 -------- .../UnitTests/View/Draw/ClearViewportTests.cs | 10 +++---- 9 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 Tests/UnitTests/FactSkipIfAOTAttribute.cs delete mode 100644 Tests/UnitTests/SkipIfAOTFactAttribute.cs diff --git a/Terminal.sln.DotSettings b/Terminal.sln.DotSettings index fd588071f4..007e4c6a38 100644 --- a/Terminal.sln.DotSettings +++ b/Terminal.sln.DotSettings @@ -381,6 +381,7 @@ False True True + AOT CWP LL LR diff --git a/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs b/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs index 718827cdf8..265644c27d 100644 --- a/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/AnsiRequestSchedulerTests.cs @@ -17,7 +17,7 @@ public AnsiRequestSchedulerTests () _scheduler = new AnsiRequestScheduler (_parserMock.Object, () => _staticNow); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void SendOrSchedule_SendsDeviceAttributeRequest_WhenNoOutstandingRequests () { // Arrange @@ -43,7 +43,7 @@ public void SendOrSchedule_SendsDeviceAttributeRequest_WhenNoOutstandingRequests Assert.True (result); // Should send immediately _parserMock.Verify (); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void SendOrSchedule_QueuesRequest_WhenOutstandingRequestExists () { // Arrange @@ -67,7 +67,7 @@ public void SendOrSchedule_QueuesRequest_WhenOutstandingRequestExists () } - [SkipIfAOTFact] + [FactSkipIfAOT] public void RunSchedule_ThrottleNotExceeded_AllowSend () { // Arrange @@ -99,7 +99,7 @@ public void RunSchedule_ThrottleNotExceeded_AllowSend () _parserMock.Verify (); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void RunSchedule_ThrottleExceeded_QueueRequest () { // Arrange @@ -145,7 +145,7 @@ public void RunSchedule_ThrottleExceeded_QueueRequest () _parserMock.Verify (); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void EvictStaleRequests_RemovesStaleRequest_AfterTimeout () { // Arrange @@ -190,7 +190,7 @@ public void EvictStaleRequests_RemovesStaleRequest_AfterTimeout () _parserMock.Verify (); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void RunSchedule_DoesNothing_WhenQueueIsEmpty () { // Act @@ -201,7 +201,7 @@ public void RunSchedule_DoesNothing_WhenQueueIsEmpty () Assert.Empty (_scheduler.QueuedRequests); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void SendOrSchedule_ManagesIndependentTerminatorsCorrectly () { // Arrange diff --git a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs index 01dbcb6c1c..83d24b4cc6 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/ApplicationV2Tests.cs @@ -21,7 +21,7 @@ private ApplicationV2 NewApplicationV2 () Mock.Of); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Init_CreatesKeybindings () { var orig = ApplicationImpl.Instance; @@ -42,7 +42,7 @@ public void Init_CreatesKeybindings () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Init_DriverIsFacade () { var orig = ApplicationImpl.Instance; @@ -64,7 +64,7 @@ public void Init_DriverIsFacade () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Init_ExplicitlyRequestWin () { var orig = ApplicationImpl.Instance; @@ -106,7 +106,7 @@ public void Init_ExplicitlyRequestWin () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Init_ExplicitlyRequestNet () { var orig = ApplicationImpl.Instance; @@ -192,7 +192,7 @@ public void NoInitThrowOnRun () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void InitRunShutdown_Top_Set_To_Null_After_Shutdown () { var orig = ApplicationImpl.Instance; @@ -231,7 +231,7 @@ public void InitRunShutdown_Top_Set_To_Null_After_Shutdown () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void InitRunShutdown_Running_Set_To_False () { var orig = ApplicationImpl.Instance; @@ -276,7 +276,7 @@ public void InitRunShutdown_Running_Set_To_False () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void InitRunShutdown_End_Is_Called () { var orig = ApplicationImpl.Instance; @@ -340,7 +340,7 @@ public void InitRunShutdown_End_Is_Called () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void InitRunShutdown_QuitKey_Quits () { var orig = ApplicationImpl.Instance; @@ -386,7 +386,7 @@ public void InitRunShutdown_QuitKey_Quits () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void InitRunShutdown_Generic_IdleForExit () { var orig = ApplicationImpl.Instance; @@ -411,7 +411,7 @@ public void InitRunShutdown_Generic_IdleForExit () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Shutdown_Closing_Closed_Raised () { var orig = ApplicationImpl.Instance; @@ -469,7 +469,7 @@ private bool IdleExit () return true; } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Shutdown_Called_Repeatedly_DoNotDuplicateDisposeOutput () { var orig = ApplicationImpl.Instance; @@ -496,7 +496,7 @@ public void Shutdown_Called_Repeatedly_DoNotDuplicateDisposeOutput () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Init_Called_Repeatedly_WarnsAndIgnores () { var orig = ApplicationImpl.Instance; @@ -532,7 +532,7 @@ public void Init_Called_Repeatedly_WarnsAndIgnores () ApplicationImpl.ChangeInstance (orig); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void Open_Calls_ContinueWith_On_UIThread () { var orig = ApplicationImpl.Instance; diff --git a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs index a4d64e0598..982be02d91 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopCoordinatorTests.cs @@ -5,7 +5,7 @@ namespace UnitTests.ConsoleDrivers.V2; public class MainLoopCoordinatorTests { - [SkipIfAOTFact] + [FactSkipIfAOT] public async Task TestMainLoopCoordinator_InputCrashes_ExceptionSurfacesMainThread () { diff --git a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs index e5e213b391..7f6eb59d56 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/MainLoopTTests.cs @@ -6,7 +6,7 @@ namespace UnitTests.ConsoleDrivers.V2; public class MainLoopTTests { - [SkipIfAOTFact] + [FactSkipIfAOT] public void MainLoopT_NotInitialized_Throws() { var m = new MainLoop (); diff --git a/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs index 81a5ad2543..fd8f40bb85 100644 --- a/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs @@ -3,7 +3,7 @@ namespace UnitTests.ConsoleDrivers.V2; public class WindowSizeMonitorTests { - [SkipIfAOTFact] + [FactSkipIfAOT] public void TestWindowSizeMonitor_RaisesEventWhenChanges () { var consoleOutput = new Mock (); @@ -37,7 +37,7 @@ public void TestWindowSizeMonitor_RaisesEventWhenChanges () Assert.Equal (new Size (20, 20), result [1].Size); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void TestWindowSizeMonitor_DoesNotRaiseEventWhen_NoChanges () { var consoleOutput = new Mock (); diff --git a/Tests/UnitTests/FactSkipIfAOTAttribute.cs b/Tests/UnitTests/FactSkipIfAOTAttribute.cs new file mode 100644 index 0000000000..df7d6ad995 --- /dev/null +++ b/Tests/UnitTests/FactSkipIfAOTAttribute.cs @@ -0,0 +1,17 @@ +namespace UnitTests; + +public class FactSkipIfAOTAttribute : FactAttribute +{ + public FactSkipIfAOTAttribute () + { + if (IsAOTEnvironment ()) + { + base.Skip = "Test skipped in AOT project due to Moq incompatibility."; + } + } + + private static bool IsAOTEnvironment () + { + return Type.GetType ("System.Runtime.CompilerServices.RuntimeFeature")?.GetProperty ("IsDynamicCodeSupported")?.GetValue (null) is bool and false; + } +} diff --git a/Tests/UnitTests/SkipIfAOTFactAttribute.cs b/Tests/UnitTests/SkipIfAOTFactAttribute.cs deleted file mode 100644 index 98b15385e4..0000000000 --- a/Tests/UnitTests/SkipIfAOTFactAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace UnitTests; - -public class SkipIfAOTFactAttribute : FactAttribute -{ - public SkipIfAOTFactAttribute () - { -#if AOT - Skip = "Test skipped in AOT project due to Moq incompatibility."; -#endif - } -} diff --git a/Tests/UnitTests/View/Draw/ClearViewportTests.cs b/Tests/UnitTests/View/Draw/ClearViewportTests.cs index e140e8eb1b..3180b55ccf 100644 --- a/Tests/UnitTests/View/Draw/ClearViewportTests.cs +++ b/Tests/UnitTests/View/Draw/ClearViewportTests.cs @@ -26,7 +26,7 @@ protected override bool OnClearingViewport () protected override void OnClearedViewport () { OnClearedViewportCalled++; } } - [SkipIfAOTFact] + [FactSkipIfAOT] public void DoClearViewport_ViewportIsTransparent_DoesNotClear () { // Arrange @@ -41,7 +41,7 @@ public void DoClearViewport_ViewportIsTransparent_DoesNotClear () Assert.Equal (0, view.Object.OnClearedViewportCalled); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void DoClearViewport_OnClearingViewportReturnsTrue_DoesNotClear () { // Arrange @@ -55,7 +55,7 @@ public void DoClearViewport_OnClearingViewportReturnsTrue_DoesNotClear () Assert.Equal (0, view.Object.OnClearedViewportCalled); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void DoClearViewport_ClearingViewportEventCancelled_DoesNotClear () { // Arrange @@ -69,7 +69,7 @@ public void DoClearViewport_ClearingViewportEventCancelled_DoesNotClear () Assert.Equal (0, view.Object.OnClearedViewportCalled); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void DoClearViewport_ClearsViewport () { // Arrange @@ -82,7 +82,7 @@ public void DoClearViewport_ClearsViewport () Assert.Equal (1, view.Object.OnClearedViewportCalled); } - [SkipIfAOTFact] + [FactSkipIfAOT] public void DoClearViewport_RaisesClearingViewportEvent () { // Arrange From 025ec91a241d884d8aa105b93be20996c1971371 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 11 Jun 2025 11:21:42 +0100 Subject: [PATCH 11/13] Fixes #4143. ReactiveExample throw System.NotSupportedException: 'Index expressions are only supported with constants.' --- Examples/ReactiveExample/LoginView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/ReactiveExample/LoginView.cs b/Examples/ReactiveExample/LoginView.cs index 8cb97cb890..0eb5e7a345 100644 --- a/Examples/ReactiveExample/LoginView.cs +++ b/Examples/ReactiveExample/LoginView.cs @@ -100,7 +100,7 @@ public LoginView (LoginViewModel viewModel) ViewModel .WhenAnyValue (x => x.IsValid) .Select (valid => valid ? SchemeManager.GetScheme ("Base") : SchemeManager.GetScheme ("Error")) - .BindTo (validation, x => x.GetScheme ()) + .Subscribe (scheme => validation.SetScheme (scheme)) .DisposeWith (_disposable); }) .AddControlAfter