From 3307e84e3aa4255ff2c58d3f8d6b761e5ed41c1a Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 5 Dec 2022 20:18:17 -0700 Subject: [PATCH] Support unittest with Release Builds --- Terminal.Gui/Terminal.Gui.csproj | 9 ++++----- UnitTests/ApplicationTests.cs | 5 ++++- UnitTests/MdiTests.cs | 5 ++++- UnitTests/RunStateTests.cs | 9 ++++++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index 4cbb36d5c..1c16d17f5 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -10,14 +10,13 @@ - 1.0 - 1.0 - 1.0 - 1.0 + 1.9 + 1.9 + 1.9 - + diff --git a/UnitTests/ApplicationTests.cs b/UnitTests/ApplicationTests.cs index 918ef1319..b9bc4101c 100644 --- a/UnitTests/ApplicationTests.cs +++ b/UnitTests/ApplicationTests.cs @@ -75,13 +75,14 @@ namespace Terminal.Gui.Core { // Verify state is back to initial Pre_Init_State (); - +#if DEBUG_IDISPOSABLE // Validate there are no outstanding Responder-based instances // after a scenario was selected to run. This proves the main UI Catalog // 'app' closed cleanly. foreach (var inst in Responder.Instances) { Assert.True (inst.WasDisposed); } +#endif } [Fact] @@ -91,8 +92,10 @@ namespace Terminal.Gui.Core { Application.Shutdown (); +#if DEBUG_IDISPOSABLE Assert.Single (Responder.Instances); Assert.True (Responder.Instances [0].WasDisposed); +#endif } [Fact] diff --git a/UnitTests/MdiTests.cs b/UnitTests/MdiTests.cs index d10af4a3b..83860bf36 100644 --- a/UnitTests/MdiTests.cs +++ b/UnitTests/MdiTests.cs @@ -30,9 +30,11 @@ namespace Terminal.Gui.Core { Application.Shutdown (); +#if DEBUG_IDISPOSABLE Assert.Equal (2, Responder.Instances.Count); Assert.True (Responder.Instances [0].WasDisposed); Assert.True (Responder.Instances [1].WasDisposed); +#endif } [Fact] @@ -45,10 +47,11 @@ namespace Terminal.Gui.Core { Application.End (rs); Application.Shutdown (); - +#if DEBUG_IDISPOSABLE Assert.Equal (2, Responder.Instances.Count); Assert.True (Responder.Instances [0].WasDisposed); Assert.True (Responder.Instances [1].WasDisposed); +#endif } [Fact, AutoInitShutdown] diff --git a/UnitTests/RunStateTests.cs b/UnitTests/RunStateTests.cs index 514ef05d5..501525ecd 100644 --- a/UnitTests/RunStateTests.cs +++ b/UnitTests/RunStateTests.cs @@ -40,8 +40,9 @@ namespace Terminal.Gui.Core { // Should not throw because Toplevel was null rs.Dispose (); +#if DEBUG_IDISPOSABLE Assert.True (rs.WasDisposed); - +#endif var top = new Toplevel (); rs = new Application.RunState (top); Assert.NotNull (rs); @@ -52,8 +53,10 @@ namespace Terminal.Gui.Core { rs.Toplevel.Dispose (); rs.Toplevel = null; rs.Dispose (); +#if DEBUG_IDISPOSABLE Assert.True (rs.WasDisposed); Assert.True (top.WasDisposed); +#endif } void Init () @@ -67,10 +70,12 @@ namespace Terminal.Gui.Core { void Shutdown () { Application.Shutdown (); +#if DEBUG_IDISPOSABLE // Validate there are no outstanding RunState-based instances left foreach (var inst in Application.RunState.Instances) { Assert.True (inst.WasDisposed); } +#endif } [Fact] @@ -95,7 +100,9 @@ namespace Terminal.Gui.Core { Shutdown (); +#if DEBUG_IDISPOSABLE Assert.True (rs.WasDisposed); +#endif Assert.Null (Application.Top); Assert.Null (Application.MainLoop);