Added a Help property to DotnetTestParams that indicates when the parsed arguments included the help param. The TestCommand then uses this property of the params to decide whether to continue with the execution or just return. Also added unit tests around this as well as introduced a DotnetTestRunnerFactory to make these unit tests possible and also push the responsibility to figure out which runner to use to the factory.
This commit is contained in:
parent
47241189b2
commit
d07a1091a8
7 changed files with 143 additions and 7 deletions
|
@ -47,6 +47,8 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
public bool NoBuild { get; set; }
|
||||
|
||||
public bool Help { get; set; }
|
||||
|
||||
public DotnetTestParams()
|
||||
{
|
||||
_app = new CommandLineApplication(false)
|
||||
|
@ -57,6 +59,8 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
};
|
||||
|
||||
AddDotnetTestParameters();
|
||||
|
||||
Help = true;
|
||||
}
|
||||
|
||||
public void Parse(string[] args)
|
||||
|
@ -108,6 +112,8 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
RemainingArguments = _app.RemainingArguments;
|
||||
|
||||
Help = false;
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
|
@ -150,7 +156,7 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
_app.Option("--no-build", "Do not build project before testing", CommandOptionType.NoValue);
|
||||
_projectPath = _app.Argument(
|
||||
"<PROJECT>",
|
||||
"The project to test, defaults to the current directory. Can be a path to a project.json or a project directory.");
|
||||
"The project to test, defaults to the current directory. Can be a path to a project.json or a project directory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
19
src/dotnet/commands/dotnet-test/DotnetTestRunnerFactory.cs
Normal file
19
src/dotnet/commands/dotnet-test/DotnetTestRunnerFactory.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test
|
||||
{
|
||||
public class DotnetTestRunnerFactory : IDotnetTestRunnerFactory
|
||||
{
|
||||
public IDotnetTestRunner Create(int? port)
|
||||
{
|
||||
IDotnetTestRunner dotnetTestRunner = new ConsoleTestRunner();
|
||||
if (port.HasValue)
|
||||
{
|
||||
dotnetTestRunner = new DesignTimeRunner();
|
||||
}
|
||||
|
||||
return dotnetTestRunner;
|
||||
}
|
||||
}
|
||||
}
|
10
src/dotnet/commands/dotnet-test/IDotnetTestRunnerFactory.cs
Normal file
10
src/dotnet/commands/dotnet-test/IDotnetTestRunnerFactory.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test
|
||||
{
|
||||
public interface IDotnetTestRunnerFactory
|
||||
{
|
||||
IDotnetTestRunner Create(int? port);
|
||||
}
|
||||
}
|
|
@ -14,7 +14,14 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
{
|
||||
public class TestCommand
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
private readonly IDotnetTestRunnerFactory _dotnetTestRunnerFactory;
|
||||
|
||||
public TestCommand(IDotnetTestRunnerFactory testRunnerFactory)
|
||||
{
|
||||
_dotnetTestRunnerFactory = testRunnerFactory;
|
||||
}
|
||||
|
||||
public int DoRun(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
|
@ -24,6 +31,11 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
try
|
||||
{
|
||||
if (dotnetTestParams.Help)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register for parent process's exit event
|
||||
if (dotnetTestParams.ParentProcessId.HasValue)
|
||||
{
|
||||
|
@ -36,11 +48,7 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
var testRunner = projectContext.ProjectFile.TestRunner;
|
||||
|
||||
IDotnetTestRunner dotnetTestRunner = new ConsoleTestRunner();
|
||||
if (dotnetTestParams.Port.HasValue)
|
||||
{
|
||||
dotnetTestRunner = new DesignTimeRunner();
|
||||
}
|
||||
IDotnetTestRunner dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port);
|
||||
|
||||
return dotnetTestRunner.RunTests(projectContext, dotnetTestParams);
|
||||
}
|
||||
|
@ -56,6 +64,13 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
}
|
||||
}
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
var testCommand = new TestCommand(new DotnetTestRunnerFactory());
|
||||
|
||||
return testCommand.DoRun(args);
|
||||
}
|
||||
|
||||
private static void RegisterForParentProcessExit(int id)
|
||||
{
|
||||
var parentProcess = Process.GetProcesses().FirstOrDefault(p => p.Id == id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue