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

Add command-line option to specify configuration file #348

Merged
merged 3 commits into from
Jan 13, 2018
Merged
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
1 change: 1 addition & 0 deletions src/NUnitConsole/nunit3-console.tests/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public void CanRecognizeBooleanOptions(string propertyName, string pattern)
[TestCase("Framework", "framework", new string[] { "net-4.0" }, new string[0])]
[TestCase("OutFile", "output|out", new string[] { "output.txt" }, new string[0])]
[TestCase("ErrFile", "err", new string[] { "error.txt" }, new string[0])]
[TestCase("ConfigurationFile", "configfile", new string[] { "mytest.config" }, new string[0] )]
[TestCase("WorkDirectory", "work", new string[] { "results" }, new string[0])]
[TestCase("DisplayTestLabels", "labels", new string[] { "Off", "On", "Before", "After", "All" }, new string[] { "JUNK" })]
[TestCase("InternalTraceLevel", "trace", new string[] { "Off", "Error", "Warning", "Info", "Debug", "Verbose" }, new string[] { "JUNK" })]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void MultipleAssemblies()
[TestCase("--domain=multiple", "DomainUsage", "Multiple")]
[TestCase("--framework=net-4.0", "RuntimeFramework", "net-4.0")]
[TestCase("--config=Release", "ActiveConfig", "Release")]
[TestCase("--configfile=mytest.config", "ConfigurationFile", "mytest.config")]
[TestCase("--trace=Error", "InternalTraceLevel", "Error")]
[TestCase("--trace=error", "InternalTraceLevel", "Error")]
[TestCase("--seed=1234", "RandomSeed", 1234)]
Expand Down
5 changes: 5 additions & 0 deletions src/NUnitConsole/nunit3-console/ConsoleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class ConsoleOptions : CommandLineOptions
public string Framework { get; private set; }
public bool FrameworkSpecified { get { return Framework != null; } }

public string ConfigurationFile { get; private set; }

public bool RunAsX86 { get; private set; }

public bool DisposeRunners { get; private set; }
Expand Down Expand Up @@ -116,6 +118,9 @@ protected override void ConfigureOptions()
this.Add("config=", "{NAME} of a project configuration to load (e.g.: Debug).",
v => ActiveConfig = RequiredValue(v, "--config"));

this.Add("configfile=", "{NAME} of configuration file to use for this run.",
v => ConfigurationFile = RequiredValue(v, "--configfile"));

// Where to Run Tests
this.Add("process=", "{PROCESS} isolation for test assemblies.\nValues: InProcess, Separate, Multiple. If not specified, defaults to Separate for a single assembly or Multiple for more than one.",
v =>
Expand Down
3 changes: 3 additions & 0 deletions src/NUnitConsole/nunit3-console/ConsoleRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ public static TestPackage MakeTestPackage(ConsoleOptions options)
if (options.TestParameters.Count != 0)
AddTestParametersSetting(package, options.TestParameters);

if (options.ConfigurationFile != null)
package.AddSetting(EnginePackageSettings.ConfigurationFile, options.ConfigurationFile);

return package;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static class DomainManagerStaticTests
static string path2 = TestPath("/test/bin/debug/test2.dll");
static string path3 = TestPath("/test/utils/test3.dll");

const string STANDARD_CONFIG_FILE = "nunit.engine.tests.dll.config";
const string ALTERNATE_CONFIG_FILE = "alt.config";

[Test]
public static void GetPrivateBinPath()
{
Expand Down Expand Up @@ -88,15 +91,22 @@ public static void GetCommonAppBase_ThreeElements_DifferentDirectories()
[Test]
public static void ProperConfigFileIsUsed()
{
var configFileName = "nunit.engine.tests.dll.config";
var expectedPath = Path.Combine(TestContext.CurrentContext.TestDirectory, configFileName);
Assert.That(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, Is.SamePath(expectedPath));
// NOTE: The alternate config file, alt.config, is copied to the bin directory and
// may be specified from the command-line, using --configfile=alt.config. This allows
// manual testing of the option while permitting this test to still pass.
var expectedPath = Path.Combine(TestContext.CurrentContext.TestDirectory, STANDARD_CONFIG_FILE);
var alternatePath = Path.Combine(TestContext.CurrentContext.TestDirectory, ALTERNATE_CONFIG_FILE);
Assert.That(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, Is.SamePath(expectedPath).Or.SamePath(alternatePath));
}

[Test]
public static void CanReadConfigFile()
{
Assert.That(ConfigurationManager.AppSettings.Get("test.setting"), Is.EqualTo("54321"));
// NOTE: The alternate config file has a different value so we can see it being used
var expectedSetting = Path.GetFileName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile) == ALTERNATE_CONFIG_FILE
? "Alternate config used"
: "54321";
Assert.That(ConfigurationManager.AppSettings.Get("test.setting"), Is.EqualTo(expectedSetting));
}

[TestCase("/path/to/mytest.dll", null, "/path/to/")]
Expand Down
6 changes: 6 additions & 0 deletions src/NUnitEngine/nunit.engine.tests/alt.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="test.setting" value="Alternate config used"/>
</appSettings>
</configuration>
3 changes: 3 additions & 0 deletions src/NUnitEngine/nunit.engine.tests/nunit.engine.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
<None Include="..\..\nunit.snk">
<Link>nunit.snk</Link>
</None>
<None Include="alt.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
Expand Down