Beispiel #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 . . .");
            }
        }
Beispiel #2
0
 public int Execute(ExtendedTextWriter writer, TextReader reader, NUnitLiteOptions options)
 {
     var textUI = new TextUI(writer, reader, options);
     return Execute(textUI, options);
 }
Beispiel #3
0
 public int Execute(ExtendedTextWriter writer, TextReader reader, string[] args)
 {
     var options = new NUnitLiteOptions(args);
     var textUI = new TextUI(writer, reader, options);
     return Execute(textUI, options);
 }
Beispiel #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();
            }
        }
Beispiel #5
0
 public TextUI(NUnitLiteOptions options) : this(null, options) { }
Beispiel #6
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
        }
Beispiel #7
0
        /// <summary>
        /// Make the settings for this run - this is public for testing
        /// </summary>
        public static Dictionary <string, object> MakeRunSettings(NUnitLiteOptions options)
        {
            // Transfer command line options to run settings
            var runSettings = new Dictionary <string, object>();

            if (options.PreFilters.Count > 0)
            {
                runSettings[FrameworkPackageSettings.LOAD] = options.PreFilters;
            }
            else if (options.TestList.Count > 0)
            {
                var prefilters = new List <string>();

                foreach (var testName in options.TestList)
                {
                    int end = testName.IndexOfAny(new char[] { '(', '<' });
                    if (end > 0)
                    {
                        prefilters.Add(testName.Substring(0, end));
                    }
                    else
                    {
                        prefilters.Add(testName);
                    }
                }

                runSettings[FrameworkPackageSettings.LOAD] = prefilters;
            }

            if (options.NumberOfTestWorkers >= 0)
            {
                runSettings[FrameworkPackageSettings.NumberOfTestWorkers] = options.NumberOfTestWorkers;
            }

            if (options.InternalTraceLevel != null)
            {
                runSettings[FrameworkPackageSettings.InternalTraceLevel] = options.InternalTraceLevel;
            }

            if (options.RandomSeed >= 0)
            {
                runSettings[FrameworkPackageSettings.RandomSeed] = options.RandomSeed;
            }

            if (options.WorkDirectory != null)
            {
                runSettings[FrameworkPackageSettings.WorkDirectory] = Path.GetFullPath(options.WorkDirectory);
            }

            if (options.DefaultTimeout >= 0)
            {
                runSettings[FrameworkPackageSettings.DefaultTimeout] = options.DefaultTimeout;
            }

            if (options.StopOnError)
            {
                runSettings[FrameworkPackageSettings.StopOnError] = true;
            }

            if (options.DefaultTestNamePattern != null)
            {
                runSettings[FrameworkPackageSettings.DefaultTestNamePattern] = options.DefaultTestNamePattern;
            }

            if (options.TestParameters.Count != 0)
            {
                runSettings[FrameworkPackageSettings.TestParametersDictionary] = options.TestParameters;
            }

            return(runSettings);
        }
Beispiel #8
0
        /// <summary>
        /// Create the test filter for this run - public for testing
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static TestFilter CreateTestFilter(NUnitLiteOptions options)
        {
            var filter = TestFilter.Empty;

            if (options.TestList.Count > 0)
            {
                var testFilters = new List<TestFilter>();
                foreach (var test in options.TestList)
                    testFilters.Add(new FullNameFilter(test));

                filter = testFilters.Count > 1
                    ? new OrFilter(testFilters.ToArray())
                    : testFilters[0];
            }
                

            if (options.WhereClauseSpecified)
            {
                string xmlText = new TestSelectionParser().Parse(options.WhereClause);
                var whereFilter = TestFilter.FromXml(TNode.FromXml(xmlText));
                filter = filter.IsEmpty
                    ? whereFilter
                    : new AndFilter(filter, whereFilter);
            }

            return filter;
        }
Beispiel #9
0
        /// <param name="options">The options to use when running the test</param>
        public TextRunner(TextUI textUI, NUnitLiteOptions options)
        {
            _textUI = textUI;
            _options = options;
            
#if !PORTABLE
            if (!Directory.Exists(_options.WorkDirectory))
                Directory.CreateDirectory(_options.WorkDirectory);

#if !NETCF
            if (_options.TeamCity)
                _teamCity = new TeamCityEventListener();
#endif
#endif
        }
Beispiel #10
0
 public TextUI(ExtendedTextWriter writer, TextReader reader, NUnitLiteOptions options)
 {
     _options = options;
     _writer = writer;
     _reader = reader;
 }
Beispiel #11
0
 public TextUI(ExtendedTextWriter writer, NUnitLiteOptions options)
 {
     _options   = options;
     _outWriter = writer ?? new ColorConsoleWriter(!options.NoColor);
 }
Beispiel #12
0
 public TextUI(NUnitLiteOptions options) : this(null, options)
 {
 }
Beispiel #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();
                }
            }
        }
Beispiel #14
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
        }
Beispiel #15
0
 public TextUI(ExtendedTextWriter writer, TextReader reader, NUnitLiteOptions options)
 {
     Writer   = writer;
     _reader  = reader;
     _options = options;
 }
Beispiel #16
0
        /// <summary>
        /// Make the settings for this run - this is public for testing
        /// </summary>
        public static Dictionary<string, object> MakeRunSettings(NUnitLiteOptions options)
        {
            // Transfer command line options to run settings
            var runSettings = new Dictionary<string, object>();

            if (options.RandomSeed >= 0)
                runSettings[PackageSettings.RandomSeed] = options.RandomSeed;

#if !PORTABLE
            if (options.WorkDirectory != null)
                runSettings[PackageSettings.WorkDirectory] = Path.GetFullPath(options.WorkDirectory);
#endif
            if (options.DefaultTimeout >= 0)
                runSettings[PackageSettings.DefaultTimeout] = options.DefaultTimeout;

            if (options.StopOnError)
                runSettings[PackageSettings.StopOnError] = true;

            return runSettings;
        }
Beispiel #17
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 !PORTABLE
                if (!Directory.Exists(_options.WorkDirectory))
                {
                    Directory.CreateDirectory(_options.WorkDirectory);
                }
#endif

                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.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);
            }
            finally
            {
                if (_options.WaitBeforeExit)
                {
                    _textUI.WaitForUser("Press Enter key to continue . . .");
                }
            }
        }
Beispiel #18
0
        private void InitializeInternalTrace(NUnitLiteOptions _options)
        {
            var traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), _options.InternalTraceLevel ?? "Off", true);

            if (traceLevel != InternalTraceLevel.Off)
            {
                var logName = GetLogFileName();

#if NETCF // NETCF: Try to encapsulate this
                InternalTrace.Initialize(Path.Combine(NUnit.Env.DocumentFolder, logName), traceLevel);
#else
                StreamWriter streamWriter = null;
                if (traceLevel > InternalTraceLevel.Off)
                {
                    string logPath = Path.Combine(Environment.CurrentDirectory, logName);
                    streamWriter = new StreamWriter(new FileStream(logPath, FileMode.Append, FileAccess.Write, FileShare.Write));
                    streamWriter.AutoFlush = true;
                }
                InternalTrace.Initialize(streamWriter, traceLevel);
#endif
            }
        }
Beispiel #19
0
        public int Execute(ExtendedTextWriter writer, TextReader reader, NUnitLiteOptions options)
        {
            var textUI = new TextUI(writer, reader, options);

            return(Execute(textUI, options));
        }
Beispiel #20
0
 public TextUI(ExtendedTextWriter writer, NUnitLiteOptions options)
 {
     _options = options;
     _outWriter = writer ?? new ColorConsoleWriter(!options.NoColor);
 }
Beispiel #21
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();
            }
        }