示例#1
0
        public ResultReporter(XmlNode result, ExtendedTextWriter writer, ConsoleOptions options)
        {
            _result = result;
            _writer = writer;

            _overallResult = result.GetAttribute("result");
            if (_overallResult == "Skipped")
                _overallResult = "Warning";

            _options = options;

            Summary = new ResultSummary(result);
        }
示例#2
0
        public ConsoleRunner(ITestEngine engine, ConsoleOptions options, ExtendedTextWriter writer)
        {
            _engine = engine;
            _options = options;
            _outWriter = writer;

            _workDirectory = options.WorkDirectory;

            if (_workDirectory == null)
                _workDirectory = Environment.CurrentDirectory;
            else if (!Directory.Exists(_workDirectory))
                Directory.CreateDirectory(_workDirectory);

            _resultService = _engine.Services.GetService<IResultService>();
        }
示例#3
0
        public ConsoleRunner(ITestEngine engine, ConsoleOptions options, ExtendedTextWriter writer)
        {
            _engine = engine;
            _options = options;
            _outWriter = writer;

            _workDirectory = options.WorkDirectory;

            if (_workDirectory == null)
                _workDirectory = Environment.CurrentDirectory;
            else if (!Directory.Exists(_workDirectory))
                Directory.CreateDirectory(_workDirectory);

            _resultService = _engine.Services.GetService<IResultService>();
            _filterService = _engine.Services.GetService<ITestFilterService>();
            _extensionService = _engine.Services.GetService<IExtensionService>();

            // Enable TeamCityEventListener immediately, before the console is redirected
            _extensionService.EnableExtension("NUnit.Engine.Listeners.TeamCityEventListener", _options.TeamCity);
        }
示例#4
0
 private void DisplayRuntimeEnvironment(ExtendedTextWriter OutWriter)
 {
     OutWriter.WriteLine(ColorStyle.SectionHeader, "Runtime Environment");
     OutWriter.WriteLabelLine("   OS Version: ", GetOSVersion());
     OutWriter.WriteLabelLine("  CLR Version: ", Environment.Version.ToString());
     OutWriter.WriteLine();
 }
示例#5
0
文件: TextUI.cs 项目: tytakoff/nunit
 public TextUI(ExtendedTextWriter writer, TextReader reader, NUnitLiteOptions options)
 {
     Writer   = writer;
     _reader  = reader;
     _options = options;
 }
示例#6
0
文件: TextUI.cs 项目: tytakoff/nunit
 public TextUI(ExtendedTextWriter writer, TextReader reader)
     : this(writer, reader, new NUnitLiteOptions())
 {
 }
示例#7
0
 public TextUI(ExtendedTextWriter writer)
 {
     _outWriter = writer;
 }
示例#8
0
 public TextUI(ExtendedTextWriter writer, NUnitLiteOptions options)
 {
     _options   = options;
     _outWriter = writer ?? new ColorConsoleWriter(!options.NoColor);
 }
示例#9
0
        public int Execute(ExtendedTextWriter writer, TextReader reader, NUnitLiteOptions options)
        {
            var textUI = new TextUI(writer, reader, options);

            return(Execute(textUI, options));
        }
 public void CreateWriter()
 {
     _output = new StringBuilder();
     _writer = new ExtendedTextWrapper(new StringWriter(_output));
 }
示例#11
0
 public int Execute(ExtendedTextWriter writer, TextReader reader, string[] args)
 {
     return(Execute(writer, reader, new NUnitLiteOptions(args)));
 }
示例#12
0
        public TextUI(ExtendedTextWriter writer)
#if SILVERLIGHT || PORTABLE
            : this(writer, null, new NUnitLiteOptions())
        {
        }
示例#13
0
        /// <summary>
        /// Execute the tests in the assembly, passing in
        /// a list of arguments.
        /// </summary>
        /// <param name="args">Execution options</param>
        public int Execute(string[] args)
        {
            var options         = new NUnitLiteOptions(args);
            var callingAssembly = Assembly.GetCallingAssembly();

            var level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel ?? "Off", true);

#if NETCF  // NETCF: Try to unify
            InitializeInternalTrace(callingAssembly.GetName().CodeBase, level);
#else
            InitializeInternalTrace(callingAssembly.Location, level);
#endif

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

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

            var _textUI = new TextUI(outWriter, options);

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

            if (options.ShowHelp)
            {
                _textUI.DisplayHelp();
                return(TextRunner.OK);
            }

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

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

                return(TextRunner.INVALID_ARG);
            }

#if !PORTABLE
            if (options.InputFiles.Count > 0)
            {
                _textUI.DisplayError("Input assemblies may not be specified when using the NUnitLite AutoRunner");
                return(TextRunner.INVALID_ARG);
            }
#endif

            _textUI.DisplayRuntimeEnvironment();
            _textUI.DisplayTestFiles(new string[] { callingAssembly.GetName().Name });

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

            try
            {
                return(new TextRunner(_textUI, options).Execute(callingAssembly));
            }
            finally
            {
                if (options.WaitBeforeExit)
                {
                    _textUI.WaitForUser("Press Enter key to continue . . .");
                }

                if (outWriter != null)
                {
                    outWriter.Close();
                }

                if (errWriter != null)
                {
                    errWriter.Close();
                }
            }
        }
示例#14
0
 /// <summary>
 /// Execute the tests in the assembly, passing in
 /// a list of arguments, a test assembly a writer
 /// and a reader. For use in builds for runtimes
 /// that don't support Assembly.GetCallingAssembly().
 /// </summary>
 /// <param name="args">Arguments passed to NUnitLite</param>
 /// <param name="writer">An ExtendedTextWriter to which output will be written</param>
 /// <param name="reader">A TextReader used when waiting for input</param>
 public int Execute(string[] args, ExtendedTextWriter writer, TextReader reader)
 {
     return(new TextRunner(_testAssembly).Execute(writer, reader, args));
 }
示例#15
0
        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
        }