Merge pull request #1253 from dotnet/piotrpMSFT/dotnet-testConfiguration

dotnet-test -c
This commit is contained in:
Piotr Puszkiewicz 2016-02-05 14:21:12 -08:00
commit 0863e02b52
3 changed files with 18 additions and 15 deletions

View file

@ -33,7 +33,7 @@ cp -rec -Force "$RepoRoot\test\TestProjects\*" "$TestBinRoot\TestProjects"
$TestProjects | foreach { $TestProjects | foreach {
# This is a workaroudn for issue #1184, where dotnet test needs to be executed from the folder containing the project.json. # This is a workaroudn for issue #1184, where dotnet test needs to be executed from the folder containing the project.json.
pushd "$RepoRoot\test\$($_.ProjectName)" pushd "$RepoRoot\test\$($_.ProjectName)"
dotnet test -xml "$TestBinRoot\$($_.ProjectName)-testResults.xml" -notrait category=failing dotnet test -c "$Configuration" -xml "$TestBinRoot\$($_.ProjectName)-testResults.xml" -notrait category=failing
popd popd
$exitCode = $LastExitCode $exitCode = $LastExitCode

View file

@ -33,7 +33,7 @@ for project in $TestProjects
do do
# This is a workaroudn for issue #1184, where dotnet test needs to be executed from the folder containing the project.json. # This is a workaroudn for issue #1184, where dotnet test needs to be executed from the folder containing the project.json.
pushd "$REPOROOT/test/$project" pushd "$REPOROOT/test/$project"
dotnet test -xml "$TEST_BIN_ROOT\$project-testResults.xml" -notrait category=failing dotnet test -c "$CONFIGURATION" -xml "$TEST_BIN_ROOT\$project-testResults.xml" -notrait category=failing
popd popd
exitCode=$? exitCode=$?

View file

@ -33,6 +33,7 @@ namespace Microsoft.DotNet.Tools.Test
var parentProcessIdOption = app.Option("--parentProcessId", "Used by IDEs to specify their process ID. Test will exit if the parent process does.", CommandOptionType.SingleValue); var parentProcessIdOption = app.Option("--parentProcessId", "Used by IDEs to specify their process ID. Test will exit if the parent process does.", CommandOptionType.SingleValue);
var portOption = app.Option("--port", "Used by IDEs to specify a port number to listen for a connection.", CommandOptionType.SingleValue); var portOption = app.Option("--port", "Used by IDEs to specify a port number to listen for a connection.", CommandOptionType.SingleValue);
var configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
var 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."); var 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.");
app.OnExecute(() => app.OnExecute(() =>
@ -57,6 +58,8 @@ namespace Microsoft.DotNet.Tools.Test
var projectContext = projectContexts.First(); var projectContext = projectContexts.First();
var testRunner = projectContext.ProjectFile.TestRunner; var testRunner = projectContext.ProjectFile.TestRunner;
var configuration = configurationOption.Value() ?? Constants.DefaultConfiguration;
if (portOption.HasValue()) if (portOption.HasValue())
{ {
@ -67,11 +70,11 @@ namespace Microsoft.DotNet.Tools.Test
throw new InvalidOperationException($"{portOption.Value()} is not a valid port number."); throw new InvalidOperationException($"{portOption.Value()} is not a valid port number.");
} }
return RunDesignTime(port, projectContext, testRunner); return RunDesignTime(port, projectContext, testRunner, configuration);
} }
else else
{ {
return RunConsole(projectContext, app, testRunner); return RunConsole(projectContext, app, testRunner, configuration);
} }
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
@ -90,9 +93,9 @@ namespace Microsoft.DotNet.Tools.Test
return app.Execute(args); return app.Execute(args);
} }
private static int RunConsole(ProjectContext projectContext, CommandLineApplication app, string testRunner) private static int RunConsole(ProjectContext projectContext, CommandLineApplication app, string testRunner, string configuration)
{ {
var commandArgs = new List<string> { projectContext.GetOutputPathCalculator().GetAssemblyPath(Constants.DefaultConfiguration) }; var commandArgs = new List<string> { projectContext.GetOutputPathCalculator().GetAssemblyPath(configuration) };
commandArgs.AddRange(app.RemainingArguments); commandArgs.AddRange(app.RemainingArguments);
return Command.CreateDotNet($"{GetCommandName(testRunner)}", commandArgs, projectContext.TargetFramework) return Command.CreateDotNet($"{GetCommandName(testRunner)}", commandArgs, projectContext.TargetFramework)
@ -102,20 +105,20 @@ namespace Microsoft.DotNet.Tools.Test
.ExitCode; .ExitCode;
} }
private static int RunDesignTime(int port, ProjectContext projectContext, string testRunner) private static int RunDesignTime(int port, ProjectContext projectContext, string testRunner, string configuration)
{ {
Console.WriteLine("Listening on port {0}", port); Console.WriteLine("Listening on port {0}", port);
using (var channel = ReportingChannel.ListenOn(port)) using (var channel = ReportingChannel.ListenOn(port))
{ {
Console.WriteLine("Client accepted {0}", channel.Socket.LocalEndPoint); Console.WriteLine("Client accepted {0}", channel.Socket.LocalEndPoint);
HandleDesignTimeMessages(projectContext, testRunner, channel); HandleDesignTimeMessages(projectContext, testRunner, channel, configuration);
return 0; return 0;
} }
} }
private static void HandleDesignTimeMessages(ProjectContext projectContext, string testRunner, ReportingChannel channel) private static void HandleDesignTimeMessages(ProjectContext projectContext, string testRunner, ReportingChannel channel, string configuration)
{ {
try try
{ {
@ -131,11 +134,11 @@ namespace Microsoft.DotNet.Tools.Test
if (message.MessageType == "TestDiscovery.Start") if (message.MessageType == "TestDiscovery.Start")
{ {
HandleTestDiscoveryStartMessage(testRunner, channel, projectContext); HandleTestDiscoveryStartMessage(testRunner, channel, projectContext, configuration);
} }
else if (message.MessageType == "TestExecution.Start") else if (message.MessageType == "TestExecution.Start")
{ {
HandleTestExecutionStartMessage(testRunner, message, channel, projectContext); HandleTestExecutionStartMessage(testRunner, message, channel, projectContext, configuration);
} }
else else
{ {
@ -167,11 +170,11 @@ namespace Microsoft.DotNet.Tools.Test
}); });
} }
private static void HandleTestDiscoveryStartMessage(string testRunner, ReportingChannel channel, ProjectContext projectContext) private static void HandleTestDiscoveryStartMessage(string testRunner, ReportingChannel channel, ProjectContext projectContext, string configuration)
{ {
TestHostTracing.Source.TraceInformation("Starting Discovery"); TestHostTracing.Source.TraceInformation("Starting Discovery");
var commandArgs = new List<string> { projectContext.GetOutputPathCalculator().GetAssemblyPath(Constants.DefaultConfiguration) }; var commandArgs = new List<string> { projectContext.GetOutputPathCalculator().GetAssemblyPath(configuration) };
commandArgs.AddRange(new[] commandArgs.AddRange(new[]
{ {
@ -189,11 +192,11 @@ namespace Microsoft.DotNet.Tools.Test
TestHostTracing.Source.TraceInformation("Completed Discovery"); TestHostTracing.Source.TraceInformation("Completed Discovery");
} }
private static void HandleTestExecutionStartMessage(string testRunner, Message message, ReportingChannel channel, ProjectContext projectContext) private static void HandleTestExecutionStartMessage(string testRunner, Message message, ReportingChannel channel, ProjectContext projectContext, string configuration)
{ {
TestHostTracing.Source.TraceInformation("Starting Execution"); TestHostTracing.Source.TraceInformation("Starting Execution");
var commandArgs = new List<string> { projectContext.GetOutputPathCalculator().GetAssemblyPath(Constants.DefaultConfiguration) }; var commandArgs = new List<string> { projectContext.GetOutputPathCalculator().GetAssemblyPath(configuration) };
commandArgs.AddRange(new[] commandArgs.AddRange(new[]
{ {