Example #1
0
        /// <summary>
        /// Execute the tests in the assembly, passing in
        /// a list of arguments.
        /// </summary>
        /// <param name="args">Execution options</param>
        public int Execute(Assembly callingAssembly, TextWriter writer, TextReader reader, string[] args)
        {
            var options = new NUnitLiteOptions(args);

            var _textUI = new TextUI(writer, reader, 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 (options.InputFiles.Count > 0)
            {
                _textUI.DisplayError("Input assemblies may not be specified when using the NUnitLite AutoRunner");
                return(TextRunner.INVALID_ARG);
            }

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

            if (options.WaitBeforeExit && options.OutFile != null)
            {
                writer.WriteLine("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 . . .");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Execute the tests in the assembly, passing in
        /// a list of arguments.
        /// </summary>
        /// <param name="args">Execution options</param>
        public int Execute(Assembly callingAssembly, TextWriter writer, TextReader reader, string[] args)
        {
            var options = new NUnitLiteOptions(args);

            var _textUI = new TextUI(writer, reader, 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 (options.InputFiles.Count > 0)
            {
                _textUI.DisplayError("Input assemblies may not be specified when using the NUnitLite AutoRunner");
                return TextRunner.INVALID_ARG;
            }

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

            if (options.WaitBeforeExit && options.OutFile != null)
                writer.WriteLine("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 . . .");
            }
        }
Example #3
0
        // Internal Execute depends on _textUI and _options having been set already.
        private int Execute()
        {
            _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder());

            InitializeInternalTrace();

            try
            {
                if (!Directory.Exists(_options.WorkDirectory))
                {
                    Directory.CreateDirectory(_options.WorkDirectory);
                }

                if (_options.TeamCity)
                {
                    _teamCity = new TeamCityEventListener(_textUI.Writer);
                }

                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.Writer.WriteLine();
                    _textUI.DisplayHelp();

                    return(TextRunner.INVALID_ARG);
                }

                if (_testAssembly == null && _options.InputFile == null)
                {
                    _textUI.DisplayError("No test assembly was specified.");
                    _textUI.Writer.WriteLine();
                    _textUI.DisplayHelp();

                    return(TextRunner.OK);
                }

                _textUI.DisplayRuntimeEnvironment();

                var testFile = _testAssembly != null
                    ? AssemblyHelper.GetAssemblyPath(_testAssembly)
                    : _options.InputFile;

                _textUI.DisplayTestFiles(new string[] { testFile });
                if (_testAssembly == null)
                {
                    _testAssembly = AssemblyHelper.Load(testFile);
                }

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

                var runSettings = MakeRunSettings(_options);

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

                TestFilter filter = CreateTestFilter(_options);

                _runner.Load(_testAssembly, runSettings);
                return(_options.Explore ? ExploreTests(filter) : RunTests(filter, runSettings));
            }
            catch (FileNotFoundException ex)
            {
                _textUI.DisplayError(ex.Message);
                return(FILE_NOT_FOUND);
            }
            catch (Exception ex)
            {
                _textUI.DisplayError(ex.ToString());
                return(UNEXPECTED_ERROR);
            }
            finally
            {
                if (_options.WaitBeforeExit)
                {
                    _textUI.WaitForUser("Press Enter key to continue . . .");
                }
            }
        }
Example #4
0
        /// <summary>
        /// Execute a test run
        /// </summary>
        /// <param name="callingAssembly">The assembly from which tests are loaded</param>
        public int Execute(TextUI textUI, NUnitLiteOptions options)
        {
            _textUI = textUI;
            _options = 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 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;
                }

                _textUI.DisplayRuntimeEnvironment();

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

                if (testFile != null)
                {
                    _textUI.DisplayTestFiles(new string[] { testFile });
                    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)
                    _assemblies.Add(AssemblyHelper.Load(nameOrPath));

                var runSettings = MakeRunSettings(_options);

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

                TestFilter filter = CreateTestFilter(_options);

                _runner.Load(_testAssembly, runSettings);
                return _options.Explore ? ExploreTests() : RunTests(filter, runSettings);
            }
            catch (FileNotFoundException ex)
            {
                _textUI.DisplayError(ex.Message);
                return FILE_NOT_FOUND;
            }
            catch (Exception ex)
            {
                _textUI.DisplayError(ex.ToString());
                return UNEXPECTED_ERROR;
            }
#if !SILVERLIGHT
            finally
            {
                if (_options.WaitBeforeExit)
                    _textUI.WaitForUser("Press Enter key to continue . . .");
            }
#endif
        }
Example #5
0
        /// <summary>
        /// Execute a test run
        /// </summary>
        /// <param name="callingAssembly">The assembly from which tests are loaded</param>
        public int Execute(TextUI textUI, NUnitLiteOptions options)
        {
            _textUI  = textUI;
            _options = 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(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);
                }

                _textUI.DisplayRuntimeEnvironment();

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

                if (testFile != null)
                {
                    _textUI.DisplayTestFiles(new string[] { testFile });
                    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)
                {
                    _assemblies.Add(AssemblyHelper.Load(nameOrPath));
                }

                var runSettings = MakeRunSettings(_options);

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

                TestFilter filter = CreateTestFilter(_options);

                _runner.Load(_testAssembly, runSettings);
                return(_options.Explore ? ExploreTests() : RunTests(filter, runSettings));
            }
            catch (FileNotFoundException ex)
            {
                _textUI.DisplayError(ex.Message);
                return(FILE_NOT_FOUND);
            }
            catch (Exception ex)
            {
                _textUI.DisplayError(ex.ToString());
                return(UNEXPECTED_ERROR);
            }
#if !SILVERLIGHT
            finally
            {
                if (_options.WaitBeforeExit)
                {
                    _textUI.WaitForUser("Press Enter key to continue . . .");
                }
            }
#endif
        }
Example #6
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();
                }
            }
        }
Example #7
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
        }
Example #8
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();
            }
        }