diff --git a/Scripts/Terminal.Gui.PowerShell.Analyzers.psd1 b/Scripts/Terminal.Gui.PowerShell.Analyzers.psd1 index b5eced04c..c94a3e242 100644 --- a/Scripts/Terminal.Gui.PowerShell.Analyzers.psd1 +++ b/Scripts/Terminal.Gui.PowerShell.Analyzers.psd1 @@ -42,7 +42,7 @@ PowerShellHostName = 'ConsoleHost' # PowerShellHostVersion = '' # Processor architecture (None, X86, Amd64) required by this module -ProcessorArchitecture = 'Amd64' +ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @('Microsoft.PowerShell.Management','Microsoft.PowerShell.Utility','./Terminal.Gui.PowerShell.Core.psd1') diff --git a/Scripts/Terminal.Gui.PowerShell.Build.psd1 b/Scripts/Terminal.Gui.PowerShell.Build.psd1 index 9f367487a..97395c3a8 100644 --- a/Scripts/Terminal.Gui.PowerShell.Build.psd1 +++ b/Scripts/Terminal.Gui.PowerShell.Build.psd1 @@ -36,7 +36,7 @@ PowerShellHostVersion = '7.4.0' # Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only. # Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else. # Has nothing to do with runtime use of Terminal.Gui. -ProcessorArchitecture = 'Amd64' +ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( diff --git a/Scripts/Terminal.Gui.PowerShell.Core.psd1 b/Scripts/Terminal.Gui.PowerShell.Core.psd1 index 302005999..541265ee8 100644 --- a/Scripts/Terminal.Gui.PowerShell.Core.psd1 +++ b/Scripts/Terminal.Gui.PowerShell.Core.psd1 @@ -44,7 +44,7 @@ PowerShellHostVersion = '7.4.0' # Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only. # Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else. # Has nothing to do with runtime use of Terminal.Gui. -ProcessorArchitecture = 'Amd64' +ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( diff --git a/Scripts/Terminal.Gui.PowerShell.Git.psd1 b/Scripts/Terminal.Gui.PowerShell.Git.psd1 index 1bfcd58a1..afca6f69b 100644 --- a/Scripts/Terminal.Gui.PowerShell.Git.psd1 +++ b/Scripts/Terminal.Gui.PowerShell.Git.psd1 @@ -44,7 +44,7 @@ PowerShellHostVersion = '7.4.0' # Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only. # Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else. # Has nothing to do with runtime use of Terminal.Gui. -ProcessorArchitecture = 'AMD64' +ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( diff --git a/Scripts/Terminal.Gui.PowerShell.psd1 b/Scripts/Terminal.Gui.PowerShell.psd1 index d90db54d9..ca182f375 100644 --- a/Scripts/Terminal.Gui.PowerShell.psd1 +++ b/Scripts/Terminal.Gui.PowerShell.psd1 @@ -49,7 +49,7 @@ PowerShellHostVersion = '7.4.0' # Processor architecture (None, MSIL, X86, IA64, Amd64, Arm, or an empty string) required by this module. One value only. # Set to AMD64 here because development on Terminal.Gui isn't really supported on anything else. # Has nothing to do with runtime use of Terminal.Gui. -ProcessorArchitecture = 'Amd64' +ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @( diff --git a/UnitTests/Application/MainLoopTests.cs b/UnitTests/Application/MainLoopTests.cs index 99c61e263..5fdc874b5 100644 --- a/UnitTests/Application/MainLoopTests.cs +++ b/UnitTests/Application/MainLoopTests.cs @@ -620,9 +620,9 @@ public class MainLoopTests } [Fact] - [AutoInitShutdown] public async Task InvokeLeakTest () { + Application.Init (); Random r = new (); TextField tf = new (); var top = new Toplevel (); @@ -641,10 +641,10 @@ public class MainLoopTests Assert.Equal (numIncrements * numPasses, tbCounter); top.Dispose (); + Application.Shutdown (); } [Theory] - [AutoInitShutdown] [MemberData (nameof (TestAddIdle))] public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions ( Action action, @@ -658,6 +658,8 @@ public class MainLoopTests int pfour ) { + Application.Init (); + total = 0; btn = null; clickMe = pclickMe; @@ -720,6 +722,8 @@ public class MainLoopTests Assert.True (taskCompleted); Assert.Equal (clickMe, btn.Text); Assert.Equal (four, total); + + Application.Shutdown (); } [Fact] diff --git a/UnitTests/Application/SynchronizatonContextTests.cs b/UnitTests/Application/SynchronizatonContextTests.cs index 3e7635580..b5a34976f 100644 --- a/UnitTests/Application/SynchronizatonContextTests.cs +++ b/UnitTests/Application/SynchronizatonContextTests.cs @@ -5,9 +5,9 @@ namespace Terminal.Gui.ApplicationTests; public class SyncrhonizationContextTests { [Fact] - [AutoInitShutdown] public void SynchronizationContext_CreateCopy () { + Application.Init (); SynchronizationContext context = SynchronizationContext.Current; Assert.NotNull (context); @@ -15,12 +15,13 @@ public class SyncrhonizationContextTests Assert.NotNull (contextCopy); Assert.NotEqual (context, contextCopy); + Application.Shutdown (); } [Fact] - [AutoInitShutdown] public void SynchronizationContext_Post () { + Application.Init (); SynchronizationContext context = SynchronizationContext.Current; var success = false; @@ -48,12 +49,14 @@ public class SyncrhonizationContextTests // blocks here until the RequestStop is processed at the end of the test Application.Run ().Dispose (); Assert.True (success); + Application.Shutdown (); } [Fact] [AutoInitShutdown] public void SynchronizationContext_Send () { + Application.Init (); SynchronizationContext context = SynchronizationContext.Current; var success = false; @@ -81,5 +84,6 @@ public class SyncrhonizationContextTests // blocks here until the RequestStop is processed at the end of the test Application.Run ().Dispose (); Assert.True (success); + Application.Shutdown (); } } diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 015707cdc..20c855315 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -23,6 +23,7 @@ public class ScenarioTests : TestsAllViews .Where (type => type.IsClass && !type.IsAbstract && type.IsSubclassOf (typeof (Scenario))) .Select (type => new object [] { type }); + private readonly object _timeoutLock = new object (); /// /// This runs through all Scenarios defined in UI Catalog, calling Init, Setup, and Run. @@ -32,61 +33,72 @@ public class ScenarioTests : TestsAllViews [MemberData (nameof (AllScenarioTypes))] public void All_Scenarios_Quit_And_Init_Shutdown_Properly (Type scenarioType) { + // If a previous test failed, this will ensure that the Application is in a clean state Application.ResetState (true); _output.WriteLine ($"Running Scenario '{scenarioType}'"); - Scenario scenario = (Scenario)Activator.CreateInstance (scenarioType); uint abortTime = 500; - bool initialized = false; bool shutdown = false; - object timeout = null; - Application.InitializedChanged += (s, a) => - { - if (a.NewValue) - { - //output.WriteLine ($" Add timeout to force quit after {abortTime}ms"); - timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback); + void OnApplicationOnInitializedChanged (object s, StateEventArgs a) + { + if (a.NewValue) + { + lock (_timeoutLock) + { + timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback); + } - Application.Iteration += OnApplicationOnIteration; - initialized = true; - } - else - { - if (timeout is { }) - { - Application.RemoveTimeout (timeout); - timeout = null; - } - Application.Iteration -= OnApplicationOnIteration; - shutdown = true; - } - }; + Application.Iteration += OnApplicationOnIteration; + initialized = true; + } + else + { + Application.Iteration -= OnApplicationOnIteration; + shutdown = true; + } + } + + Application.InitializedChanged += OnApplicationOnInitializedChanged; scenario.Main (); scenario.Dispose (); scenario = null; + Application.InitializedChanged -= OnApplicationOnInitializedChanged; + + lock (_timeoutLock) + { + if (timeout is { }) + { + Application.RemoveTimeout (timeout); + timeout = null; + } + } + + Assert.True (initialized); Assert.True (shutdown); #if DEBUG_IDISPOSABLE Assert.Empty (Responder.Instances); #endif - Application.Shutdown (); return; // If the scenario doesn't close within 500ms, this will force it to quit bool ForceCloseCallback () { - if (timeout is { }) + lock (_timeoutLock) { - Application.RemoveTimeout (timeout); - timeout = null; + if (timeout is { }) + { + Application.RemoveTimeout (timeout); + timeout = null; + } } Application.ResetState (true); Assert.Fail ( @@ -97,7 +109,7 @@ public class ScenarioTests : TestsAllViews void OnApplicationOnIteration (object s, IterationEventArgs a) { - if (scenario is { }) + if (Application._initialized) { // Press QuitKey Application.OnKeyDown (Application.QuitKey);