コード例 #1
0
        protected override void Run(object dataItem)
        {
            MessageHandler guiRun = delegate
            {
                var project = IdeApp.ProjectOperations.CurrentSelectedProject as DProject;
                if (project == null)
                {
                    return;
                }

                DProjectConfiguration conf = project.Configurations["Unittest"] as DProjectConfiguration;
                if (conf == null)
                {
                    return;
                }

                ProjectFile file = IdeApp.ProjectOperations.CurrentSelectedItem as ProjectFile;
                if (file == null)
                {
                    return;
                }

                string filePath = file.FilePath.FullPath;

                IdeApp.Workbench.SaveAll();

                if ((string)commandInfo.Command.Id == "MonoDevelop.D.Unittest.Commands.UnittestCommands.RunExternal")
                {
                    UnittestCore.RunExternal(filePath, project, conf);
                }
                else
                {
                    UnittestCore.Run(filePath, project, conf);
                }
            };

            DispatchService.GuiDispatch(guiRun);
        }
コード例 #2
0
        protected override void Run(object dataItem)
        {
            var doc = IdeApp.Workbench.ActiveDocument;
            var prj = doc.Project as AbstractDProject;

            if (prj == null)
            {
                return;
            }

            var monitor = Ide.IdeApp.Workbench.ProgressMonitors.GetOutputProgressMonitor("dunittests", "Run Unittest", MonoDevelop.Ide.Gui.Stock.RunProgramIcon, true, true);

            var pad = Ide.IdeApp.Workbench.ProgressMonitors.GetPadForMonitor(monitor);

            if (pad != null)
            {
                pad.BringToFront();
            }

            if (IdeApp.Preferences.BeforeBuildSaveAction != BeforeCompileAction.Nothing)               //TODO: Handle prompt for save.
            {
                foreach (var doc_ in new List <MonoDevelop.Ide.Gui.Document> (IdeApp.Workbench.Documents))
                {
                    if (doc_.IsDirty && doc_.Project != null)
                    {
                        doc_.Save();
                        if (doc_.IsDirty)
                        {
                            monitor.ReportError("Couldn't save document \"" + doc_.Name + "\"", new Exception());
                            return;
                        }
                    }
                }
            }

            monitor.BeginTask("Starting Unit Tests", 1);

            DispatchService.BackgroundDispatch(() => {
                try{
                    if (prj is DubProject)
                    {
                        DubBuilder.ExecuteProject(prj as DubProject, monitor,
                                                  new ExecutionContext(MonoDevelop.Core.Runtime.ProcessService.DefaultExecutionHandler, Ide.IdeApp.Workbench.ProgressMonitors, IdeApp.Workspace.ActiveExecutionTarget),
                                                  IdeApp.Workspace.ActiveConfiguration, "test");
                    }
                    else if (prj is DProject)
                    {
                        var dprj = prj as DProject;
                        var cfg  = dprj.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as DProjectConfiguration;

                        var cmd     = UnittestCore.ExtractCommand(UnittestSettings.UnittestCommand);
                        string args = UnittestCore.GetCommandArgs(UnittestSettings.UnittestCommand.Substring(cmd.Length + 1), doc.FileName, dprj, cfg);
                        string errorOutput;
                        string stdOutput;
                        string execDir = cfg.OutputDirectory.ToAbsolute(prj.BaseDirectory);

                        ProjectBuilder.ExecuteCommand(cmd, args, execDir, monitor, out stdOutput, out errorOutput);

                        monitor.Log.WriteLine(stdOutput);
                        monitor.Log.WriteLine(errorOutput);
                    }
                }
                catch (Exception ex)
                {
                    monitor.ReportError("Error during unit testing", ex);
                }
                finally
                {
                    monitor.Log.WriteLine("unittest done.");
                    monitor.EndTask();
                    monitor.Dispose();
                }
            });
        }