Exemple #1
0
        public int Execute(ConsoleOptions options)
        {
            this.workDir = options.work;
            if (workDir == null || workDir == string.Empty)
            {
                workDir = Environment.CurrentDirectory;
            }
            else
            {
                workDir = Path.GetFullPath(workDir);
                if (!Directory.Exists(workDir))
                {
                    Directory.CreateDirectory(workDir);
                }
            }

            TextWriter outWriter      = Console.Out;
            bool       redirectOutput = options.output != null && options.output != string.Empty;

            if (redirectOutput)
            {
                StreamWriter outStreamWriter = new StreamWriter(Path.Combine(workDir, options.output));
                outStreamWriter.AutoFlush = true;
                outWriter = outStreamWriter;
            }

            TextWriter errorWriter   = Console.Error;
            bool       redirectError = options.err != null && options.err != string.Empty;

            if (redirectError)
            {
                StreamWriter errorStreamWriter = new StreamWriter(Path.Combine(workDir, options.err));
                errorStreamWriter.AutoFlush = true;
                errorWriter = errorStreamWriter;
            }

            TestPackage package = MakeTestPackage(options);

            ProcessModel processModel = package.Settings.Contains("ProcessModel")
                ? (ProcessModel)package.Settings["ProcessModel"]
                : ProcessModel.Default;

            DomainUsage domainUsage = package.Settings.Contains("DomainUsage")
                ? (DomainUsage)package.Settings["DomainUsage"]
                : DomainUsage.Default;

            RuntimeFramework framework = package.Settings.Contains("RuntimeFramework")
                ? (RuntimeFramework)package.Settings["RuntimeFramework"]
                : RuntimeFramework.CurrentFramework;

#if CLR_2_0 || CLR_4_0
            Console.WriteLine("ProcessModel: {0}    DomainUsage: {1}", processModel, domainUsage);

            Console.WriteLine("Execution Runtime: {0}", framework);
#else
            Console.WriteLine("DomainUsage: {0}", domainUsage);

            if (processModel != ProcessModel.Default && processModel != ProcessModel.Single)
            {
                Console.WriteLine("Warning: Ignoring project setting 'processModel={0}'", processModel);
            }

            if (!RuntimeFramework.CurrentFramework.Supports(framework))
            {
                Console.WriteLine("Warning: Ignoring project setting 'runtimeFramework={0}'", framework);
            }
#endif

            using (TestRunner testRunner = new DefaultTestRunnerFactory().MakeTestRunner(package))
            {
                testRunner.Load(package);

                if (testRunner.Test == null)
                {
                    testRunner.Unload();
                    Console.Error.WriteLine("Unable to locate fixture {0}", options.fixture);
                    return(FIXTURE_NOT_FOUND);
                }

                EventCollector collector = new EventCollector(options, outWriter, errorWriter);

                TestFilter       testFilter = TestFilter.Empty;
                SimpleNameFilter nameFilter = new SimpleNameFilter();

                if (options.run != null && options.run != string.Empty)
                {
                    Console.WriteLine("Selected test(s): " + options.run);
                    foreach (string name in TestNameParser.Parse(options.run))
                    {
                        nameFilter.Add(name);
                    }
                    testFilter = nameFilter;
                }

                if (options.runlist != null && options.runlist != string.Empty)
                {
                    Console.WriteLine("Run list: " + options.runlist);
                    using (StreamReader rdr = new StreamReader(options.runlist))
                    {
                        // NOTE: We can't use rdr.EndOfStream because it's
                        // not present in .NET 1.x.
                        string line = rdr.ReadLine();
                        while (line != null)
                        {
                            if (line[0] != '#')
                            {
                                nameFilter.Add(line);
                            }
                            line = rdr.ReadLine();
                        }
                    }
                    testFilter = nameFilter;
                }

                if (options.include != null && options.include != string.Empty)
                {
                    TestFilter includeFilter = new CategoryExpression(options.include).Filter;
                    Console.WriteLine("Included categories: " + includeFilter.ToString());

                    if (testFilter.IsEmpty)
                    {
                        testFilter = includeFilter;
                    }
                    else
                    {
                        testFilter = new AndFilter(testFilter, includeFilter);
                    }
                }

                if (options.exclude != null && options.exclude != string.Empty)
                {
                    TestFilter excludeFilter = new NotFilter(new CategoryExpression(options.exclude).Filter);
                    Console.WriteLine("Excluded categories: " + excludeFilter.ToString());

                    if (testFilter.IsEmpty)
                    {
                        testFilter = excludeFilter;
                    }
                    else if (testFilter is AndFilter)
                    {
                        ((AndFilter)testFilter).Add(excludeFilter);
                    }
                    else
                    {
                        testFilter = new AndFilter(testFilter, excludeFilter);
                    }
                }

                if (testFilter is NotFilter)
                {
                    ((NotFilter)testFilter).TopLevel = true;
                }

                TestResult result         = null;
                string     savedDirectory = Environment.CurrentDirectory;
                TextWriter savedOut       = Console.Out;
                TextWriter savedError     = Console.Error;

                try
                {
                    result = testRunner.Run(collector, testFilter, false, LoggingThreshold.Off);
                }
                finally
                {
                    outWriter.Flush();
                    errorWriter.Flush();

                    if (redirectOutput)
                    {
                        outWriter.Close();
                    }
                    if (redirectError)
                    {
                        errorWriter.Close();
                    }

                    Environment.CurrentDirectory = savedDirectory;
                    Console.SetOut(savedOut);
                    Console.SetError(savedError);
                }

                Console.WriteLine();

                int returnCode = UNEXPECTED_ERROR;

                if (result != null)
                {
                    string           xmlOutput = CreateXmlOutput(result);
                    ResultSummarizer summary   = new ResultSummarizer(result);

                    if (options.xmlConsole)
                    {
                        Console.WriteLine(xmlOutput);
                    }
                    else
                    {
                        WriteSummaryReport(summary);

                        bool hasErrors = summary.Errors > 0 || summary.Failures > 0 || result.IsError || result.IsFailure;

                        if (options.stoponerror && (hasErrors || summary.NotRunnable > 0))
                        {
                            Console.WriteLine("Test run was stopped after first error, as requested.");
                            Console.WriteLine();
                        }

                        if (hasErrors)
                        {
                            WriteErrorsAndFailuresReport(result);
                        }

                        if (summary.TestsNotRun > 0)
                        {
                            WriteNotRunReport(result);
                        }

                        if (!options.noresult)
                        {
                            // Write xml output here
                            string xmlResultFile = options.result == null || options.result == string.Empty
                                ? "TestResult.xml" : options.result;

                            using (StreamWriter writer = new StreamWriter(Path.Combine(workDir, xmlResultFile)))
                            {
                                writer.Write(xmlOutput);
                            }
                        }
                    }

                    returnCode = summary.Errors + summary.Failures + summary.NotRunnable;
                }

                if (collector.HasExceptions)
                {
                    collector.WriteExceptions();
                    returnCode = UNEXPECTED_ERROR;
                }

                return(returnCode);
            }
        }
Exemple #2
0
        public static int Main(string[] args)
        {
            ConsoleOptions options = new ConsoleOptions();

            try
            {
                options.Parse(args);
            }
            catch (OptionException ex)
            {
                WriteHeader();
                ColorConsole.WriteLine(ColorStyle.Error, string.Format(ex.Message, ex.OptionName));
                return(ConsoleRunner.INVALID_ARG);
            }

            ColorConsole.Options = options;

            // Create SettingsService early so we know the trace level right at the start
            //SettingsService settingsService = new SettingsService();
            //InternalTraceLevel level = (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default);
            //if (options.trace != InternalTraceLevel.Default)
            //    level = options.trace;

            //InternalTrace.Initialize("nunit-console_%p.log", level);

            //log.Info("NUnit-console.exe starting");
            try
            {
                if (options.PauseBeforeRun)
                {
                    ColorConsole.WriteLine(ColorStyle.Warning, "Press any key to continue . . .");
                    Console.ReadKey(true);
                }

                if (!options.NoHeader)
                {
                    WriteHeader();
                }

                if (options.ShowHelp)
                {
                    WriteHelpText(options);
                    return(ConsoleRunner.OK);
                }

                if (!options.Validate())
                {
                    using (new ColorConsole(ColorStyle.Error))
                    {
                        foreach (string message in options.ErrorMessages)
                        {
                            Console.Error.WriteLine(message);
                        }
                    }

                    return(ConsoleRunner.INVALID_ARG);
                }

                if (options.InputFiles.Count == 0)
                {
                    using (new ColorConsole(ColorStyle.Error))
                        Console.Error.WriteLine("Error: no inputs specified");
                    return(ConsoleRunner.OK);
                }

                // TODO: Move this to engine
                foreach (string file in options.InputFiles)
                {
                    //if (!Services.ProjectService.CanLoadProject(file) && !PathUtils.IsAssemblyFileType(file))
                    string ext = Path.GetExtension(file);
                    if (ext != ".dll" && ext != ".exe" && ext != ".nunit")
                    {
                        ColorConsole.WriteLine(ColorStyle.Warning, "File type not known: " + file);
                        return(ConsoleRunner.INVALID_ARG);
                    }
                }

                string workDirectory = options.WorkDirectory ?? Environment.CurrentDirectory;
                var    traceLevel    = options.InternalTraceLevel != null
                    ? (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel)
                    : InternalTraceLevel.Off;

                using (ITestEngine engine = TestEngineActivator.CreateInstance(workDirectory, traceLevel))
                {
                    try
                    {
                        return(new ConsoleRunner(engine, options).Execute());
                    }
                    catch (NUnitEngineException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
                        return(ConsoleRunner.INVALID_ARG);
                    }
                    catch (FileNotFoundException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
#if DEBUG
                        ColorConsole.WriteLine(ColorStyle.Error, ex.StackTrace);
#endif
                        return(ConsoleRunner.FILE_NOT_FOUND);
                    }
                    catch (DirectoryNotFoundException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
                        return(ConsoleRunner.FILE_NOT_FOUND);
                    }
                    catch (Exception ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
                        return(ConsoleRunner.UNEXPECTED_ERROR);
                    }
                    finally
                    {
                        if (options.WaitBeforeExit)
                        {
                            using (new ColorConsole(ColorStyle.Warning))
                            {
                                Console.Out.WriteLine("\nPress any key to continue . . .");
                                Console.ReadKey(true);
                            }
                        }

                        //    log.Info( "NUnit-console.exe terminating" );
                    }
                }
            }
            finally
            {
                Console.ResetColor();
            }
        }
Exemple #3
0
        // TODO: See if this can be unified with the Gui's MakeTestPackage
        private TestPackage MakeTestPackage(ConsoleOptions options)
        {
            TestPackage      package;
            DomainUsage      domainUsage  = DomainUsage.Default;
            ProcessModel     processModel = ProcessModel.Default;
            RuntimeFramework framework    = null;

            string[] parameters = new string[options.ParameterCount];
            for (int i = 0; i < options.ParameterCount; i++)
            {
                parameters[i] = Path.GetFullPath((string)options.Parameters[i]);
            }

            if (options.IsTestProject)
            {
                NUnitProject project =
                    Services.ProjectService.LoadProject(parameters[0]);

                string configName = options.config;
                if (configName != null)
                {
                    project.SetActiveConfig(configName);
                }

                package      = project.ActiveConfig.MakeTestPackage();
                processModel = project.ProcessModel;
                domainUsage  = project.DomainUsage;
                framework    = project.ActiveConfig.RuntimeFramework;
            }
            else if (parameters.Length == 1)
            {
                package     = new TestPackage(parameters[0]);
                domainUsage = DomainUsage.Single;
            }
            else
            {
                // TODO: Figure out a better way to handle "anonymous" packages
                package             = new TestPackage(null, parameters);
                package.AutoBinPath = true;
                domainUsage         = DomainUsage.Multiple;
            }

#if CLR_2_0 || CLR_4_0
            if (options.framework != null)
            {
                framework = RuntimeFramework.Parse(options.framework);
            }

            if (options.process != ProcessModel.Default)
            {
                processModel = options.process;
            }
#endif

            if (options.domain != DomainUsage.Default)
            {
                domainUsage = options.domain;
            }

            package.TestName = options.fixture;

            package.Settings["ProcessModel"] = processModel;
            package.Settings["DomainUsage"]  = domainUsage;
            if (framework != null)
            {
                package.Settings["RuntimeFramework"] = framework;
            }



            if (domainUsage == DomainUsage.None)
            {
                // Make sure that addins are available
                CoreExtensions.Host.AddinRegistry = Services.AddinRegistry;
            }

            package.Settings["ShadowCopyFiles"]   = !options.noshadow;
            package.Settings["UseThreadedRunner"] = !options.nothread;
            package.Settings["DefaultTimeout"]    = options.timeout;
            package.Settings["WorkDirectory"]     = this.workDir;
            package.Settings["StopOnError"]       = options.stoponerror;

            if (options.apartment != System.Threading.ApartmentState.Unknown)
            {
                package.Settings["ApartmentState"] = options.apartment;
            }

            return(package);
        }
Exemple #4
0
        // This is public static for ease of testing
        public static TestPackage MakeTestPackage(ConsoleOptions options)
        {
            TestPackage package = new TestPackage(options.InputFiles);

            if (options.ProcessModelSpecified)
            {
                package.AddSetting(PackageSettings.ProcessModel, options.ProcessModel);
            }

            if (options.DomainUsageSpecified)
            {
                package.AddSetting(PackageSettings.DomainUsage, options.DomainUsage);
            }

            if (options.FrameworkSpecified)
            {
                package.AddSetting(PackageSettings.RuntimeFramework, options.Framework);
            }

            if (options.RunAsX86)
            {
                package.AddSetting(PackageSettings.RunAsX86, true);
            }

            if (options.DisposeRunners)
            {
                package.AddSetting(PackageSettings.DisposeRunners, true);
            }

            if (options.ShadowCopyFiles)
            {
                package.AddSetting(PackageSettings.ShadowCopyFiles, true);
            }

            if (options.LoadUserProfile)
            {
                package.AddSetting(PackageSettings.LoadUserProfile, true);
            }

            if (options.DefaultTimeout >= 0)
            {
                package.AddSetting(PackageSettings.DefaultTimeout, options.DefaultTimeout);
            }

            if (options.InternalTraceLevelSpecified)
            {
                package.AddSetting(PackageSettings.InternalTraceLevel, options.InternalTraceLevel);
            }

            if (options.ActiveConfigSpecified)
            {
                package.AddSetting(PackageSettings.ActiveConfig, options.ActiveConfig);
            }

            // Always add work directory, in case current directory is changed
            var workDirectory = options.WorkDirectory ?? Environment.CurrentDirectory;

            package.AddSetting(PackageSettings.WorkDirectory, workDirectory);

            if (options.StopOnError)
            {
                package.AddSetting(PackageSettings.StopOnError, true);
            }

            if (options.MaxAgentsSpecified)
            {
                package.AddSetting(PackageSettings.MaxAgents, options.MaxAgents);
            }

            if (options.NumberOfTestWorkersSpecified)
            {
                package.AddSetting(PackageSettings.NumberOfTestWorkers, options.NumberOfTestWorkers);
            }

            if (options.RandomSeedSpecified)
            {
                package.AddSetting(PackageSettings.RandomSeed, options.RandomSeed);
            }

            if (options.DebugTests)
            {
                package.AddSetting(PackageSettings.DebugTests, true);

                if (!options.NumberOfTestWorkersSpecified)
                {
                    package.AddSetting(PackageSettings.NumberOfTestWorkers, 0);
                }
            }

            if (options.PauseBeforeRun)
            {
                package.AddSetting(PackageSettings.PauseBeforeRun, true);
            }

#if DEBUG
            if (options.DebugAgent)
            {
                package.AddSetting(PackageSettings.DebugAgent, true);
            }

            //foreach (KeyValuePair<string, object> entry in package.Settings)
            //    if (!(entry.Value is string || entry.Value is int || entry.Value is bool))
            //        throw new Exception(string.Format("Package setting {0} is not a valid type", entry.Key));
#endif

            if (options.DefaultTestNamePattern != null)
            {
                package.AddSetting(PackageSettings.DefaultTestNamePattern, options.DefaultTestNamePattern);
            }

            if (options.TestParameters != null)
            {
                package.AddSetting(PackageSettings.TestParameters, options.TestParameters);
            }

            return(package);
        }
Exemple #5
0
        public static int Main(string[] args)
        {
            ConsoleOptions options = new ConsoleOptions(args);

            // Create SettingsService early so we know the trace level right at the start
            SettingsService    settingsService = new SettingsService();
            InternalTraceLevel level           = (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default);

            if (options.trace != InternalTraceLevel.Default)
            {
                level = options.trace;
            }

            InternalTrace.Initialize("nunit-console_%p.log", level);

            log.Info("NUnit-console.exe starting");

            if (!options.nologo)
            {
                WriteCopyright();
            }

            if (options.help)
            {
                options.Help();
                return(ConsoleUi.OK);
            }

            if (options.NoArgs)
            {
                Console.Error.WriteLine("fatal error: no inputs specified");
                options.Help();
                return(ConsoleUi.OK);
            }

            if (!options.Validate())
            {
                foreach (string arg in options.InvalidArguments)
                {
                    Console.Error.WriteLine("fatal error: invalid argument: {0}", arg);
                }
                options.Help();
                return(ConsoleUi.INVALID_ARG);
            }

            // Add Standard Services to ServiceManager
            ServiceManager.Services.AddService(settingsService);
            ServiceManager.Services.AddService(new DomainManager());
            //ServiceManager.Services.AddService( new RecentFilesService() );
            ServiceManager.Services.AddService(new ProjectService());
            //ServiceManager.Services.AddService( new TestLoader() );
            ServiceManager.Services.AddService(new AddinRegistry());
            ServiceManager.Services.AddService(new AddinManager());
            ServiceManager.Services.AddService(new TestAgency());

            // Initialize Services
            ServiceManager.Services.InitializeServices();

            foreach (string parm in options.Parameters)
            {
                if (!Services.ProjectService.CanLoadProject(parm) && !PathUtils.IsAssemblyFileType(parm))
                {
                    Console.WriteLine("File type not known: {0}", parm);
                    return(ConsoleUi.INVALID_ARG);
                }
            }

            try
            {
                ConsoleUi consoleUi = new ConsoleUi();
                return(consoleUi.Execute(options));
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                return(ConsoleUi.FILE_NOT_FOUND);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception:\n{0}", ex.ToString());
                return(ConsoleUi.UNEXPECTED_ERROR);
            }
            finally
            {
                if (options.wait)
                {
                    Console.Out.WriteLine("\nHit <enter> key to continue");
                    Console.ReadLine();
                }

                log.Info("NUnit-console.exe terminating");
            }
        }
        public static int Main(string[] args)
        {
            NTrace.Info("NUnit-console.exe starting");

            ConsoleOptions options = new ConsoleOptions(args);

            if (!options.nologo)
            {
                WriteCopyright();
            }

            if (options.help)
            {
                options.Help();
                return(ConsoleUi.OK);
            }

            if (options.NoArgs)
            {
                Console.Error.WriteLine("fatal error: no inputs specified");
                options.Help();
                return(ConsoleUi.OK);
            }

            if (!options.Validate())
            {
                foreach (string arg in options.InvalidArguments)
                {
                    Console.Error.WriteLine("fatal error: invalid argument: {0}", arg);
                }
                options.Help();
                return(ConsoleUi.INVALID_ARG);
            }

            // Add Standard Services to ServiceManager
            ServiceManager.Services.AddService(new SettingsService());
            ServiceManager.Services.AddService(new DomainManager());
            //ServiceManager.Services.AddService( new RecentFilesService() );
            //ServiceManager.Services.AddService( new TestLoader() );
            ServiceManager.Services.AddService(new AddinRegistry());
            ServiceManager.Services.AddService(new AddinManager());
            // TODO: Resolve conflict with gui testagency when running
            // console tests under the gui.
            //ServiceManager.Services.AddService( new TestAgency() );

            // Initialize Services
            ServiceManager.Services.InitializeServices();

            try
            {
                ConsoleUi consoleUi = new ConsoleUi();
                return(consoleUi.Execute(options));
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                return(ConsoleUi.FILE_NOT_FOUND);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception:\n{0}", ex.ToString());
                return(ConsoleUi.UNEXPECTED_ERROR);
            }
            finally
            {
                if (options.wait)
                {
                    Console.Out.WriteLine("\nHit <enter> key to continue");
                    Console.ReadLine();
                }

                NTrace.Info("NUnit-console.exe terminating");
            }
        }
        internal static bool CreateTestFilter(ConsoleOptions options, out TestFilter testFilter)
        {
            testFilter = TestFilter.Empty;

            SimpleNameFilter nameFilter = new SimpleNameFilter();

            if (options.run != null && options.run != string.Empty)
            {
                Console.WriteLine("Selected test(s): " + options.run);

                foreach (string name in TestNameParser.Parse(options.run))
                {
                    nameFilter.Add(name);
                }

                testFilter = nameFilter;
            }

            if (options.runlist != null && options.runlist != string.Empty)
            {
                Console.WriteLine("Run list: " + options.runlist);

                try
                {
                    using (StreamReader rdr = new StreamReader(options.runlist))
                    {
                        // NOTE: We can't use rdr.EndOfStream because it's
                        // not present in .NET 1.x.
                        string line = rdr.ReadLine();
                        while (line != null && line.Length > 0)
                        {
                            if (line[0] != '#')
                            {
                                nameFilter.Add(line);
                            }
                            line = rdr.ReadLine();
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e is FileNotFoundException || e is DirectoryNotFoundException)
                    {
                        Console.WriteLine("Unable to locate file: " + options.runlist);
                        return(false);
                    }
                    throw;
                }

                testFilter = nameFilter;
            }

            if (options.include != null && options.include != string.Empty)
            {
                TestFilter includeFilter = new CategoryExpression(options.include).Filter;
                Console.WriteLine("Included categories: " + includeFilter.ToString());

                if (testFilter.IsEmpty)
                {
                    testFilter = includeFilter;
                }
                else
                {
                    testFilter = new AndFilter(testFilter, includeFilter);
                }
            }

            if (options.exclude != null && options.exclude != string.Empty)
            {
                TestFilter excludeFilter = new NotFilter(new CategoryExpression(options.exclude).Filter);
                Console.WriteLine("Excluded categories: " + excludeFilter.ToString());

                if (testFilter.IsEmpty)
                {
                    testFilter = excludeFilter;
                }
                else if (testFilter is AndFilter)
                {
                    ((AndFilter)testFilter).Add(excludeFilter);
                }
                else
                {
                    testFilter = new AndFilter(testFilter, excludeFilter);
                }
            }

            if (testFilter is NotFilter)
            {
                ((NotFilter)testFilter).TopLevel = true;
            }

            return(true);
        }
Exemple #8
0
        // This is public static for ease of testing
        public static TestPackage MakeTestPackage(ConsoleOptions options)
        {
            TestPackage package = new TestPackage(options.InputFiles);

            if (options.ProcessModel != null)//ProcessModel.Default)
            {
                package.Settings[PackageSettings.ProcessModel] = options.ProcessModel;
            }

            if (options.DomainUsage != null)
            {
                package.Settings[PackageSettings.DomainUsage] = options.DomainUsage;
            }

            if (options.Framework != null)
            {
                package.Settings[PackageSettings.RuntimeFramework] = options.Framework;
            }

            if (options.RunAsX86)
            {
                package.Settings[PackageSettings.RunAsX86] = true;
            }

            if (options.DisposeRunners)
            {
                package.Settings[PackageSettings.DisposeRunners] = true;
            }

            if (options.DefaultTimeout >= 0)
            {
                package.Settings[PackageSettings.DefaultTimeout] = options.DefaultTimeout;
            }

            if (options.InternalTraceLevel != null)
            {
                package.Settings[PackageSettings.InternalTraceLevel] = options.InternalTraceLevel;
            }

            if (options.ActiveConfig != null)
            {
                package.Settings[PackageSettings.ActiveConfig] = options.ActiveConfig;
            }

            if (options.WorkDirectory != null)
            {
                package.Settings[PackageSettings.WorkDirectory] = options.WorkDirectory;
            }

            if (options.StopOnError)
            {
                package.Settings[PackageSettings.StopOnError] = true;
            }

            if (options.NumWorkers > 0)
            {
                package.Settings[PackageSettings.NumberOfTestWorkers] = options.NumWorkers;
            }

            if (options.RandomSeed > 0)
            {
                package.Settings[PackageSettings.RandomSeed] = options.RandomSeed;
            }

            if (options.Verbose)
            {
                package.Settings["Verbose"] = true;
            }

#if DEBUG
            //foreach (KeyValuePair<string, object> entry in package.Settings)
            //    if (!(entry.Value is string || entry.Value is int || entry.Value is bool))
            //        throw new Exception(string.Format("Package setting {0} is not a valid type", entry.Key));
#endif

            return(package);
        }