コード例 #1
0
        public int Execute(string[] args)
        {
            _options = new NUnitLiteOptions(_testAssembly == null, args);

            ExtendedTextWriter outWriter = null;

            if (_options.OutFile != null)
            {
                var outFile    = Path.Combine(_options.WorkDirectory, _options.OutFile);
                var textWriter = TextWriter.Synchronized(new StreamWriter(outFile));
                outWriter = new ExtendedTextWrapper(textWriter);
                Console.SetOut(outWriter);
            }
            else
            {
                outWriter = new ColorConsoleWriter(!_options.NoColor);
            }

            using (outWriter)
            {
                TextWriter errWriter = null;
                if (_options.ErrFile != null)
                {
                    var errFile = Path.Combine(_options.WorkDirectory, _options.ErrFile);
                    errWriter = TextWriter.Synchronized(new StreamWriter(errFile));
                    Console.SetError(errWriter);
                }

                using (errWriter)
                {
                    _textUI = new TextUI(outWriter, Console.In, _options);
                    return(Execute());
                }
            }
        }
コード例 #2
0
ファイル: TextRunner.cs プロジェクト: wangxueqzz/nunit
        public int Execute(string[] args)
        {
            var options = new NUnitLiteOptions(args);

            InitializeInternalTrace(options);

            ExtendedTextWriter outWriter = null;

            if (options.OutFile != null)
            {
                var outFile = Path.Combine(options.WorkDirectory, options.OutFile);
#if NETSTANDARD1_6
                var textWriter = File.CreateText(outFile);
#else
                var textWriter = TextWriter.Synchronized(new StreamWriter(outFile));
#endif
                outWriter = new ExtendedTextWrapper(textWriter);
                Console.SetOut(outWriter);
            }
            else
            {
                outWriter = new ColorConsoleWriter();
            }

            TextWriter errWriter = null;
            if (options.ErrFile != null)
            {
                var errFile = Path.Combine(options.WorkDirectory, options.ErrFile);
#if NETSTANDARD1_6
                errWriter = File.CreateText(errFile);
#else
                errWriter = TextWriter.Synchronized(new StreamWriter(errFile));
#endif
                Console.SetError(errWriter);
            }

            try
            {
                return(Execute(outWriter, Console.In, options));
            }
            finally
            {
                if (options.OutFile != null && outWriter != null)
#if NETSTANDARD1_6
                { outWriter.Dispose(); }
#else
                { outWriter.Close(); }
#endif

                if (options.ErrFile != null && errWriter != null)
#if NETSTANDARD1_6
                { errWriter.Dispose(); }
#else
                { errWriter.Close(); }
#endif
            }
        }
コード例 #3
0
ファイル: TextRunner.cs プロジェクト: yunmiha/TizenFX
        public int Execute(string[] args)
        {
            var options = new NUnitLiteOptions(args);
            ExtendedTextWriter outWriter = null;

            outWriter = new ColorConsoleWriter();
            try
            {
                return(Execute(outWriter, Console.In, options));
            }
            finally
            {
                if (options.OutFile != null && outWriter != null)
                {
                    outWriter.Flush();
                }
            }
        }
コード例 #4
0
        public int Execute(string[] args)
        {
            var options = new NUnitLiteOptions(args);

            InitializeInternalTrace(options);

            ExtendedTextWriter outWriter = null;

            if (options.OutFile != null)
            {
                outWriter = new ExtendedTextWrapper(new StreamWriter(Path.Combine(options.WorkDirectory, options.OutFile)));
                Console.SetOut(outWriter);
            }
            else
            {
                outWriter = new ColorConsoleWriter();
            }

            TextWriter errWriter = null;

            if (options.ErrFile != null)
            {
                errWriter = new StreamWriter(Path.Combine(options.WorkDirectory, options.ErrFile));
                Console.SetError(errWriter);
            }

            try
            {
                return(Execute(outWriter, Console.In, options));
            }
            finally
            {
                if (options.OutFile != null && outWriter != null)
                {
                    outWriter.Close();
                }

                if (options.ErrFile != null && errWriter != null)
                {
                    errWriter.Close();
                }
            }
        }
コード例 #5
0
ファイル: ConsoleRunner.cs プロジェクト: mjedrzejek/nunit
        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;

        }
コード例 #6
0
ファイル: ConsoleRunner.cs プロジェクト: JohanLarsson/nunit
        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;
        }
コード例 #7
0
ファイル: ConsoleRunner.cs プロジェクト: ChrisMaddock/nunit
        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;
        }
コード例 #8
0
ファイル: TextRunner.cs プロジェクト: yunmiha/TizenFX
        public void LoadTest(string[] args)
        {
            //TLogger.Write("LoadTest ..................");
            _options = new NUnitLiteOptions(args);
            ExtendedTextWriter outWriter = null;

            outWriter = new ColorConsoleWriter();
            _textUI   = new TextUI(outWriter, Console.In, _options);
            _runner   = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());
            try
            {
                #if !SILVERLIGHT && !PORTABLE
                if (!Directory.Exists(_options.WorkDirectory))
                {
                    Directory.CreateDirectory(_options.WorkDirectory);
                }

                #if !NETCF
                if (_options.TeamCity)
                {
                    _teamCity = new TeamCityEventListener();
                }
                #endif
                #endif

                if (_options.ShowVersion || !_options.NoHeader)
                {
                    _textUI.DisplayHeader();
                }

                if (_options.ShowHelp)
                {
                    _textUI.DisplayHelp();
                    return;
                }

                // We already showed version as a part of the header
                if (_options.ShowVersion)
                {
                    return;
                }

                if (_options.ErrorMessages.Count > 0)
                {
                    _textUI.DisplayErrors(_options.ErrorMessages);
                    _textUI.DisplayHelp();

                    return;
                }

                _textUI.DisplayRuntimeEnvironment();

                var testFile = _testAssembly != null
                                        ? AssemblyHelper.GetAssemblyPath(_testAssembly)
                                        : _options.InputFiles.Count > 0
                                        ? _options.InputFiles[0]
                                        : null;

                //TLogger.Write("Input File [0]:" + _options.InputFiles[0]);
                //TLogger.Write("Input File Format Size :"+ _options.InputFiles.Count);

                if (testFile != null)
                {
                    _textUI.DisplayTestFiles(new string[] { testFile });
                    //TLogger.Write("after DisplayTestFiles");
                    if (_testAssembly == null)
                    {
                        _testAssembly = AssemblyHelper.Load(testFile);
                    }
                }


                if (_options.WaitBeforeExit && _options.OutFile != null)
                {
                    _textUI.DisplayWarning("Ignoring /wait option - only valid for Console");
                }

                foreach (string nameOrPath in _options.InputFiles)
                {
                    //TLogger.Write("In foreach" + nameOrPath);
                    _assemblies.Add(AssemblyHelper.Load(nameOrPath));
                }

                // We display the filters at this point so  that any exception message
                // thrown by CreateTestFilter will be understandable.
                _textUI.DisplayTestFilters();
                var runSettings = MakeRunSettings(_options);

                TestFilter filter = CreateTestFilter(_options);

                _runner.Load(_testAssembly, runSettings);
            }
            catch (FileNotFoundException ex)
            {
                _textUI.DisplayError(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                _textUI.DisplayError(ex.ToString());
                return;
            }
                #if !SILVERLIGHT
            finally
            {
                if (_options.WaitBeforeExit)
                {
                    _textUI.WaitForUser("Press Enter key to continue . . .");
                }
                if (_options.OutFile != null && outWriter != null)
                {
                    outWriter.Flush();
                }
            }
                #endif
        }