private int RunTests(TestPackage package, TestFilter filter) { foreach (var spec in _options.ResultOutputSpecifications) { var outputPath = Path.Combine(_workDirectory, spec.OutputPath); GetResultWriter(spec).CheckWritability(outputPath); } // TODO: Incorporate this in EventCollector? RedirectErrorOutputAsRequested(); var labels = _options.DisplayTestLabels != null ? _options.DisplayTestLabels.ToUpperInvariant() : "ON"; XmlNode result; try { using (new SaveConsoleOutput()) using (new ColorConsole(ColorStyle.Output)) using (ITestRunner runner = _engine.GetRunner(package)) using (var output = CreateOutputWriter()) { var eventHandler = new TestEventHandler(output, labels); result = runner.Run(eventHandler, filter); } } finally { RestoreErrorOutput(); } var writer = new ColorConsoleWriter(!_options.NoColor); var reporter = new ResultReporter(result, writer, _options); reporter.ReportResults(); foreach (var spec in _options.ResultOutputSpecifications) { var outputPath = Path.Combine(_workDirectory, spec.OutputPath); GetResultWriter(spec).WriteResultFile(result, outputPath); _outWriter.WriteLine("Results ({0}) saved as {1}", spec.Format, spec.OutputPath); } if (reporter.Summary.UnexpectedError) { return(ConsoleRunner.UNEXPECTED_ERROR); } if (reporter.Summary.InvalidAssemblies > 0) { return(ConsoleRunner.INVALID_ASSEMBLY); } return(reporter.Summary.InvalidTestFixtures > 0 ? ConsoleRunner.INVALID_TEST_FIXTURE : reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount); }
private int RunTests(TestPackage package, TestFilter filter) { // TODO: We really need options as resolved by engine for most of these DisplayRequestedOptions(); foreach (var spec in _options.ResultOutputSpecifications) { GetResultWriter(spec).CheckWritability(spec.OutputPath); } // TODO: Incorporate this in EventCollector? RedirectErrorOutputAsRequested(); var labels = _options.DisplayTestLabels != null ? _options.DisplayTestLabels.ToUpperInvariant() : "ON"; XmlNode result; try { using (new SaveConsoleOutput()) using (new ColorConsole(ColorStyle.Output)) using (ITestRunner runner = _engine.GetRunner(package)) using (var output = CreateOutputWriter()) { var eventHandler = new TestEventHandler(output, labels, _options.TeamCity); result = runner.Run(eventHandler, filter); } } finally { RestoreErrorOutput(); } var writer = new ColorConsoleWriter(!_options.NoColor); var reporter = new ResultReporter(result, writer, _options); reporter.ReportResults(); foreach (var spec in _options.ResultOutputSpecifications) { GetResultWriter(spec).WriteResultFile(result, spec.OutputPath); _outWriter.WriteLine("Results ({0}) saved as {1}", spec.Format, spec.OutputPath); } return(reporter.Summary.InvalidAssemblies > 0 ? ConsoleRunner.INVALID_ASSEMBLY : reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount); }
private int RunTests(TestPackage package, TestFilter filter) { var writer = new ColorConsoleWriter(!_options.NoColor); foreach (var spec in _options.ResultOutputSpecifications) { var outputPath = Path.Combine(_workDirectory, spec.OutputPath); IResultWriter resultWriter; try { resultWriter = GetResultWriter(spec); } catch (Exception ex) { throw new NUnitEngineException($"Error encountered in resolving output specification: {spec}", ex); } try { var outputDirectory = Path.GetDirectoryName(outputPath); Directory.CreateDirectory(outputDirectory); } catch (Exception ex) { writer.WriteLine(ColorStyle.Error, String.Format( "The directory in --result {0} could not be created", spec.OutputPath)); writer.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessage(ex)); return(ConsoleRunner.UNEXPECTED_ERROR); } try { resultWriter.CheckWritability(outputPath); } catch (Exception ex) { throw new NUnitEngineException( String.Format( "The path specified in --result {0} could not be written to", spec.OutputPath), ex); } } var labels = _options.DisplayTestLabels != null ? _options.DisplayTestLabels.ToUpperInvariant() : "ON"; XmlNode result = null; NUnitEngineUnloadException unloadException = null; NUnitEngineException engineException = null; try { using (new SaveConsoleOutput()) using (ITestRunner runner = _engine.GetRunner(package)) using (var output = CreateOutputWriter()) { var eventHandler = new TestEventHandler(output, labels); result = runner.Run(eventHandler, filter); } } catch (NUnitEngineUnloadException ex) { unloadException = ex; } catch (NUnitEngineException ex) { engineException = ex; } if (result != null) { var reporter = new ResultReporter(result, writer, _options); reporter.ReportResults(); foreach (var spec in _options.ResultOutputSpecifications) { var outputPath = Path.Combine(_workDirectory, spec.OutputPath); GetResultWriter(spec).WriteResultFile(result, outputPath); writer.WriteLine("Results ({0}) saved as {1}", spec.Format, spec.OutputPath); } if (engineException != null) { writer.WriteLine(ColorStyle.Error, Environment.NewLine + ExceptionHelper.BuildMessage(engineException)); return(ConsoleRunner.UNEXPECTED_ERROR); } if (unloadException != null) { writer.WriteLine(ColorStyle.Warning, Environment.NewLine + ExceptionHelper.BuildMessage(unloadException)); } if (reporter.Summary.UnexpectedError) { return(ConsoleRunner.UNEXPECTED_ERROR); } if (reporter.Summary.InvalidAssemblies > 0) { return(ConsoleRunner.INVALID_ASSEMBLY); } if (reporter.Summary.InvalidTestFixtures > 0) { return(ConsoleRunner.INVALID_TEST_FIXTURE); } var failureCount = reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount; return(Math.Min(failureCount, MAXIMUM_RETURN_CODE_ALLOWED)); } // If we got here, it's because we had an exception, but check anyway if (engineException != null) { writer.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessage(engineException)); writer.WriteLine(); writer.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessageAndStackTrace(engineException)); } return(ConsoleRunner.UNEXPECTED_ERROR); }
private int RunTests(TestPackage package, TestFilter filter) { foreach (var spec in _options.ResultOutputSpecifications) { var outputPath = Path.Combine(_workDirectory, spec.OutputPath); IResultWriter resultWriter; try { resultWriter = GetResultWriter(spec); } catch (Exception ex) { throw new NUnitEngineException($"Error encountered in resolving output specification: {spec}", ex); } try { resultWriter.CheckWritability(outputPath); } catch (SystemException ex) { throw new NUnitEngineException( String.Format( "The path specified in --result {0} could not be written to", spec.OutputPath), ex); } } // TODO: Incorporate this in EventCollector? RedirectErrorOutputAsRequested(); var labels = _options.DisplayTestLabels != null ? _options.DisplayTestLabels.ToUpperInvariant() : "ON"; XmlNode result = null; NUnitEngineException engineException = null; try { using (new SaveConsoleOutput()) using (new ColorConsole(ColorStyle.Output)) using (ITestRunner runner = _engine.GetRunner(package)) using (var output = CreateOutputWriter()) { var eventHandler = new TestEventHandler(output, labels); result = runner.Run(eventHandler, filter); } } catch (NUnitEngineException ex) { engineException = ex; } finally { RestoreErrorOutput(); } var writer = new ColorConsoleWriter(!_options.NoColor); if (result != null) { var reporter = new ResultReporter(result, writer, _options); reporter.ReportResults(); foreach (var spec in _options.ResultOutputSpecifications) { var outputPath = Path.Combine(_workDirectory, spec.OutputPath); GetResultWriter(spec).WriteResultFile(result, outputPath); _outWriter.WriteLine("Results ({0}) saved as {1}", spec.Format, spec.OutputPath); } // Since we got a result, we display any engine exception as a warning if (engineException != null) { writer.WriteLine(ColorStyle.Warning, Environment.NewLine + ExceptionHelper.BuildMessage(engineException)); } if (reporter.Summary.UnexpectedError) { return(ConsoleRunner.UNEXPECTED_ERROR); } if (reporter.Summary.InvalidAssemblies > 0) { return(ConsoleRunner.INVALID_ASSEMBLY); } return(reporter.Summary.InvalidTestFixtures > 0 ? ConsoleRunner.INVALID_TEST_FIXTURE : reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount); } // If we got here, it's because we had an exception, but check anyway if (engineException != null) { writer.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessage(engineException)); writer.WriteLine(); writer.WriteLine(ColorStyle.Error, ExceptionHelper.BuildStackTrace(engineException)); } return(ConsoleRunner.UNEXPECTED_ERROR); }