diff --git a/Terminal.Gui/Application/Application.Initialization.cs b/Terminal.Gui/Application/Application.Initialization.cs index caf1ff28c..62822f3c2 100644 --- a/Terminal.Gui/Application/Application.Initialization.cs +++ b/Terminal.Gui/Application/Application.Initialization.cs @@ -1,4 +1,5 @@ #nullable enable +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Reflection; @@ -80,6 +81,16 @@ public static partial class Application // Initialization (Init/Shutdown) if (driver is { }) { Driver = driver; + + if (driver is FakeDriver) + { + // We're running unit tests. Disable loading config files other than default + if (Locations == ConfigLocations.All) + { + Locations = ConfigLocations.DefaultOnly; + Reset (); + } + } } // Start the process of configuration management. diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 70232faf5..74d915d06 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -65,7 +65,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute _verifyShutdown = verifyShutdown; } - private bool _verifyShutdown; + private readonly bool _verifyShutdown; private readonly Type _driverType; public override void After (MethodInfo methodUnderTest) @@ -114,7 +114,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute Reset(); // Enable subsequent tests that call Init to get all config files (the default). - Locations = ConfigLocations.All; + //Locations = ConfigLocations.All; } public override void Before (MethodInfo methodUnderTest) @@ -161,9 +161,6 @@ public class TestRespondersDisposed : BeforeAfterTestAttribute Debug.WriteLine ($"After: {methodUnderTest.Name}"); base.After (methodUnderTest); - // Reset the to default All - Locations = ConfigLocations.All; - #if DEBUG_IDISPOSABLE Assert.Empty (Responder.Instances); #endif @@ -173,10 +170,6 @@ public class TestRespondersDisposed : BeforeAfterTestAttribute { Debug.WriteLine ($"Before: {methodUnderTest.Name}"); - // Force the use of the default config file - Locations = ConfigLocations.DefaultOnly; - Reset (); - base.Before (methodUnderTest); #if DEBUG_IDISPOSABLE @@ -208,19 +201,12 @@ public class SetupFakeDriverAttribute : BeforeAfterTestAttribute Application.Driver = null; base.After (methodUnderTest); - - // Reset the to default All - Locations = ConfigLocations.All; } public override void Before (MethodInfo methodUnderTest) { Debug.WriteLine ($"Before: {methodUnderTest.Name}"); - // Force the use of the default config file - Locations = ConfigLocations.DefaultOnly; - Reset (); - Application.ResetState (true); Assert.Null (Application.Driver); Application.Driver = new FakeDriver { Rows = 25, Cols = 25 }; diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index d56550b35..660434b66 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -1318,6 +1318,9 @@ public class TabViewTests (ITestOutputHelper output) private void InitFakeDriver () { + ConfigurationManager.Locations = ConfigurationManager.ConfigLocations.DefaultOnly; + ConfigurationManager.Reset (); + var driver = new FakeDriver (); Application.Init (driver); driver.Init (); diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index 350b93706..6bb982988 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -54,7 +54,7 @@ public class TableViewTests (ITestOutputHelper output) } [Fact] - [AutoInitShutdown] + [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)] public void CellEventsBackgroundFill () { var tv = new TableView { Width = 20, Height = 4 }; @@ -412,7 +412,7 @@ public class TableViewTests (ITestOutputHelper output) } [Fact] - [AutoInitShutdown] + [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)] public void LongColumnTest () { var tableView = new TableView (); @@ -602,7 +602,7 @@ public class TableViewTests (ITestOutputHelper output) top.Dispose (); } - [AutoInitShutdown] + [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)] [Fact] public void PageDown_ExcludesHeaders () { @@ -1000,7 +1000,7 @@ public class TableViewTests (ITestOutputHelper output) } [Fact] - [AutoInitShutdown] + [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)] public void TableView_Activate () { string activatedValue = null; @@ -1566,7 +1566,7 @@ public class TableViewTests (ITestOutputHelper output) } [Fact] - [AutoInitShutdown] + [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)] public void Test_CollectionNavigator () { var tv = new TableView ();