Example #1
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)
        {
            TestFilter namefilter = options.TestList.Count > 0
                ? new SimpleNameFilter(options.TestList)
                : TestFilter.Empty;

            TestFilter includeFilter = string.IsNullOrEmpty(options.Include)
                ? TestFilter.Empty
                : new SimpleCategoryExpression(options.Include).Filter;

            TestFilter excludeFilter = string.IsNullOrEmpty(options.Exclude)
                ? TestFilter.Empty
                : new NotFilter(new SimpleCategoryExpression(options.Exclude).Filter);

            TestFilter catFilter = includeFilter.IsEmpty
                ? excludeFilter
                : excludeFilter.IsEmpty
                    ? includeFilter
                    : new AndFilter(includeFilter, excludeFilter);

            return namefilter.IsEmpty
                ? catFilter
                : catFilter.IsEmpty
                    ? namefilter
                    : new AndFilter(namefilter, catFilter);
        }
Example #2
0
        /// <param name="options">The options to use when running the test</param>
        public TextRunner(TextUI textUI, NUnitLiteOptions options)
        {
            _textUI = textUI;
            _options = options;

            if (!Directory.Exists(_options.WorkDirectory))
                Directory.CreateDirectory(_options.WorkDirectory);

#if !NETCF
            if (_options.TeamCity)
                _teamCity = new TeamCityEventListener();
#endif
        }
Example #3
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 (options.WorkDirectory != null)
                runSettings[PackageSettings.WorkDirectory] = Path.GetFullPath(options.WorkDirectory);

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

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

            return runSettings;
        }
Example #4
0
 public TextUI(ExtendedTextWriter writer, NUnitLiteOptions options)
 {
     _options = options;
     _outWriter = writer ?? new ColorConsoleWriter(!options.NoColor);
 }
Example #5
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 filters = new List<TestFilter>();

            foreach (var test in options.TestList)
                filters.Add(new FullNameFilter(test));

            if (options.WhereClauseSpecified)
            {
                string xmlText = new TestSelectionParser().Parse(options.WhereClause);
                filters.Add(TestFilter.FromXml(TNode.FromXml(xmlText)));
            }

            switch (filters.Count)
            {
                case 0:
                    return TestFilter.Empty;
                case 1:
                    return filters[0];
                default:
                    return new AndFilter(filters.ToArray());
            }
        }
Example #6
0
 public TextUI(NUnitLiteOptions options) : this(null, options) { }
Example #7
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.NoHeader)
            {
                _textUI.DisplayHeader();
            }

            if (options.ShowHelp)
            {
                _textUI.DisplayHelp();
                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.DisplayTestFiles(new string[] { callingAssembly.GetName().Name });
            _textUI.DisplayRuntimeEnvironment();
            _textUI.DisplayRequestedOptions();

            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 #8
0
 public TextUI(ExtendedTextWriter writer, NUnitLiteOptions options)
 {
     _options   = options;
     _outWriter = writer ?? new ColorConsoleWriter(!options.NoColor);
 }
Example #9
0
 public TextUI(NUnitLiteOptions options) : this(null, options)
 {
 }
Example #10
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.NoHeader)
                _textUI.DisplayHeader();

            if (options.ShowHelp)
            {
                _textUI.DisplayHelp();
                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.DisplayTestFiles(new string[] { callingAssembly.GetName().Name });
            _textUI.DisplayRuntimeEnvironment();
            _textUI.DisplayRequestedOptions();

            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();
            }
        }