Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a continue-on-unload-error option #308

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/NUnitConsole/nunit3-console/ConsoleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class ConsoleOptions : CommandLineOptions
public string DomainUsage { get; private set; }
public bool DomainUsageSpecified { get { return DomainUsage != null; } }

public bool ContinueOnUnloadError { get; private set; }

// How to Run Tests

public string Framework { get; private set; }
Expand Down Expand Up @@ -160,6 +162,9 @@ protected override void ConfigureOptions()
this.Add("pause", "Pause before running to allow attaching a debugger.",
v => PauseBeforeRun = v != null);

this.Add("continue-on-unload-error", "Continue if unload errors happen.",
v => ContinueOnUnloadError = v != null);

this.Add("list-extensions", "List all extension points and the extensions for each.",
v => ListExtensions = v != null);

Expand Down
11 changes: 7 additions & 4 deletions src/NUnitConsole/nunit3-console/ConsoleRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down Expand Up @@ -287,8 +287,8 @@ private static string GetOSVersion()
var unixVariant = Marshal.PtrToStringAnsi(buf);
if (unixVariant.Equals("Darwin"))
unixVariant = "MacOSX";
osString = string.Format("{0} {1} {2}", unixVariant, os.Version, os.ServicePack);

osString = string.Format("{0} {1} {2}", unixVariant, os.Version, os.ServicePack);
}
Marshal.FreeHGlobal(buf);
}
Expand Down Expand Up @@ -386,6 +386,9 @@ public static TestPackage MakeTestPackage(ConsoleOptions options)
if (options.DomainUsageSpecified)
package.AddSetting(EnginePackageSettings.DomainUsage, options.DomainUsage);

if (options.ContinueOnUnloadError)
package.AddSetting(EnginePackageSettings.ContinueOnUnloadError, options.ContinueOnUnloadError);

if (options.FrameworkSpecified)
package.AddSetting(EnginePackageSettings.RuntimeFramework, options.Framework);

Expand Down
26 changes: 16 additions & 10 deletions src/NUnitConsole/nunit3-console/EnginePackageSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -25,7 +25,7 @@ namespace NUnit
{
/// <summary>
/// EngineSettings contains constant values that
/// are used as keys in setting up a TestPackage.
/// are used as keys in setting up a TestPackage.
/// Values here are used in the engine, and set by the runner.
/// Setting values may be a string, int or bool.
/// </summary>
Expand All @@ -47,15 +47,15 @@ public static class EnginePackageSettings
public const string AutoBinPath = "AutoBinPath";

/// <summary>
/// The ApplicationBase to use in loading the tests. If not
/// The ApplicationBase to use in loading the tests. If not
/// specified, and each assembly has its own process, then the
/// location of the assembly is used. For multiple assemblies
/// in a single process, the closest common root directory is used.
/// </summary>
public const string BasePath = "BasePath";

/// <summary>
/// Path to the config file to use in running the tests.
/// Path to the config file to use in running the tests.
/// </summary>
public const string ConfigurationFile = "ConfigurationFile";

Expand All @@ -65,7 +65,7 @@ public static class EnginePackageSettings
public const string DebugTests = "DebugTests";

/// <summary>
/// Bool flag indicating whether a debugger should be launched at agent
/// Bool flag indicating whether a debugger should be launched at agent
/// startup. Used only for debugging NUnit itself.
/// </summary>
public const string DebugAgent = "DebugAgent";
Expand All @@ -86,7 +86,7 @@ public static class EnginePackageSettings
public const string PrivateBinPath = "PrivateBinPath";

/// <summary>
/// The maximum number of test agents permitted to run simultaneously.
/// The maximum number of test agents permitted to run simultaneously.
/// Ignored if the ProcessModel is not set or defaulted to Multiple.
/// </summary>
public const string MaxAgents = "MaxAgents";
Expand All @@ -99,14 +99,14 @@ public static class EnginePackageSettings
public const string ProcessModel = "ProcessModel";

/// <summary>
/// Indicates the desired runtime to use for the tests. Values
/// Indicates the desired runtime to use for the tests. Values
/// are strings like "net-4.5", "mono-4.0", etc. Default is to
/// use the target framework for which an assembly was built.
/// </summary>
public const string RuntimeFramework = "RuntimeFramework";

/// <summary>
/// Bool flag indicating that the test should be run in a 32-bit process
/// Bool flag indicating that the test should be run in a 32-bit process
/// on a 64-bit system. By default, NUNit runs in a 64-bit process on
/// a 64-bit system. Ignored if set on a 32-bit system.
/// </summary>
Expand All @@ -118,7 +118,7 @@ public static class EnginePackageSettings
public const string DisposeRunners = "DisposeRunners";

/// <summary>
/// Bool flag indicating that the test assemblies should be shadow copied.
/// Bool flag indicating that the test assemblies should be shadow copied.
/// Defaults to false.
/// </summary>
public const string ShadowCopyFiles = "ShadowCopyFiles";
Expand Down Expand Up @@ -152,6 +152,12 @@ public static class EnginePackageSettings
/// </summary>
public const string PrincipalPolicy = "PrincipalPolicy";

/// <summary>
/// Flag (bool) indicating whether to continue if unloading test assemblies fail. The default is false,
/// in which case an exception is thrown.
/// </summary>
public const string ContinueOnUnloadError = "ContinueOnUnloadError";

#endregion
}
}
16 changes: 14 additions & 2 deletions src/NUnitEngine/nunit.engine.tests/Services/DomainManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down Expand Up @@ -110,6 +110,18 @@ public void UnloadingTwiceThrowsNUnitEngineException()
CheckDomainIsUnloaded(domain);
}

[Test]
public void UnloadingTwiceDoesNotThrowNUnitEngineExceptionIfContinueOnUnloadErrorIsSet()
{
var domain = _domainManager.CreateDomain(_package);
_domainManager.Unload(domain, true);

Assert.That(() => _domainManager.Unload(domain, true), Throws.Nothing);

CheckDomainIsUnloaded(domain);
}


#region Helper Methods

private void CheckDomainIsUnloaded(AppDomain domain)
Expand Down
27 changes: 17 additions & 10 deletions src/NUnitEngine/nunit.engine/EnginePackageSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -25,7 +25,7 @@ namespace NUnit
{
/// <summary>
/// EngineSettings contains constant values that
/// are used as keys in setting up a TestPackage.
/// are used as keys in setting up a TestPackage.
/// Values here are used in the engine, and set by the runner.
/// Setting values may be a string, int or bool.
/// </summary>
Expand All @@ -47,15 +47,15 @@ public static class EnginePackageSettings
public const string AutoBinPath = "AutoBinPath";

/// <summary>
/// The ApplicationBase to use in loading the tests. If not
/// The ApplicationBase to use in loading the tests. If not
/// specified, and each assembly has its own process, then the
/// location of the assembly is used. For multiple assemblies
/// in a single process, the closest common root directory is used.
/// </summary>
public const string BasePath = "BasePath";

/// <summary>
/// Path to the config file to use in running the tests.
/// Path to the config file to use in running the tests.
/// </summary>
public const string ConfigurationFile = "ConfigurationFile";

Expand All @@ -65,7 +65,7 @@ public static class EnginePackageSettings
public const string DebugTests = "DebugTests";

/// <summary>
/// Bool flag indicating whether a debugger should be launched at agent
/// Bool flag indicating whether a debugger should be launched at agent
/// startup. Used only for debugging NUnit itself.
/// </summary>
public const string DebugAgent = "DebugAgent";
Expand All @@ -86,7 +86,7 @@ public static class EnginePackageSettings
public const string PrivateBinPath = "PrivateBinPath";

/// <summary>
/// The maximum number of test agents permitted to run simultaneously.
/// The maximum number of test agents permitted to run simultaneously.
/// Ignored if the ProcessModel is not set or defaulted to Multiple.
/// </summary>
public const string MaxAgents = "MaxAgents";
Expand All @@ -99,14 +99,14 @@ public static class EnginePackageSettings
public const string ProcessModel = "ProcessModel";

/// <summary>
/// Indicates the desired runtime to use for the tests. Values
/// Indicates the desired runtime to use for the tests. Values
/// are strings like "net-4.5", "mono-4.0", etc. Default is to
/// use the target framework for which an assembly was built.
/// </summary>
public const string RuntimeFramework = "RuntimeFramework";

/// <summary>
/// Bool flag indicating that the test should be run in a 32-bit process
/// Bool flag indicating that the test should be run in a 32-bit process
/// on a 64-bit system. By default, NUNit runs in a 64-bit process on
/// a 64-bit system. Ignored if set on a 32-bit system.
/// </summary>
Expand All @@ -118,7 +118,7 @@ public static class EnginePackageSettings
public const string DisposeRunners = "DisposeRunners";

/// <summary>
/// Bool flag indicating that the test assemblies should be shadow copied.
/// Bool flag indicating that the test assemblies should be shadow copied.
/// Defaults to false.
/// </summary>
public const string ShadowCopyFiles = "ShadowCopyFiles";
Expand Down Expand Up @@ -152,6 +152,13 @@ public static class EnginePackageSettings
/// </summary>
public const string PrincipalPolicy = "PrincipalPolicy";

/// <summary>
/// Flag (bool) indicating whether to continue if unloading test assemblies fail. The default is false,
/// in which case an exception is thrown.
/// </summary>
public const string ContinueOnUnloadError = "ContinueOnUnloadError";


#endregion
}
}
10 changes: 6 additions & 4 deletions src/NUnitEngine/nunit.engine/Runners/TestDomainRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -32,10 +32,12 @@ namespace NUnit.Engine.Runners
public class TestDomainRunner : DirectTestRunner
{
private DomainManager _domainManager;
private bool _continueOnUnloadError;

public TestDomainRunner(IServiceLocator services, TestPackage package) : base(services, package)
public TestDomainRunner(IServiceLocator services, TestPackage package) : base(services, package)
{
_domainManager = Services.GetService<DomainManager>();
_continueOnUnloadError = package.GetSetting(EnginePackageSettings.ContinueOnUnloadError, false);
}

#region DirectTestRunner Overrides
Expand All @@ -54,7 +56,7 @@ public override void UnloadPackage()
{
if (this.TestDomain != null)
{
_domainManager.Unload(this.TestDomain);
_domainManager.Unload(this.TestDomain, _continueOnUnloadError);
this.TestDomain = null;
}
}
Expand Down
Loading