Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private int RunTests(TestPackage package, TestFilter filter)
        {
            // TODO: We really need options as resolved by engine for most of  these
            DisplayRequestedOptions();

            // TODO: Incorporate this in EventCollector?
            RedirectOutputAsRequested();

            TestEventHandler eventHandler = new TestEventHandler(options, outWriter, errorWriter);

            XmlNode result = null;

            // Save things that might be messed up by a bad test
            TextWriter savedOut   = Console.Out;
            TextWriter savedError = Console.Error;

            DateTime startTime = DateTime.Now;

            try
            {
                using (new ColorConsole(ColorStyle.Output))
#if true
                    result = engine.Run(package, eventHandler, filter);
#else
                    using (ITestRunner runner = engine.GetRunner(package))
                    {
                        if (runner.Load(package))
                        {
                            engineResult = runner.Run(eventHandler, testFilter);
                        }
                    }
#endif
            }
            finally
            {
                Console.SetOut(savedOut);
                Console.SetError(savedError);

                RestoreOutput();
            }

            //Console.WriteLine();

            ResultReporter reporter = new ResultReporter(result, options);
            reporter.ReportResults();

            // TODO: Inject this?
            var outputManager = new OutputManager(result, this.workDirectory);

            foreach (var outputSpec in options.ResultOutputSpecifications)
            {
                outputManager.WriteResultFile(outputSpec, startTime);
            }

            return(reporter.Summary.ErrorsAndFailures);
        }
Exemplo n.º 3
0
        private int RunTests(TestPackage package, TestFilter filter)
        {
            // TODO: We really need options as resolved by engine for most of  these
            DisplayRequestedOptions();

            // TODO: Incorporate this in EventCollector?
            RedirectOutputAsRequested();

            var labels = _options.DisplayTestLabels != null
                ? _options.DisplayTestLabels.ToUpperInvariant()
                : "ON";

            TestEventHandler eventHandler = new TestEventHandler(_outWriter, labels);

            XmlNode result = null;

            // Save things that might be messed up by a bad test
            TextWriter savedOut   = Console.Out;
            TextWriter savedError = Console.Error;

            DateTime startTime = DateTime.Now;

            try
            {
                using (new ColorConsole(ColorStyle.Output))
                    using (ITestRunner runner = _engine.GetRunner(package))
                    {
                        result = runner.Run(eventHandler, filter);
                    }
            }
            finally
            {
                Console.SetOut(savedOut);
                Console.SetError(savedError);

                RestoreOutput();
            }

            //Console.WriteLine();

            ResultReporter reporter = new ResultReporter(result, _options);

            reporter.ReportResults();

            // TODO: Inject this?
            var outputManager = new OutputManager(result, _workDirectory);

            foreach (var outputSpec in _options.ResultOutputSpecifications)
            {
                outputManager.WriteResultFile(outputSpec, startTime);
            }

            return(reporter.Summary.ErrorsAndFailures);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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?
            RedirectOutputAsRequested();

            var labels = _options.DisplayTestLabels != null
                ? _options.DisplayTestLabels.ToUpperInvariant()
                : "ON";

            var eventHandler = new TestEventHandler(_outWriter, labels, _options.TeamCity);

            XmlNode result;

            try
            {
                using (new SaveConsoleOutput())
                    using (new ColorConsole(ColorStyle.Output))
                        using (ITestRunner runner = _engine.GetRunner(package))
                        {
                            result = runner.Run(eventHandler, filter);
                        }
            }
            finally
            {
                RestoreOutput();
            }

            var reporter = new ResultReporter(result, new ExtendedTextWriter(Console.Out), _options);

            reporter.ReportResults();

            foreach (var spec in _options.ResultOutputSpecifications)
            {
                GetResultWriter(spec).WriteResultFile(result, spec.OutputPath);
            }

            return(reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount);
        }
Exemplo n.º 6
0
        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, _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)
            {
                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;

            return reporter.Summary.InvalidAssemblies > 0
                    ? ConsoleRunner.INVALID_ASSEMBLY
                    : reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount;

        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount;
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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 = 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 + engineException.Message);

                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, engineException.Message);

            return ConsoleRunner.UNEXPECTED_ERROR;
        }
Exemplo n.º 11
0
        private int RunTests(TestPackage package, TestFilter filter)
        {
            // TODO: We really need options as resolved by engine for most of  these
            DisplayRequestedOptions();

            // TODO: Incorporate this in EventCollector?
            RedirectOutputAsRequested();

            var labels = _options.DisplayTestLabels != null
                ? _options.DisplayTestLabels.ToUpperInvariant()
                : "ON";
            TestEventHandler eventHandler = new TestEventHandler(_outWriter, labels);

            XmlNode result = null;

            // Save things that might be messed up by a bad test
            TextWriter savedOut = Console.Out;
            TextWriter savedError = Console.Error;

            DateTime startTime = DateTime.Now;

            try
            {
                using ( new ColorConsole( ColorStyle.Output ) )
                using (ITestRunner runner = _engine.GetRunner(package))
                {
                    result = runner.Run(eventHandler, filter);
                }
            }
            finally
            {
                Console.SetOut(savedOut);
                Console.SetError(savedError);

                RestoreOutput();
            }

            //Console.WriteLine();

            ResultReporter reporter = new ResultReporter(result, _options);
            reporter.ReportResults();

            // TODO: Inject this?
            var outputManager = new OutputManager(result, _workDirectory);

            foreach (var outputSpec in _options.ResultOutputSpecifications)
                outputManager.WriteResultFile(outputSpec, startTime);

            return reporter.Summary.ErrorsAndFailures;
        }