Exemplo n.º 1
0
        public static void ReloadCoverage(IEnumerable <CoverageProject> projects, bool darkMode)
        {
            // reset

            ClearProcesses();

            HtmlFilePath = null;

            CoverageLines.Clear();

            // process pipeline

            projects = projects
                       .Select(project =>
            {
                project.ProjectFileXElement = XElementUtil.Load(project.ProjectFile, true);
                project.Settings            = GetSettings(project);

                if (!project.Settings.Enabled)
                {
                    project.FailureDescription = $"Disabled";
                    return(project);
                }

                if (string.IsNullOrWhiteSpace(project.ProjectFile))
                {
                    project.FailureDescription = $"Unsupported project type for DLL '{project.TestDllFile}'";
                    return(project);
                }

                project.CoverageOutputFolder = Path.Combine(project.ProjectOutputFolder, "fine-code-coverage");
                project.CoverageOutputFile   = Path.Combine(project.CoverageOutputFolder, "project.coverage.xml");
                project.IsDotNetSdkStyle     = IsDotNetSdkStyle(project);
                project.ReferencedProjects   = GetReferencedProjects(project);
                project.HasExcludeFromCodeCoverageAssemblyAttribute = HasExcludeFromCodeCoverageAssemblyAttribute(project.ProjectFileXElement);
                project.AssemblyName = GetAssemblyName(project.ProjectFileXElement, Path.GetFileNameWithoutExtension(project.ProjectFile));

                project.EnsureEmptyOutputFolder();

                try
                {
                    var legacyOutputFolder = Path.Combine(project.ProjectOutputFolder, "_outputFolder");
                    Directory.Delete(legacyOutputFolder, true);
                }
                catch
                {
                    // ignore
                }

                return(project);
            })
                       .Select(p => p.Step("Run Coverage Tool", project =>
            {
                // run the appropriate cover tool

                if (project.IsDotNetSdkStyle)
                {
                    CoverletUtil.RunCoverlet(project, true);
                }
                else
                {
                    OpenCoverUtil.RunOpenCover(project, true);
                }
            }))
                       .Where(x => !x.HasFailed)
                       .ToArray();

            // project files

            var coverOutputFiles = projects
                                   .Select(x => x.CoverageOutputFile)
                                   .ToArray();

            if (!coverOutputFiles.Any())
            {
                return;
            }

            // run reportGenerator process

            ReportGeneratorUtil.RunReportGenerator(coverOutputFiles, darkMode, out var unifiedHtmlFile, out var unifiedXmlFile, true);

            // update CoverageLines

            CoverageReport = CoberturaUtil.ProcessCoberturaXmlFile(unifiedXmlFile, out var coverageLines);
            CoverageLines  = coverageLines;

            // update HtmlFilePath

            ReportGeneratorUtil.ProcessUnifiedHtmlFile(unifiedHtmlFile, darkMode, out var coverageHtml);
            HtmlFilePath = coverageHtml;
        }
Exemplo n.º 2
0
        public static void ReloadCoverage(IEnumerable <CoverageProject> projects, bool darkMode)
        {
            // reset

            ClearProcesses();

            HtmlFilePath = null;

            CoverageLines.Clear();

            // process pipeline

            projects = projects
                       .Select(project =>
            {
                project.Settings = GetSettings(project);

                if (!project.Settings.Enabled)
                {
                    project.FailureDescription = $"Disabled";
                    return(project);
                }

                if (string.IsNullOrWhiteSpace(project.ProjectFile))
                {
                    project.FailureDescription = $"Unsupported project type for DLL '{project.TestDllFileInOutputFolder}'";
                    return(project);
                }

                project.WorkOutputFolder        = Path.Combine(project.WorkFolder, "_outputfolder");
                project.CoverToolOutputFile     = Path.Combine(project.WorkOutputFolder, "_cover.tool.xml");
                project.TestDllFileInWorkFolder = Path.Combine(project.WorkFolder, Path.GetFileName(project.TestDllFileInOutputFolder));
                project.IsDotNetSdkStyle        = IsDotNetSdkStyle(project);

                return(project);
            })
                       .Select(p => p.Step("Ensure Work Folder Exists", project =>
            {
                // create folders

                var logs = new List <string>();

                if (!Directory.Exists(project.WorkFolder))
                {
                    Directory.CreateDirectory(project.WorkFolder);
                    logs.Add($"Created : {project.WorkFolder}");
                }

                if (!Directory.Exists(project.WorkOutputFolder))
                {
                    Directory.CreateDirectory(project.WorkOutputFolder);
                    logs.Add($"Created : {project.WorkOutputFolder}");
                }

                //Logger.LogWithoutTitle(logs);
            }))
                       .Select(p => p.Step("Synchronize Output Files To Work Folder", project =>
            {
                // sync files from output folder to work folder where we do the analysis

                var logs = FileSynchronizationUtil.Synchronize(project.ProjectOutputFolder, project.WorkFolder);

                //Logger.LogWithoutTitle(logs);
            }))
                       .Select(p => p.Step("Run Coverage Tool", project =>
            {
                // run the appropriate cover tool

                if (project.IsDotNetSdkStyle)
                {
                    CoverletUtil.RunCoverlet(project, true);
                }
                else
                {
                    OpenCoverUtil.RunOpenCover(project, true);
                }
            }))
                       .Where(x => !x.HasFailed)
                       .ToArray();

            // project files

            var coverOutputFiles = projects
                                   .Select(x => x.CoverToolOutputFile)
                                   .ToArray();

            if (!coverOutputFiles.Any())
            {
                return;
            }

            // run reportGenerator process

            ReportGeneratorUtil.RunReportGenerator(coverOutputFiles, darkMode, out var unifiedHtmlFile, out var unifiedXmlFile, true);

            // update CoverageLines

            CoberturaUtil.ProcessCoberturaXmlFile(unifiedXmlFile, out var coverageLines);
            CoverageLines = coverageLines;

            // update HtmlFilePath

            ReportGeneratorUtil.ProcessCoberturaHtmlFile(unifiedHtmlFile, darkMode, out var coverageHtml);
            HtmlFilePath = coverageHtml;
        }