public int DoRun(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var dotnetTestParams = new DotnetTestParams(); try { dotnetTestParams.Parse(args); if (dotnetTestParams.Help) { return(0); } // Register for parent process's exit event if (dotnetTestParams.ParentProcessId.HasValue) { RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value); } return(RunTest(dotnetTestParams)); } catch (InvalidOperationException ex) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return(-1); } catch (Exception ex) when(!(ex is GracefulException)) { Console.WriteLine(ex.ToString()); TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return(-2); } }
private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var strings = new List <string> { $"{dotnetTestParams.ProjectOrAssemblyPath}", $"--configuration", dotnetTestParams.Config, "--framework", projectContext.TargetFramework.ToString() }; // Build the test specifically for the target framework \ rid of the ProjectContext. // This avoids building the project for tfms that the user did not request. if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath)) { strings.Add("--build-base-path"); strings.Add(dotnetTestParams.BuildBasePath); } if (!string.IsNullOrEmpty(dotnetTestParams.Output)) { strings.Add("--output"); strings.Add(dotnetTestParams.Output); } if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier)) { strings.Add("--runtime"); strings.Add(projectContext.RuntimeIdentifier); } var result = Command.CreateDotNet("build", strings).Execute().ExitCode; return(result); }
private void HandleDesignTimeMessages(DotnetTestParams dotnetTestParams) { var reportingChannelFactory = new ReportingChannelFactory(); var adapterChannel = reportingChannelFactory.CreateAdapterChannel(dotnetTestParams.Port.Value); try { var pathToAssemblyUnderTest = _assemblyUnderTest; var messages = new TestMessagesCollection(); using (var dotnetTest = new DotnetTest(messages, pathToAssemblyUnderTest)) { var testRunnerFactory = new TestRunnerFactory(_testRunnerNameResolver.ResolveTestRunner(), _commandFactory); dotnetTest .AddNonSpecificMessageHandlers(messages, adapterChannel) .AddTestDiscoveryMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory) .AddTestRunMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory) .AddTestRunnnersMessageHandlers(adapterChannel, reportingChannelFactory); dotnetTest.StartListeningTo(adapterChannel); adapterChannel.Connect(); dotnetTest.StartHandlingMessages(); } } catch (Exception ex) { adapterChannel.SendError(ex); } }
private int RunTest(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { var testRunner = projectContext.ProjectFile.TestRunner; var dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port); return(dotnetTestRunner.RunTests(projectContext, dotnetTestParams, workspace)); }
public ITestRunnerNameResolver Create(DotnetTestParams dotnetTestParams) { var testRunnerResolver = dotnetTestParams.IsTestingAssembly ? GetAssemblyTestRunnerResolver(dotnetTestParams) : GetProjectJsonTestRunnerResolver(dotnetTestParams); return(testRunnerResolver); }
internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value); HandleDesignTimeMessages(projectContext, dotnetTestParams); return(0); }
internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value); HandleDesignTimeMessages(projectContext, dotnetTestParams); return 0; }
public int RunTests(DotnetTestParams dotnetTestParams) { Console.WriteLine("Listening on port {0}", dotnetTestParams.Port.Value); HandleDesignTimeMessages(dotnetTestParams); return(0); }
public int RunTests(DotnetTestParams dotnetTestParams) { var projectPath = GetProjectPath(dotnetTestParams.ProjectOrAssemblyPath); var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ? new[] { dotnetTestParams.Runtime } : RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(); var exitCode = 0; // Create a workspace var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment()); if (dotnetTestParams.Framework != null) { var projectContext = workspace.GetProjectContext(projectPath, dotnetTestParams.Framework); if (projectContext == null) { Reporter.Error.WriteLine( $"Project '{projectPath}' does not support framework: {dotnetTestParams.UnparsedFramework}"); return(1); } projectContext = workspace.GetRuntimeContext(projectContext, runtimeIdentifiers); exitCode = RunTests(projectContext, dotnetTestParams); } else { var summary = new Summary(); var projectContexts = workspace.GetProjectContextCollection(projectPath) .EnsureValid(projectPath) .FrameworkOnlyContexts .Select(c => workspace.GetRuntimeContext(c, runtimeIdentifiers)) .ToList(); // Execute for all TFMs the project targets. foreach (var projectContext in projectContexts) { var result = RunTests(projectContext, dotnetTestParams); if (result == 0) { summary.Passed++; } else { summary.Failed++; if (exitCode == 0) { // If tests fail in more than one TFM, we'll have it use the result of the first one // as the exit code. exitCode = result; } } } summary.Print(); } return(exitCode); }
private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { if (dotnetTestParams.NoBuild) { return 0; } return DoBuildTestProject(projectContext, dotnetTestParams, workspace); }
private int BuildTestProject(DotnetTestParams dotnetTestParams) { if (dotnetTestParams.NoBuild) { return 0; } return DoBuildTestProject(dotnetTestParams); }
private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { if (dotnetTestParams.NoBuild) { return(0); } return(DoBuildTestProject(projectContext, dotnetTestParams, workspace)); }
private int BuildTestProject(DotnetTestParams dotnetTestParams) { if (dotnetTestParams.NoBuild) { return(0); } return(DoBuildTestProject(dotnetTestParams)); }
public void It_throws_InvalidOperationException_if_an_invalid_parent_process_id_is_passed_to_it() { var dotnetTestParams = new DotnetTestParams(); const string invalidParentProcessId = "daddy"; Action action = () => dotnetTestParams.Parse(new [] { "--parentProcessId", invalidParentProcessId }); action .ShouldThrow<InvalidOperationException>() .WithMessage($"Invalid process id '{invalidParentProcessId}'. Process id must be an integer."); }
public int RunTests(DotnetTestParams dotnetTestParams) { return(_commandFactory.Create( _testRunnerNameResolver.ResolveTestRunner(), GetCommandArgs(dotnetTestParams), _framework, dotnetTestParams.Config) .Execute() .ExitCode); }
private IEnumerable <string> GetCommandArgs(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var commandArgs = new List <string> { new AssemblyUnderTest(projectContext, dotnetTestParams).Path }; commandArgs.AddRange(dotnetTestParams.RemainingArguments); return(commandArgs); }
private IEnumerable <string> GetCommandArgs(DotnetTestParams dotnetTestParams) { var commandArgs = new List <string> { _assemblyUnderTest }; commandArgs.AddRange(dotnetTestParams.RemainingArguments); return(commandArgs); }
private IEnumerable<string> GetCommandArgs(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var commandArgs = new List<string> { new AssemblyUnderTest(projectContext, dotnetTestParams).Path }; commandArgs.AddRange(dotnetTestParams.RemainingArguments); return commandArgs; }
public int RunTests(DotnetTestParams dotnetTestParams) { var assembly = new FileInfo(dotnetTestParams.ProjectOrAssemblyPath); var publishDirectory = assembly.Directory.FullName; var applicationName = Path.GetFileNameWithoutExtension(dotnetTestParams.ProjectOrAssemblyPath); var commandFactory = new PublishedPathCommandFactory(publishDirectory, applicationName); var assemblyUnderTest = dotnetTestParams.ProjectOrAssemblyPath; return(_nextRunner(commandFactory, assemblyUnderTest).RunTests(dotnetTestParams)); }
private ITestRunnerNameResolver GetAssemblyTestRunnerResolver(DotnetTestParams dotnetTestParams) { ITestRunnerNameResolver testRunnerNameResolver = null; if (dotnetTestParams.HasTestRunner) { testRunnerNameResolver = new ParameterTestRunnerNameResolver(dotnetTestParams.TestRunner); } else { testRunnerNameResolver = new AssemblyTestRunnerNameResolver(dotnetTestParams.ProjectOrAssemblyPath); } return(testRunnerNameResolver); }
internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var commandFactory = new ProjectDependenciesCommandFactory( projectContext.TargetFramework, dotnetTestParams.Config, dotnetTestParams.Output, dotnetTestParams.BuildBasePath, projectContext.ProjectDirectory); return commandFactory.Create( GetCommandName(projectContext.ProjectFile.TestRunner), GetCommandArgs(projectContext, dotnetTestParams), projectContext.TargetFramework, dotnetTestParams.Config) .Execute() .ExitCode; }
internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var commandFactory = new ProjectDependenciesCommandFactory( projectContext.TargetFramework, dotnetTestParams.Config, dotnetTestParams.Output, dotnetTestParams.BuildBasePath, projectContext.ProjectDirectory); return(commandFactory.Create( GetCommandName(projectContext.ProjectFile.TestRunner), GetCommandArgs(projectContext, dotnetTestParams), projectContext.TargetFramework, dotnetTestParams.Config) .Execute() .ExitCode); }
public int DoRun(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var dotnetTestParams = new DotnetTestParams(); dotnetTestParams.Parse(args); try { if (dotnetTestParams.Help) { return(0); } // Register for parent process's exit event if (dotnetTestParams.ParentProcessId.HasValue) { RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value); } var projectContexts = CreateProjectContexts(dotnetTestParams.ProjectPath); var projectContext = projectContexts.First(); var testRunner = projectContext.ProjectFile.TestRunner; IDotnetTestRunner dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port); return(dotnetTestRunner.RunTests(projectContext, dotnetTestParams)); } catch (InvalidOperationException ex) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return(-1); } catch (Exception ex) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return(-2); } }
private static void HandleDesignTimeMessages( ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var reportingChannelFactory = new ReportingChannelFactory(); var adapterChannel = reportingChannelFactory.CreateAdapterChannel(dotnetTestParams.Port.Value); try { var pathToAssemblyUnderTest = new AssemblyUnderTest(projectContext, dotnetTestParams).Path; var messages = new TestMessagesCollection(); using (var dotnetTest = new DotnetTest(messages, pathToAssemblyUnderTest)) { var commandFactory = new ProjectDependenciesCommandFactory( projectContext.TargetFramework, dotnetTestParams.Config, dotnetTestParams.Output, dotnetTestParams.BuildBasePath, projectContext.ProjectDirectory); var testRunnerFactory = new TestRunnerFactory(GetCommandName(projectContext.ProjectFile.TestRunner), commandFactory); dotnetTest .AddNonSpecificMessageHandlers(messages, adapterChannel) .AddTestDiscoveryMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory) .AddTestRunMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory) .AddTestRunnnersMessageHandlers(adapterChannel, reportingChannelFactory); dotnetTest.StartListeningTo(adapterChannel); adapterChannel.Connect(); dotnetTest.StartHandlingMessages(); } } catch (Exception ex) { adapterChannel.SendError(ex); } }
public int DoRun(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var dotnetTestParams = new DotnetTestParams(); dotnetTestParams.Parse(args); try { if (dotnetTestParams.Help) { return 0; } // Register for parent process's exit event if (dotnetTestParams.ParentProcessId.HasValue) { RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value); } var projectContexts = CreateProjectContexts(dotnetTestParams.ProjectPath); var projectContext = projectContexts.First(); var testRunner = projectContext.ProjectFile.TestRunner; IDotnetTestRunner dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port); return dotnetTestRunner.RunTests(projectContext, dotnetTestParams); } catch (InvalidOperationException ex) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return -1; } catch (Exception ex) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return -2; } }
public IDotnetTestRunner Create(DotnetTestParams dotnetTestParams) { Func <ICommandFactory, string, NuGetFramework, IDotnetTestRunner> nextTestRunner = (commandFactory, assemblyUnderTest, framework) => { var dotnetTestRunnerResolver = _dotnetTestRunnerResolverFactory.Create(dotnetTestParams); IDotnetTestRunner testRunner = new ConsoleTestRunner(dotnetTestRunnerResolver, commandFactory, assemblyUnderTest, framework); if (dotnetTestParams.Port.HasValue) { testRunner = new DesignTimeRunner(dotnetTestRunnerResolver, commandFactory, assemblyUnderTest); } return(testRunner); }; return(dotnetTestParams.IsTestingAssembly ? CreateTestRunnerForAssembly(nextTestRunner) : CreateTestRunnerForProjectJson(nextTestRunner)); }
public GivenThatWeWantToParseArgumentsForDotnetTest() { _dotnetTestFullParams = new DotnetTestParams(); _emptyDotnetTestParams = new DotnetTestParams(); _dotnetTestFullParams.Parse(new[] { ProjectJson, "--parentProcessId", ParentProcessId.ToString(), "--port", Port.ToString(), "--framework", Framework, "--output", Output, "--build-base-path", BuildBasePath, "--configuration", Config, "--runtime", Runtime, "--no-build", "--additional-parameters", "additional-parameter-value" }); _emptyDotnetTestParams.Parse(new string[] { }); }
internal override int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { try { var commandFactory = new ProjectDependenciesCommandFactory( projectContext.TargetFramework, dotnetTestParams.Config, dotnetTestParams.Output, dotnetTestParams.BuildBasePath, projectContext.ProjectDirectory); return(commandFactory.Create( GetCommandName(projectContext.ProjectFile.TestRunner), GetCommandArgs(projectContext, dotnetTestParams), projectContext.TargetFramework, dotnetTestParams.Config) .ForwardStdErr() .ForwardStdOut() .Execute() .ExitCode); } catch (CommandUnknownException e) { var commandFactory = new DotNetCommandFactory(); return(commandFactory.Create( GetDotNetCommandName(projectContext.ProjectFile.TestRunner), GetCommandArgs(projectContext, dotnetTestParams), projectContext.TargetFramework, dotnetTestParams.Config) .ForwardStdErr() .ForwardStdOut() .Execute() .ExitCode); } }
private int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var result = _testProjectBuilder.BuildTestProject(projectContext, dotnetTestParams); if (result == 0) { var commandFactory = new ProjectDependenciesCommandFactory( projectContext.TargetFramework, dotnetTestParams.Config, dotnetTestParams.Output, dotnetTestParams.BuildBasePath, projectContext.ProjectDirectory); var assemblyUnderTest = new AssemblyUnderTest(projectContext, dotnetTestParams); var framework = projectContext.TargetFramework; result = _nextRunner(commandFactory, assemblyUnderTest.Path, framework).RunTests(dotnetTestParams); } return(result); }
private int DoBuildTestProject(DotnetTestParams dotnetTestParams) { var strings = new List<string> { $"--configuration", dotnetTestParams.Config, $"{dotnetTestParams.ProjectPath}" }; if (dotnetTestParams.Framework != null) { strings.Add("--framework"); strings.Add($"{dotnetTestParams.Framework}"); } if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath)) { strings.Add("--build-base-path"); strings.Add(dotnetTestParams.BuildBasePath); } if (!string.IsNullOrEmpty(dotnetTestParams.Output)) { strings.Add("--output"); strings.Add(dotnetTestParams.Output); } if (!string.IsNullOrEmpty(dotnetTestParams.Runtime)) { strings.Add("--runtime"); strings.Add(dotnetTestParams.Runtime); } var result = Build.BuildCommand.Run(strings.ToArray()); return result; }
private int DoBuildTestProject(DotnetTestParams dotnetTestParams) { var strings = new List <string> { $"--configuration", dotnetTestParams.Config, $"{dotnetTestParams.ProjectPath}" }; if (dotnetTestParams.Framework != null) { strings.Add("--framework"); strings.Add($"{dotnetTestParams.Framework}"); } if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath)) { strings.Add("--build-base-path"); strings.Add(dotnetTestParams.BuildBasePath); } if (!string.IsNullOrEmpty(dotnetTestParams.Output)) { strings.Add("--output"); strings.Add(dotnetTestParams.Output); } if (!string.IsNullOrEmpty(dotnetTestParams.Runtime)) { strings.Add("--runtime"); strings.Add(dotnetTestParams.Runtime); } var result = Build.BuildCommand.Run(strings.ToArray()); return(result); }
private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { var strings = new List<string> { $"--configuration", dotnetTestParams.Config, $"{dotnetTestParams.ProjectPath}" }; // Build the test specifically for the target framework \ rid of the ProjectContext. This avoids building the project // for tfms that the user did not request. strings.Add("--framework"); strings.Add(projectContext.TargetFramework.ToString()); if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath)) { strings.Add("--build-base-path"); strings.Add(dotnetTestParams.BuildBasePath); } if (!string.IsNullOrEmpty(dotnetTestParams.Output)) { strings.Add("--output"); strings.Add(dotnetTestParams.Output); } if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier)) { strings.Add("--runtime"); strings.Add(projectContext.RuntimeIdentifier); } var result = Build.BuildCommand.Run(strings.ToArray(), workspace); return result; }
private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { var strings = new List <string> { $"--configuration", dotnetTestParams.Config, $"{dotnetTestParams.ProjectPath}" }; // Build the test specifically for the target framework \ rid of the ProjectContext. This avoids building the project // for tfms that the user did not request. strings.Add("--framework"); strings.Add(projectContext.TargetFramework.ToString()); if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath)) { strings.Add("--build-base-path"); strings.Add(dotnetTestParams.BuildBasePath); } if (!string.IsNullOrEmpty(dotnetTestParams.Output)) { strings.Add("--output"); strings.Add(dotnetTestParams.Output); } if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier)) { strings.Add("--runtime"); strings.Add(projectContext.RuntimeIdentifier); } var result = Build.BuildCommand.Run(strings.ToArray(), workspace); return(result); }
public AssemblyUnderTest(ProjectContext projectContext, DotnetTestParams dotentTestParams) { _projectContext = projectContext; _dotentTestParams = dotentTestParams; }
internal abstract int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams);
public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { var result = BuildTestProject(projectContext, dotnetTestParams, workspace); return result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result; }
public void It_throws_InvalidOperationException_if_an_invalid_port_is_passed_to_it() { var dotnetTestParams = new DotnetTestParams(); const string invalidPort = "door"; Action action = () => dotnetTestParams.Parse(new[] { "--port", invalidPort }); action .ShouldThrow<InvalidOperationException>() .WithMessage($"{invalidPort} is not a valid port number."); }
public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { var result = BuildTestProject(projectContext, dotnetTestParams, workspace); return(result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result); }
private int RunTest(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace) { var testRunner = projectContext.ProjectFile.TestRunner; var dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port); return dotnetTestRunner.RunTests(projectContext, dotnetTestParams, workspace); }
public void It_sets_the_framework_to_unsupported_when_an_invalid_framework_is_passed_in() { var dotnetTestParams = new DotnetTestParams(); dotnetTestParams.Parse(new[] { "--framework", "farm work" }); dotnetTestParams.Framework.DotNetFrameworkName.Should().Be("Unsupported,Version=v0.0"); }
public void It_sets_Help_to_true_when_help_is_passed_in() { var dotnetTestParams = new DotnetTestParams(); dotnetTestParams.Parse(new[] { "--help" }); dotnetTestParams.Help.Should().BeTrue(); }
private int RunTest(DotnetTestParams dotnetTestParams) { var dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams); return(dotnetTestRunner.RunTests(dotnetTestParams)); }
public int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { return(dotnetTestParams.NoBuild ? 0 : DoBuildTestProject(projectContext, dotnetTestParams)); }
public int DoRun(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var dotnetTestParams = new DotnetTestParams(); try { dotnetTestParams.Parse(args); if (dotnetTestParams.Help) { return(0); } // Register for parent process's exit event if (dotnetTestParams.ParentProcessId.HasValue) { RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value); } var projectPath = GetProjectPath(dotnetTestParams.ProjectPath); var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ? new[] { dotnetTestParams.Runtime } : RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(); var exitCode = 0; // Create a workspace var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment()); if (dotnetTestParams.Framework != null) { var projectContext = workspace.GetProjectContext(projectPath, dotnetTestParams.Framework); if (projectContext == null) { Reporter.Error.WriteLine($"Project '{projectPath}' does not support framework: {dotnetTestParams.UnparsedFramework}"); return(1); } projectContext = workspace.GetRuntimeContext(projectContext, runtimeIdentifiers); exitCode = RunTest(projectContext, dotnetTestParams, workspace); } else { var summary = new Summary(); var projectContexts = workspace.GetProjectContextCollection(projectPath) .EnsureValid(projectPath) .FrameworkOnlyContexts .Select(c => workspace.GetRuntimeContext(c, runtimeIdentifiers)) .ToList(); // Execute for all TFMs the project targets. foreach (var projectContext in projectContexts) { var result = RunTest(projectContext, dotnetTestParams, workspace); if (result == 0) { summary.Passed++; } else { summary.Failed++; if (exitCode == 0) { // If tests fail in more than one TFM, we'll have it use the result of the first one // as the exit code. exitCode = result; } } } summary.Print(); } return(exitCode); } catch (InvalidOperationException ex) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return(-1); } catch (Exception ex) when(!(ex is GracefulException)) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return(-2); } }
public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams) { var result = BuildTestProject(dotnetTestParams); return result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result; }
private ITestRunnerNameResolver GetProjectJsonTestRunnerResolver(DotnetTestParams dotnetTestParams) { var project = _projectReader.ReadProject(dotnetTestParams.ProjectOrAssemblyPath); return(new ProjectJsonTestRunnerNameResolver(project)); }
public int DoRun(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var dotnetTestParams = new DotnetTestParams(); try { dotnetTestParams.Parse(args); if (dotnetTestParams.Help) { return 0; } // Register for parent process's exit event if (dotnetTestParams.ParentProcessId.HasValue) { RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value); } var projectPath = GetProjectPath(dotnetTestParams.ProjectPath); var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ? new[] { dotnetTestParams.Runtime } : RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(); var exitCode = 0; // Create a workspace var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment()); if (dotnetTestParams.Framework != null) { var projectContext = workspace.GetProjectContext(projectPath, dotnetTestParams.Framework); if (projectContext == null) { Reporter.Error.WriteLine($"Project '{projectPath}' does not support framework: {dotnetTestParams.UnparsedFramework}"); return 1; } projectContext = workspace.GetRuntimeContext(projectContext, runtimeIdentifiers); exitCode = RunTest(projectContext, dotnetTestParams, workspace); } else { var summary = new Summary(); var projectContexts = workspace.GetProjectContextCollection(projectPath) .EnsureValid(projectPath) .FrameworkOnlyContexts .Select(c => workspace.GetRuntimeContext(c, runtimeIdentifiers)) .ToList(); // Execute for all TFMs the project targets. foreach (var projectContext in projectContexts) { var result = RunTest(projectContext, dotnetTestParams, workspace); if (result == 0) { summary.Passed++; } else { summary.Failed++; if (exitCode == 0) { // If tests fail in more than one TFM, we'll have it use the result of the first one // as the exit code. exitCode = result; } } } summary.Print(); } return exitCode; } catch (InvalidOperationException ex) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return -1; } catch (Exception ex) when (!(ex is GracefulException)) { TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString()); return -2; } }