Пример #1
0
        public ProjectController(IProjectTreeModel projectTreeModel, IEventAggregator eventAggregator, IFileSystem fileSystem,
                                 IFileWatcher fileWatcher, IUnhandledExceptionPolicy unhandledExceptionPolicy, ITestProjectManager testProjectManager)
        {
            this.projectTreeModel         = projectTreeModel;
            this.eventAggregator          = eventAggregator;
            this.fileSystem               = fileSystem;
            this.fileWatcher              = fileWatcher;
            this.unhandledExceptionPolicy = unhandledExceptionPolicy;
            this.testProjectManager       = testProjectManager;

            TestFilters = new Observable <IList <FilterInfo> >(new List <FilterInfo>());
            TestFilters.PropertyChanged += (s, e) =>
            {
                if (updating)
                {
                    return;
                }

                projectTreeModel.TestProject.ClearTestFilters();
                GenericCollectionUtils.ForEach(TestFilters.Value, x =>
                                               projectTreeModel.TestProject.AddTestFilter(x));
            };

            fileWatcher.FileChangedEvent += delegate(string fullPath)
            {
                string fileName = Path.GetFileName(fullPath);
                EventHandlerPolicy.SafeInvoke(FileChanged, this, new FileChangedEventArgs(fileName));
            };
        }
Пример #2
0
        private RuntimeSetup CreateRuntimeSetup()
        {
            var runtimeSetup = new RuntimeSetup();

            GenericCollectionUtils.ForEach(Arguments.PluginDirectories, runtimeSetup.AddPluginDirectory);
            return(runtimeSetup);
        }
Пример #3
0
        /// <inheritdoc />
        protected override int RunImpl(string[] args)
        {
            if (!ParseArguments(args))
            {
                ShowHelp();
                return(1);
            }

            if (Arguments.Help)
            {
                ShowHelp();
                return(0);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var runtimeSetup = new RuntimeSetup();

            GenericCollectionUtils.ForEach(Arguments.PluginDirectories, x => runtimeSetup.AddPluginDirectory(x));

            ILogger logger = new FilteredLogger(new RichConsoleLogger(Console), Verbosity.Normal);

            using (RuntimeBootstrap.Initialize(runtimeSetup, logger))
            {
                IControlPanelPresenter presenter = RuntimeAccessor.Instance.ServiceLocator.Resolve <IControlPanelPresenter>();
                presenter.Show(null);
            }

            return(0);
        }
Пример #4
0
        protected override void ShowHelp()
        {
            // Show argument only help first because what we do next might take a little while
            // and we want to make the program appear responsive.
            base.ShowHelp();

            // Print out options related to the currently available set of plugins.
            var setup = new RuntimeSetup();

            if (Arguments != null && Arguments.PluginDirectories != null)
            {
                GenericCollectionUtils.ForEach(Arguments.PluginDirectories, x => setup.AddPluginDirectory(x));
            }

            using (RuntimeBootstrap.Initialize(setup, CreateLogger()))
            {
                IReportManager reportManager = RuntimeAccessor.ServiceLocator.Resolve <IReportManager>();
                ShowRegisteredComponents("Supported report types:", reportManager.FormatterHandles,
                                         h => h.GetTraits().Name, h => h.GetTraits().Description);

                ITestRunnerManager runnerManager = RuntimeAccessor.ServiceLocator.Resolve <ITestRunnerManager>();
                ShowRegisteredComponents("Supported runner types:", runnerManager.TestRunnerFactoryHandles,
                                         h => h.GetTraits().Name, h => h.GetTraits().Description);
            }
        }
Пример #5
0
        /// <inheritdoc />
        protected override int RunImpl(string[] args)
        {
            if (!ParseArguments(args))
            {
                ShowHelp();
                return(1);
            }

            if (Arguments.Help)
            {
                ShowHelp();
                return(0);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            UnhandledErrorPolicy();

            var runtimeSetup = new RuntimeSetup
            {
                RuntimePath = Path.GetDirectoryName(AssemblyUtils.GetFriendlyAssemblyLocation(
                                                        typeof(IcarusProgram).Assembly))
            };

            var runtimeLogger = new RuntimeLogger();

            GenericCollectionUtils.ForEach(Arguments.PluginDirectories, runtimeSetup.AddPluginDirectory);

            using (RuntimeBootstrap.Initialize(runtimeSetup, runtimeLogger))
            {
                // wire up services & components
                var scanner = new DefaultConventionScanner(RuntimeAccessor.Registry);
                scanner.Scan("Gallio.Icarus", Assembly.GetExecutingAssembly());

                LoadPackages();

                var optionsController = RuntimeAccessor.ServiceLocator.Resolve <IOptionsController>();

                // create & initialize a test runner whenever the test runner factory is changed
                optionsController.TestRunnerFactory.PropertyChanged += (s, e) =>
                                                                       ConfigureTestRunnerFactory(optionsController.TestRunnerFactory);

                ConfigureTestRunnerFactory(optionsController.TestRunnerFactory);

                var runtimeLogController = RuntimeAccessor.ServiceLocator.Resolve <IRuntimeLogController>();
                runtimeLogController.SetLogger(runtimeLogger);

                var applicationController = RuntimeAccessor.ServiceLocator.Resolve <IApplicationController>();
                applicationController.Arguments = Arguments;

                ErrorDialogUnhandledExceptionHandler.RunApplicationWithHandler(new Main(applicationController));

                UnloadPackages();
            }

            return(ResultCode.Success);
        }
Пример #6
0
        private void LoadProject(TestProject testProject, string projectLocation)
        {
            projectTreeModel.FileName    = projectLocation;
            projectTreeModel.TestProject = testProject;

            fileWatcher.Clear();
            GenericCollectionUtils.ForEach(testProject.TestPackage.Files, x => fileWatcher.Add(x.FullName));

            PublishUpdates();

            eventAggregator.Send(this, new ProjectLoaded(projectLocation));
        }
Пример #7
0
        /// <summary>
        /// Initializes a test project with the contents of this structure.
        /// </summary>
        /// <param name="testProject">The test project to populate.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testProject"/> is null.</exception>
        public void InitializeTestProject(TestProject testProject)
        {
            if (testProject == null)
            {
                throw new ArgumentNullException("testProject");
            }

            testPackage.InitializeTestPackage(testProject.TestPackage);
            GenericCollectionUtils.ForEach(testFilters, x => testProject.AddTestFilter(x));
            GenericCollectionUtils.ForEach(testRunnerExtensions, x => testProject.AddTestRunnerExtensionSpecification(x));
            testProject.ReportNameFormat = reportNameFormat;
            testProject.ReportDirectory  = reportDirectory;
        }
Пример #8
0
        /// <summary>
        /// Creates a host setup based on the package properties.
        /// </summary>
        /// <returns>The host setup.</returns>
        public HostSetup CreateHostSetup()
        {
            var hostSetup = new HostSetup
            {
                DebuggerSetup            = DebuggerSetup,
                ShadowCopy               = ShadowCopy,
                ApplicationBaseDirectory = ApplicationBaseDirectory != null ? ApplicationBaseDirectory.FullName : null,
                WorkingDirectory         = WorkingDirectory != null ? WorkingDirectory.FullName : null,
                RuntimeVersion           = RuntimeVersion
            };

            GenericCollectionUtils.ForEach(Properties, x => hostSetup.AddProperty(x.Key, x.Value));
            GenericCollectionUtils.ForEach(HintDirectories, x => hostSetup.AddHintDirectory(x.FullName));
            return(hostSetup);
        }
Пример #9
0
        public void AddFiles(IProgressMonitor progressMonitor, IList <string> files)
        {
            using (progressMonitor.BeginTask(Resources.AddingFiles, (files.Count + 2)))
            {
                var validFiles = GetValidFiles(progressMonitor, files);

                GenericCollectionUtils.ForEach(validFiles, x =>
                                               TestPackage.AddFile(new FileInfo(x)));

                projectTreeModel.NotifyTestProjectChanged();

                progressMonitor.Worked(1);
                fileWatcher.Add(validFiles);
            }
        }
Пример #10
0
        /// <summary>
        /// Initializes a test package with the contents of this structure.
        /// </summary>
        /// <param name="testPackage">The test package to populate.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testPackage"/> is null.</exception>
        public void InitializeTestPackage(TestPackage testPackage)
        {
            if (testPackage == null)
            {
                throw new ArgumentNullException("testPackage");
            }

            GenericCollectionUtils.ForEach(files, x => testPackage.AddFile(new FileInfo(x)));
            GenericCollectionUtils.ForEach(hintDirectories, x => testPackage.AddHintDirectory(new DirectoryInfo(x)));
            GenericCollectionUtils.ForEach(excludedFrameworkIds, x => testPackage.AddExcludedTestFrameworkId(x));
            testPackage.ShadowCopy               = ShadowCopy;
            testPackage.DebuggerSetup            = Debug ? new DebuggerSetup() : null;
            testPackage.ApplicationBaseDirectory = ApplicationBaseDirectory != null ? new DirectoryInfo(ApplicationBaseDirectory) : null;
            testPackage.WorkingDirectory         = WorkingDirectory != null ? new DirectoryInfo(WorkingDirectory) : null;
            testPackage.RuntimeVersion           = RuntimeVersion;
            GenericCollectionUtils.ForEach(Properties, x => testPackage.AddProperty(x.Key, x.Value));
        }
Пример #11
0
        private void Launch(bool doNoRun)
        {
            MarkupStreamWriter logStreamWriter = TestLog.Default;

            var launcher = new TestLauncher();

            launcher.TestProject.TestPackage = testPackage;
            launcher.Logger = new MarkupStreamLogger(logStreamWriter);
            launcher.TestExecutionOptions.FilterSet    = new FilterSet <ITestDescriptor>(new OrFilter <ITestDescriptor>(filters));
            launcher.TestProject.TestRunnerFactoryName = TestRunnerFactoryName;

            string reportDirectory = SpecialPathPolicy.For <SampleRunner>().GetTempDirectory().FullName;

            launcher.TestProject.ReportDirectory  = reportDirectory;
            launcher.TestProject.ReportNameFormat = "SampleRunnerReport";
            launcher.ReportFormatterOptions.AddProperty(@"SaveAttachmentContents", @"false");
            launcher.AddReportFormat(@"Text");
            // Disabled because the Xml can get really big and causes problems if the sample runner is used frequently.
            //launcher.AddReportFormat("Xml");

            launcher.DoNotRun = doNoRun;

            GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => launcher.TestRunnerOptions.AddProperty(x.Key, x.Value));

            using (logStreamWriter.BeginSection("Log Output"))
                result = launcher.Run();

            using (logStreamWriter.BeginSection("Text Report"))
            {
                foreach (string reportPath in result.ReportDocumentPaths)
                {
                    string extension = Path.GetExtension(reportPath);
                    if (extension == ".txt")
                    {
                        logStreamWriter.WriteLine(File.ReadAllText(reportPath));
                    }
                    else if (extension == ".xml")
                    {
                        logStreamWriter.Container.AttachXml(null, File.ReadAllText(reportPath));
                    }

                    File.Delete(reportPath);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Applies the settings of another test package as an overlay on top of this one.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Overrides scalar settings (such as <see cref="ApplicationBaseDirectory"/>) with those of
        /// the overlay when they are specified (such as when <see cref="IsApplicationBaseDirectorySpecified" /> is true).
        /// Merges aggregate settings (such as lists of files).
        /// </para>
        /// </remarks>
        /// <param name="overlay">The test package to overlay on top of this one.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="overlay"/> is null.</exception>
        public void ApplyOverlay(TestPackage overlay)
        {
            if (overlay == null)
            {
                throw new ArgumentNullException("overlay");
            }

            if (overlay.IsApplicationBaseDirectorySpecified)
            {
                ApplicationBaseDirectory = overlay.ApplicationBaseDirectory;
            }
            if (overlay.IsDebuggerSetupSpecified)
            {
                DebuggerSetup = overlay.DebuggerSetup;
            }
            if (overlay.IsRuntimeVersionSpecified)
            {
                RuntimeVersion = overlay.RuntimeVersion;
            }
            if (overlay.IsTestFrameworkOptionsSpecified)
            {
                TestFrameworkOptions = overlay.TestFrameworkOptions;
            }
            if (overlay.IsTestFrameworkFallbackModeSpecified)
            {
                TestFrameworkFallbackMode = overlay.TestFrameworkFallbackMode;
            }
            if (overlay.IsShadowCopySpecified)
            {
                ShadowCopy = overlay.ShadowCopy;
            }
            if (overlay.IsWorkingDirectorySpecified)
            {
                WorkingDirectory = overlay.WorkingDirectory;
            }

            GenericCollectionUtils.ForEach(overlay.Files, x => AddFile(x));
            GenericCollectionUtils.ForEach(overlay.HintDirectories, x => AddHintDirectory(x));
            GenericCollectionUtils.ForEach(overlay.ExcludedTestFrameworkIds, x => AddExcludedTestFrameworkId(x));
            GenericCollectionUtils.ForEach(overlay.Properties, x => properties[x.Key] = x.Value);
        }
Пример #13
0
        /// <summary>
        /// Creates a local host.
        /// </summary>
        /// <param name="hostSetup">The host setup.</param>
        /// <param name="logger">The logger for host message output.</param>
        /// <param name="debuggerManager">The debugger manager.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/>, <paramref name="logger"/>
        /// or <paramref name="debuggerManager"/> is null.</exception>
        public LocalHost(HostSetup hostSetup, ILogger logger, IDebuggerManager debuggerManager)
            : base(hostSetup, logger)
        {
            if (debuggerManager == null)
            {
                throw new ArgumentNullException("debuggerManager");
            }

            this.debuggerManager = debuggerManager;

            if (!string.IsNullOrEmpty(hostSetup.WorkingDirectory))
            {
                currentDirectorySwitcher = new CurrentDirectorySwitcher(hostSetup.WorkingDirectory);
            }

            if (hostSetup.HintDirectories.Count != 0)
            {
                assemblyLoader = new DefaultAssemblyLoader();
                GenericCollectionUtils.ForEach(hostSetup.HintDirectories, assemblyLoader.AddHintDirectory);
            }
        }
Пример #14
0
        /// <summary>
        /// Applies the settings of another test project as an overlay on top of this one.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Overrides scalar settings (such as <see cref="ReportNameFormat"/>) with those of
        /// the overlay when they are specified (such as when <see cref="IsReportNameFormatSpecified" /> is true).
        /// Merges aggregate settings (such as lists of files).
        /// </para>
        /// </remarks>
        /// <param name="overlay">The test project to overlay on top of this one.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="overlay"/> is null.</exception>
        public void ApplyOverlay(TestProject overlay)
        {
            if (overlay == null)
            {
                throw new ArgumentNullException("overlay");
            }

            if (overlay.IsReportNameFormatSpecified)
            {
                ReportNameFormat = overlay.ReportNameFormat;
            }
            if (overlay.IsReportDirectorySpecified)
            {
                ReportDirectory = overlay.ReportDirectory;
            }
            if (overlay.IsTestRunnerFactoryNameSpecified)
            {
                TestRunnerFactoryName = overlay.TestRunnerFactoryName;
            }
            GenericCollectionUtils.ForEach(overlay.TestFilters, x => AddTestFilter(x.Copy()));
            GenericCollectionUtils.ForEach(overlay.TestRunnerExtensions, AddTestRunnerExtension);
            GenericCollectionUtils.ForEach(overlay.TestRunnerExtensionSpecifications, AddTestRunnerExtensionSpecification);
            TestPackage.ApplyOverlay(overlay.TestPackage);
        }
Пример #15
0
 /// <summary>
 /// Clears the list of test parameters.
 /// </summary>
 public void ClearParameters()
 {
     GenericCollectionUtils.ForEach(Parameters, x => x.Owner = null);
     parameters = null;
 }
Пример #16
0
 /// <summary>
 /// Clears the list of children.
 /// </summary>
 public void ClearChildren()
 {
     GenericCollectionUtils.ForEach(Children, x => x.Parent = null);
     children = null;
 }
Пример #17
0
        /// <inheritdoc />
        public void Initialize(TestRunnerOptions testRunnerOptions, ILogger logger, IProgressMonitor progressMonitor)
        {
            if (testRunnerOptions == null)
            {
                throw new ArgumentNullException("testRunnerOptions");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (progressMonitor == null)
            {
                throw new ArgumentNullException("progressMonitor");
            }

            ThrowIfDisposed();
            if (state != State.Created)
            {
                throw new InvalidOperationException("The test runner has already been initialized.");
            }

            testRunnerOptions = testRunnerOptions.Copy();

            this.testRunnerOptions = testRunnerOptions;
            tappedLogger           = new TappedLogger(this, logger);

            int extensionCount = extensions.Count;

            using (progressMonitor.BeginTask("Initializing the test runner.", 1 + extensionCount))
            {
                foreach (ITestRunnerExtension extension in extensions)
                {
                    string extensionName = extension.GetType().Name; // TODO: improve me

                    progressMonitor.SetStatus(String.Format("Installing extension '{0}'.", extensionName));
                    try
                    {
                        // Note: We don't pass the tapped logger to the extensions because the
                        //       extensions frequently write to the console a bunch of information we
                        //       already have represented in the report.  We are more interested in what
                        //       the test driver has to tell us.
                        extension.Install(eventDispatcher, logger);
                        progressMonitor.Worked(1);
                    }
                    catch (Exception ex)
                    {
                        throw new RunnerException(String.Format("Failed to install extension '{0}'.", extensionName), ex);
                    }
                    progressMonitor.SetStatus("");
                }

                try
                {
                    UnhandledExceptionPolicy.ReportUnhandledException += OnUnhandledException;

                    eventDispatcher.NotifyInitializeStarted(new InitializeStartedEventArgs(testRunnerOptions));

                    progressMonitor.SetStatus("Initializing the test isolation context.");

                    TestIsolationOptions testIsolationOptions = new TestIsolationOptions();
                    GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testIsolationOptions.AddProperty(x.Key, x.Value));
                    testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, tappedLogger);

                    progressMonitor.Worked(1);
                }
                catch (Exception ex)
                {
                    eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(false));

                    UnhandledExceptionPolicy.ReportUnhandledException -= OnUnhandledException;

                    throw new RunnerException("A fatal exception occurred while initializing the test isolation context.", ex);
                }

                state = State.Initialized;
                eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(true));
            }
        }
Пример #18
0
        /// <inheritdoc />
        public Report Run(TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IProgressMonitor progressMonitor)
        {
            if (testPackage == null)
            {
                throw new ArgumentNullException("testPackageConfig");
            }
            if (testExplorationOptions == null)
            {
                throw new ArgumentNullException("testExplorationOptions");
            }
            if (testExecutionOptions == null)
            {
                throw new ArgumentNullException("testExecutionOptions");
            }
            if (progressMonitor == null)
            {
                throw new ArgumentNullException("progressMonitor");
            }

            ThrowIfDisposed();
            if (state != State.Initialized)
            {
                throw new InvalidOperationException("The test runner must be initialized before this operation is performed.");
            }

            testPackage            = testPackage.Copy();
            testExplorationOptions = testExplorationOptions.Copy();
            testExecutionOptions   = testExecutionOptions.Copy();
            GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testPackage.AddProperty(x.Key, x.Value));

            using (progressMonitor.BeginTask("Running the tests.", 10))
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                Report    report    = new Report()
                {
                    TestPackage    = new TestPackageData(testPackage),
                    TestModel      = new TestModelData(),
                    TestPackageRun = new TestPackageRun()
                    {
                        StartTime = DateTime.Now
                    }
                };
                var reportLockBox = new LockBox <Report>(report);

                eventDispatcher.NotifyRunStarted(new RunStartedEventArgs(testPackage, testExplorationOptions,
                                                                         testExecutionOptions, reportLockBox));

                bool success;
                using (Listener listener = new Listener(eventDispatcher, tappedLogger, reportLockBox))
                {
                    try
                    {
                        ITestDriver testDriver = testFrameworkManager.GetTestDriver(
                            testPackage.CreateTestFrameworkSelector(), tappedLogger);

                        using (testIsolationContext.BeginBatch(progressMonitor.SetStatus))
                        {
                            testDriver.Run(testIsolationContext, testPackage, testExplorationOptions,
                                           testExecutionOptions, listener, progressMonitor.CreateSubProgressMonitor(10));
                        }

                        success = true;
                    }
                    catch (Exception ex)
                    {
                        success = false;

                        tappedLogger.Log(LogSeverity.Error,
                                         "A fatal exception occurred while running tests.  Possible causes include invalid test runner parameters and stack overflows.",
                                         ex);
                        report.TestModel.Annotations.Add(new AnnotationData(AnnotationType.Error,
                                                                            CodeLocation.Unknown, CodeReference.Unknown,
                                                                            "A fatal exception occurred while running tests.  See log for details.", null));
                    }
                    finally
                    {
                        report.TestPackageRun.EndTime             = DateTime.Now;
                        report.TestPackageRun.Statistics.Duration = stopwatch.Elapsed.TotalSeconds;
                    }
                }

                eventDispatcher.NotifyRunFinished(new RunFinishedEventArgs(success, report));

                return(report);
            }
        }
Пример #19
0
        /// <inheritdoc />
        protected override int RunImpl(string[] args)
        {
            ShowBanner();
            InstallCancelHandler();

            if (!ParseArguments(args) || Arguments.CommandAndArguments.Length == 0)
            {
                ShowHelp();
                return(Arguments.Help ? 0 : 1);
            }

            ILogger logger = CreateLogger();
            IProgressMonitorProvider progressMonitorProvider = Arguments.NoProgress
                ? (IProgressMonitorProvider)NullProgressMonitorProvider.Instance
                : new RichConsoleProgressMonitorProvider(Console);

            string commandName = Arguments.CommandAndArguments[0];

            string[] commandRawArguments = new string[Arguments.CommandAndArguments.Length - 1];
            Array.Copy(Arguments.CommandAndArguments, 1, commandRawArguments, 0, commandRawArguments.Length);
            IUtilityCommand command          = GetSpecialCommand(commandName);
            bool            isSpecialCommand = command != null;
            var             runtimeSetup     = new RuntimeSetup();

            GenericCollectionUtils.ForEach(Arguments.PluginDirectories, x => runtimeSetup.AddPluginDirectory(x));

            using (isSpecialCommand ? null : RuntimeBootstrap.Initialize(runtimeSetup, logger))
            {
                if (command == null)
                {
                    var commandManager = RuntimeAccessor.ServiceLocator.Resolve <IUtilityCommandManager>();
                    command = commandManager.GetCommand(commandName);

                    if (command == null)
                    {
                        ShowErrorMessage(string.Format("Unrecognized utility command name: '{0}'.", commandName));
                        ShowHelp();
                        return(1);
                    }
                }

                Type commandArgumentsClass = command.GetArgumentClass();
                var  commandArgumentParser = new CommandLineArgumentParser(commandArgumentsClass, null);

                if (Arguments.Help)
                {
                    ShowHelpForParticularCommand(commandName, commandArgumentParser);
                    return(0);
                }

                object commandArguments = Activator.CreateInstance(commandArgumentsClass);

                if (!commandArgumentParser.Parse(commandRawArguments, commandArguments, ShowErrorMessage) || !command.ValidateArguments(commandArguments, ShowErrorMessage))
                {
                    ShowHelpForParticularCommand(commandName, commandArgumentParser);
                    return(1);
                }

                var commandContext = new UtilityCommandContext(commandArguments, Console, logger, progressMonitorProvider, Arguments.Verbosity);
                return(command.Execute(commandContext));
            }
        }
Пример #20
0
        internal static void ConfigureLauncherFromArguments(TestLauncher launcher, EchoArguments arguments)
        {
            launcher.RuntimeSetup = new RuntimeSetup();
            GenericCollectionUtils.ForEach(arguments.PluginDirectories, x => launcher.RuntimeSetup.AddPluginDirectory(x));

            if (arguments.ShadowCopy.HasValue)
            {
                launcher.TestProject.TestPackage.ShadowCopy = arguments.ShadowCopy.Value;
            }

            if (arguments.Debug.HasValue && arguments.Debug.Value)
            {
                launcher.TestProject.TestPackage.DebuggerSetup = new DebuggerSetup();
            }

            if (arguments.ApplicationBaseDirectory != null)
            {
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(arguments.ApplicationBaseDirectory);
            }

            if (arguments.WorkingDirectory != null)
            {
                launcher.TestProject.TestPackage.WorkingDirectory = new DirectoryInfo(arguments.WorkingDirectory);
            }

            if (arguments.RuntimeVersion != null)
            {
                launcher.TestProject.TestPackage.RuntimeVersion = arguments.RuntimeVersion;
            }

            GenericCollectionUtils.ForEach(arguments.Files, launcher.AddFilePattern);

            foreach (string hintDirectory in arguments.HintDirectories)
            {
                launcher.TestProject.TestPackage.AddHintDirectory(new DirectoryInfo(hintDirectory));
            }

            if (arguments.ReportDirectory != null)
            {
                launcher.TestProject.ReportDirectory = arguments.ReportDirectory;
            }

            if (arguments.ReportNameFormat != null)
            {
                launcher.TestProject.ReportNameFormat = arguments.ReportNameFormat;
            }

            launcher.TestProject.ReportArchive = ReportArchive.Parse(arguments.ReportArchive);
            GenericCollectionUtils.ForEach(arguments.ReportTypes, launcher.AddReportFormat);

            if (arguments.RunnerType != null)
            {
                launcher.TestProject.TestRunnerFactoryName = arguments.RunnerType;
            }
            GenericCollectionUtils.ForEach(arguments.RunnerExtensions, x => launcher.TestProject.AddTestRunnerExtensionSpecification(x));

            foreach (string option in arguments.ReportFormatterProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.ReportFormatterOptions.AddProperty(pair.Key, pair.Value);
            }

            foreach (string option in arguments.RunnerProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.TestRunnerOptions.AddProperty(pair.Key, pair.Value);
            }

            launcher.DoNotRun          = arguments.DoNotRun;
            launcher.IgnoreAnnotations = arguments.IgnoreAnnotations;

            if (!String.IsNullOrEmpty(arguments.Filter))
            {
                launcher.TestExecutionOptions.FilterSet = FilterUtils.ParseTestFilterSet(arguments.Filter);
            }

            launcher.EchoResults = !arguments.NoEchoResults;
            launcher.ShowReports = arguments.ShowReports;

            if (arguments.RunTimeLimitInSeconds >= 0)
            {
                launcher.RunTimeLimit = TimeSpan.FromSeconds(arguments.RunTimeLimitInSeconds);
            }
        }
Пример #21
0
        internal void InternalExecute()
        {
            // We don't catch exceptions here because NAnt takes care of that job,
            // and decides whether to let them through based on the value of the
            // FailOnError
            var logger = CreateLogger();

            DisplayVersion();
            var launcher = new TestLauncher();

            launcher.Logger = logger;
            launcher.ProgressMonitorProvider        = new LogProgressMonitorProvider(logger);
            launcher.TestExecutionOptions.FilterSet = GetFilterSet();
            launcher.ShowReports       = ShowReports;
            launcher.DoNotRun          = DoNotRun;
            launcher.IgnoreAnnotations = IgnoreAnnotations;
            launcher.EchoResults       = EchoResults;
            launcher.RunTimeLimit      = runTimeLimit;

            if (RunnerType != null)
            {
                launcher.TestProject.TestRunnerFactoryName = RunnerType;
            }

            if (RunnerExtensions != null)
            {
                foreach (Argument arg in RunnerExtensions)
                {
                    launcher.TestProject.AddTestRunnerExtensionSpecification(arg.Value);
                }
            }

            launcher.RuntimeSetup = new RuntimeSetup();

            // Set the installation path explicitly to the path of the NAnt task assembly
            // since otherwise we will look at the path of NAnt.exe.
            launcher.RuntimeSetup.RuntimePath = Path.GetDirectoryName(AssemblyUtils.GetFriendlyAssemblyLocation(typeof(GallioTask).Assembly));

            if (ApplicationBaseDirectory != null)
            {
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(ApplicationBaseDirectory);
            }
            if (WorkingDirectory != null)
            {
                launcher.TestProject.TestPackage.WorkingDirectory = new DirectoryInfo(WorkingDirectory);
            }
            if (ShadowCopy.HasValue)
            {
                launcher.TestProject.TestPackage.ShadowCopy = ShadowCopy.Value;
            }
            if (Debug.HasValue && Debug.Value)
            {
                launcher.TestProject.TestPackage.DebuggerSetup = new DebuggerSetup();
            }
            if (RuntimeVersion != null)
            {
                launcher.TestProject.TestPackage.RuntimeVersion = RuntimeVersion;
            }

            foreach (Argument option in ReportFormatterProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option.Value);
                launcher.ReportFormatterOptions.AddProperty(pair.Key, pair.Value);
            }

            foreach (Argument option in RunnerProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option.Value);
                launcher.TestRunnerOptions.AddProperty(pair.Key, pair.Value);
            }

            AddAssemblies(launcher);
            AddHintDirectories(launcher);
            AddPluginDirectories(launcher);

            if (ReportDirectory != null)
            {
                launcher.TestProject.ReportDirectory = ReportDirectory;
            }
            if (ReportNameFormat != null)
            {
                launcher.TestProject.ReportNameFormat = ReportNameFormat;
            }
            if (ReportArchive != null)
            {
                launcher.TestProject.ReportArchive = Runner.Reports.ReportArchive.Parse(ReportArchive);
            }

            if (ReportTypes != null)
            {
                string[] typeNames = ReportTypes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                GenericCollectionUtils.ForEach(typeNames, launcher.AddReportFormat);
            }

            TestLauncherResult result = RunLauncher(launcher);

            SetResultProperty(result.ResultCode);
            PopulateStatistics(result);

            if (!FailOnError)
            {
                return;
            }

            if (result.ResultCode != ResultCode.Success && result.ResultCode != ResultCode.NoTests)
            {
                // The only way to make the task fail is to throw an exception
                throw new BuildException(Resources.TestExecutionFailed);
            }
        }
Пример #22
0
        internal bool InternalExecute()
        {
            DisplayVersion();
            var logger   = new FilteredLogger(new TaskLogger(Log), verbosity);
            var launcher = new TestLauncher();

            launcher.Logger = logger;
            launcher.ProgressMonitorProvider        = new LogProgressMonitorProvider(logger);
            launcher.TestExecutionOptions.FilterSet = GetFilterSet();
            launcher.ShowReports       = ShowReports;
            launcher.DoNotRun          = DoNotRun;
            launcher.IgnoreAnnotations = IgnoreAnnotations;
            launcher.RunTimeLimit      = runTimeLimit;
            launcher.RuntimeSetup      = new RuntimeSetup();

            // Set the installation path explicitly to the path of the MSBuild task assembly
            // since otherwise we will look at the path of MSBuild.exe.
            launcher.RuntimeSetup.RuntimePath = Path.GetDirectoryName(AssemblyUtils.GetFriendlyAssemblyLocation(typeof(Gallio).Assembly));

            if (EchoResults)
            {
                launcher.TestProject.AddTestRunnerExtension(new TaskLogExtension(Log));
            }
            if (ApplicationBaseDirectory != null)
            {
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(ApplicationBaseDirectory.ItemSpec);
            }
            if (WorkingDirectory != null)
            {
                launcher.TestProject.TestPackage.WorkingDirectory = new DirectoryInfo(WorkingDirectory.ItemSpec);
            }
            launcher.TestProject.TestPackage.ShadowCopy = ShadowCopy;
            if (Debug)
            {
                launcher.TestProject.TestPackage.DebuggerSetup = new DebuggerSetup();
            }
            if (RuntimeVersion != null)
            {
                launcher.TestProject.TestPackage.RuntimeVersion = RuntimeVersion;
            }

            foreach (string option in ReportFormatterProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.ReportFormatterOptions.AddProperty(pair.Key, pair.Value);
            }

            foreach (string option in RunnerProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.TestRunnerOptions.AddProperty(pair.Key, pair.Value);
            }

            ForEachItemSpec(Files, launcher.AddFilePattern);
            ForEachItemSpec(HintDirectories, x => launcher.TestProject.TestPackage.AddHintDirectory(new DirectoryInfo(x)));
            ForEachItemSpec(PluginDirectories, x => launcher.RuntimeSetup.AddPluginDirectory(x));

            if (ReportDirectory != null)
            {
                launcher.TestProject.ReportDirectory = ReportDirectory.ItemSpec;
            }
            if (ReportNameFormat != null)
            {
                launcher.TestProject.ReportNameFormat = ReportNameFormat;
            }
            if (ReportTypes != null)
            {
                GenericCollectionUtils.ForEach(ReportTypes, launcher.AddReportFormat);
            }
            if (ReportArchive != null)
            {
                launcher.TestProject.ReportArchive = Runner.Reports.ReportArchive.Parse(ReportArchive);
            }
            if (RunnerType != null)
            {
                launcher.TestProject.TestRunnerFactoryName = RunnerType;
            }
            if (RunnerExtensions != null)
            {
                GenericCollectionUtils.ForEach(RunnerExtensions, x => launcher.TestProject.AddTestRunnerExtensionSpecification(x));
            }

            TestLauncherResult result = RunLauncher(launcher);

            ExitCode = result.ResultCode;
            LogResultSummary(logger, result);
            PopulateStatistics(result);
            return(ExitCode == ResultCode.Success ||
                   ExitCode == ResultCode.NoTests ||
                   IgnoreFailures);
        }
Пример #23
0
        internal TestLauncherResult Execute()
        {
            var launcher = new TestLauncher
            {
                Logger = Logger,
                ProgressMonitorProvider = ProgressMonitorProvider,
                TestExecutionOptions    = { FilterSet = GetFilterSet() },
                ShowReports             = ShowReports.IsPresent,
                DoNotRun          = DoNotRun.IsPresent,
                IgnoreAnnotations = IgnoreAnnotations.IsPresent,
                EchoResults       = !NoEchoResults.IsPresent,
                RunTimeLimit      = runTimeLimit
            };

            if (RunnerType != null)
            {
                launcher.TestProject.TestRunnerFactoryName = RunnerType;
            }
            if (RunnerExtensions != null)
            {
                GenericCollectionUtils.ForEach(RunnerExtensions, x => launcher.TestProject.AddTestRunnerExtensionSpecification(x));
            }

            launcher.RuntimeSetup = new RuntimeSetup();

            // Set the installation path explicitly to the path of the Gallio cmdlet task assembly
            // since otherwise we will look at the path of PowerShell.exe.
            launcher.RuntimeSetup.RuntimePath = Path.GetDirectoryName(AssemblyUtils.GetFriendlyAssemblyLocation(typeof(RunGallioCommand).Assembly));

            if (ApplicationBaseDirectory != null)
            {
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(ApplicationBaseDirectory);
            }
            if (WorkingDirectory != null)
            {
                launcher.TestProject.TestPackage.WorkingDirectory = new DirectoryInfo(WorkingDirectory);
            }
            if (ShadowCopy.HasValue)
            {
                launcher.TestProject.TestPackage.ShadowCopy = ShadowCopy.Value.IsPresent;
            }
            if (DebugTests.HasValue && DebugTests.Value.IsPresent)
            {
                launcher.TestProject.TestPackage.DebuggerSetup = new DebuggerSetup();
            }
            if (RuntimeVersion != null)
            {
                launcher.TestProject.TestPackage.RuntimeVersion = RuntimeVersion;
            }

            foreach (string option in ReportFormatterProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.ReportFormatterOptions.AddProperty(pair.Key, pair.Value);
            }

            foreach (string option in RunnerProperties)
            {
                KeyValuePair <string, string> pair = StringUtils.ParseKeyValuePair(option);
                launcher.TestRunnerOptions.AddProperty(pair.Key, pair.Value);
            }

            ForEachItem(Files, launcher.AddFilePattern);
            ForEachItem(HintDirectories, x => launcher.TestProject.TestPackage.AddHintDirectory(new DirectoryInfo(x)));
            ForEachItem(PluginDirectories, x => launcher.RuntimeSetup.AddPluginDirectory(x));

            if (ReportDirectory != null)
            {
                launcher.TestProject.ReportDirectory = ReportDirectory;
            }
            if (ReportNameFormat != null)
            {
                launcher.TestProject.ReportNameFormat = ReportNameFormat;
            }
            if (ReportTypes != null)
            {
                GenericCollectionUtils.ForEach(ReportTypes, launcher.AddReportFormat);
            }
            launcher.TestProject.ReportArchive = Runner.Reports.ReportArchive.Parse(ReportArchive);
            TestLauncherResult result = RunLauncher(launcher);

            return(result);
        }