From 600a4833c5a53058f7b420be794190b61f83dcce Mon Sep 17 00:00:00 2001 From: Tony Hallett Date: Thu, 18 Nov 2021 13:28:56 +0000 Subject: [PATCH 1/3] correct js report error that could occur. --- SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs index 2aee3be5..ee7a870b 100644 --- a/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs +++ b/SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs @@ -825,8 +825,11 @@ private string HackGroupingToAllowAll(int groupingLevel) { return $@" var customizeBox = document.getElementsByClassName('customizebox')[0]; - var groupingInput = customizeBox.querySelector('input'); - groupingInput.max = {groupingLevel}; + if(customizeBox){{ + var groupingInput = customizeBox.querySelector('input'); + groupingInput.max = {groupingLevel}; + }} + "; } From 15967991ab5ddb99c73c6679108a9ed4d54ae5fb Mon Sep 17 00:00:00 2001 From: Tony Hallett Date: Thu, 18 Nov 2021 13:29:29 +0000 Subject: [PATCH 2/3] allow for adjacent build output for relative paths in tests --- README.md | 5 ++-- SharedProject/Core/Model/CoverageProject.cs | 27 ++++++++++++++++++++- SharedProject/Options/AppOptions.cs | 4 +++ SharedProject/Options/IAppOptions.cs | 1 + 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b44708df..1c6a2c07 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ or download from [releases](https://github.com/FortuneN/FineCodeCoverage/release Prerequisites Only that the test adapters are nuget packages. For instance, the NUnit Test Adapter extension is not sufficient. -FCC will copy your test dll and dependencies to a sub folder this may affect your tests. +FCC will copy your test dll and dependencies to a sub folder this may affect your tests. The alternative is to set the option AdjacentBuildOutput to true. --------------------------------------- Introduction @@ -139,7 +139,8 @@ CoverletConsoleLocal Specify true to use your own dotnet tools local instal CoverletConsoleCustomPath Specify path to coverlet console exe if you need functionality that the FCC version does not provide. CoverletConsoleGlobal Specify true to use your own dotnet tools global install of coverlet console. -FCCSolutionOutputDirectoryName To have fcc output visible in a sub folder of your solution provide this name +FCCSolutionOutputDirectoryName To have fcc output visible in a sub folder of your solution provide this name +AdjacentBuildOutput If your tests are dependent upon their path set this to true. The "CoverletConsole" settings have precedence Local / CustomPath / Global. diff --git a/SharedProject/Core/Model/CoverageProject.cs b/SharedProject/Core/Model/CoverageProject.cs index ad3deecb..33f61c18 100644 --- a/SharedProject/Core/Model/CoverageProject.cs +++ b/SharedProject/Core/Model/CoverageProject.cs @@ -26,7 +26,32 @@ internal class CoverageProject : ICoverageProject private IAppOptions settings; private readonly string fccFolderName = "fine-code-coverage"; private readonly string buildOutputFolderName = "build-output"; - private string BuildOutputPath => Path.Combine(FCCOutputFolder, buildOutputFolderName); + private string buildOutputPath; + private string BuildOutputPath + { + get + { + if(buildOutputPath == null) + { + var adjacentBuildOutput = appOptionsProvider.Get().AdjacentBuildOutput; + if (adjacentBuildOutput) + { + // Net framework - Debug | Debug-NET45 + // SDK style - Debug/netcoreapp3.1 etc + var projectOutputDirectory = new DirectoryInfo(ProjectOutputFolder); + var projectOutputDirectoryName = projectOutputDirectory.Name; + var containingDirectoryPath = projectOutputDirectory.Parent.FullName; + buildOutputPath = Path.Combine(containingDirectoryPath, $"{fccFolderName}-{projectOutputDirectoryName}"); + } + else + { + buildOutputPath = Path.Combine(FCCOutputFolder, buildOutputFolderName); + } + } + return buildOutputPath; + + } + } private readonly string coverageToolOutputFolderName = "coverage-tool-output"; public CoverageProject(IAppOptionsProvider appOptionsProvider, IFileSynchronizationUtil fileSynchronizationUtil, ILogger logger, DTE dte, bool canUseMsBuildWorkspace) diff --git a/SharedProject/Options/AppOptions.cs b/SharedProject/Options/AppOptions.cs index cc8958d5..b979dc92 100644 --- a/SharedProject/Options/AppOptions.cs +++ b/SharedProject/Options/AppOptions.cs @@ -139,6 +139,10 @@ You can also ignore additional attributes by adding to this list (short name or [Category(outputCategory)] public string FCCSolutionOutputDirectoryName { get; set; } + [Description("If your tests are dependent upon their path set this to true.")] + [Category(outputCategory)] + public bool AdjacentBuildOutput { get; set; } + [Category(reportCategory)] [Description("When cyclomatic complexity exceeds this value for a method then the method will be present in the risk hotspots tab.")] public int ThresholdForCyclomaticComplexity { get; set; } = 30; diff --git a/SharedProject/Options/IAppOptions.cs b/SharedProject/Options/IAppOptions.cs index 875e111b..e8c02d1e 100644 --- a/SharedProject/Options/IAppOptions.cs +++ b/SharedProject/Options/IAppOptions.cs @@ -25,5 +25,6 @@ public interface IAppOptions bool StickyCoverageTable { get; } bool NamespacedClasses { get; } bool HideFullyCovered { get; } + bool AdjacentBuildOutput { get; } } } \ No newline at end of file From 53c5327bb39fd89e2266e3d5fbe1832ac9bc96cb Mon Sep 17 00:00:00 2001 From: Tony Hallett Date: Thu, 18 Nov 2021 13:47:53 +0000 Subject: [PATCH 3/3] add DefaultCoverageOutputFolder --- .../CoverageToolOutputManager_Tests.cs | 12 +++++++----- .../CoverageToolOutput/CoverageToolOutputManager.cs | 7 +++---- SharedProject/Core/Model/CoverageProject.cs | 6 +++--- SharedProject/Core/Model/ICoverageProject.cs | 1 + 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/FineCodeCoverageTests/CoverageToolOutput_Tests/CoverageToolOutputManager_Tests.cs b/FineCodeCoverageTests/CoverageToolOutput_Tests/CoverageToolOutputManager_Tests.cs index 8cc253c0..1db75f56 100644 --- a/FineCodeCoverageTests/CoverageToolOutput_Tests/CoverageToolOutputManager_Tests.cs +++ b/FineCodeCoverageTests/CoverageToolOutput_Tests/CoverageToolOutputManager_Tests.cs @@ -17,6 +17,7 @@ class CoverageToolOutputManager_Tests private Mock mockProject2; private List coverageProjects; private List callOrder; + private const string DefaultCoverageFolder = "defaultFolder"; [SetUp] public void SetUp() @@ -26,9 +27,11 @@ public void SetUp() mockProject1.Setup(p => p.FCCOutputFolder).Returns("p1output"); mockProject1.Setup(p => p.ProjectName).Returns("project1"); mockProject1.SetupProperty(p => p.CoverageOutputFolder); + mockProject1.Setup(p => p.DefaultCoverageOutputFolder).Returns(DefaultCoverageFolder); mockProject2 = new Mock(); mockProject2.Setup(p => p.FCCOutputFolder).Returns("p2output"); mockProject2.Setup(p => p.ProjectName).Returns("project2"); + mockProject2.Setup(p => p.DefaultCoverageOutputFolder).Returns(DefaultCoverageFolder); coverageProjects = new List { mockProject1.Object, mockProject2.Object }; } @@ -105,16 +108,15 @@ public void Should_Set_CoverageOutputFolder_To_ProjectName_Sub_Folder_Of_Provide } [Test] - public void Should_Set_CoverageOutputFolder_To_Sub_Folder_Of_CoverageProject_FCCOutputFolder_For_All_When_Not_Provided() + public void Should_Set_CoverageOutputFolder_To_Default_For_All_When_Not_Provided() { SetUpProviders(true, null, null); var coverageToolOutputManager = mocker.Create(); coverageToolOutputManager.SetProjectCoverageOutputFolder(coverageProjects); - var expectedProject1OutputFolder = Path.Combine(mockProject1.Object.FCCOutputFolder, "coverage-tool-output"); - var expectedProject2OutputFolder = Path.Combine(mockProject2.Object.FCCOutputFolder, "coverage-tool-output"); - mockProject1.VerifySet(p => p.CoverageOutputFolder = expectedProject1OutputFolder); - mockProject2.VerifySet(p => p.CoverageOutputFolder = expectedProject2OutputFolder); + + mockProject1.VerifySet(p => p.CoverageOutputFolder = DefaultCoverageFolder); + mockProject2.VerifySet(p => p.CoverageOutputFolder = DefaultCoverageFolder); } [Test] diff --git a/SharedProject/Core/CoverageToolOutput/CoverageToolOutputManager.cs b/SharedProject/Core/CoverageToolOutput/CoverageToolOutputManager.cs index 731d634c..f38efa27 100644 --- a/SharedProject/Core/CoverageToolOutput/CoverageToolOutputManager.cs +++ b/SharedProject/Core/CoverageToolOutput/CoverageToolOutputManager.cs @@ -13,7 +13,6 @@ internal class CoverageToolOutputManager : ICoverageToolOutputManager { private readonly ILogger logger; private readonly IFileUtil fileUtil; - private const string projectCoverageToolOutputFolderName = "coverage-tool-output"; private string outputFolderForAllProjects; private List coverageProjects; private readonly IOrderedEnumerable> outputFolderProviders; @@ -29,12 +28,12 @@ public CoverageToolOutputManager(IFileUtil fileUtil, ILogger logger,[ImportMany] public void SetProjectCoverageOutputFolder(List coverageProjects) { this.coverageProjects = coverageProjects; - DetermineOutputFolder(); + DetermineOutputFolderForAllProjects(); if (outputFolderForAllProjects == null) { foreach(var coverageProject in coverageProjects) { - coverageProject.CoverageOutputFolder = Path.Combine(coverageProject.FCCOutputFolder, projectCoverageToolOutputFolderName); + coverageProject.CoverageOutputFolder = coverageProject.DefaultCoverageOutputFolder; } } else @@ -49,7 +48,7 @@ public void SetProjectCoverageOutputFolder(List coverageProjec - private void DetermineOutputFolder() + private void DetermineOutputFolderForAllProjects() { outputFolderForAllProjects = outputFolderProviders.SelectFirstNonNull(p => p.Value.Provide(coverageProjects)); if(outputFolderForAllProjects != null) diff --git a/SharedProject/Core/Model/CoverageProject.cs b/SharedProject/Core/Model/CoverageProject.cs index 33f61c18..deca6e17 100644 --- a/SharedProject/Core/Model/CoverageProject.cs +++ b/SharedProject/Core/Model/CoverageProject.cs @@ -336,7 +336,7 @@ Process PropertyGroup settings } } public string CoverageOutputFolder { get; set; } - + public string DefaultCoverageOutputFolder => Path.Combine(FCCOutputFolder, coverageToolOutputFolderName); public XElement ProjectFileXElement { @@ -382,7 +382,7 @@ public async System.Threading.Tasks.Task StepAsync(string stepName, Func { buildOutputFolderName, coverageToolOutputFolderName }; var fccDirectory = new DirectoryInfo(FCCOutputFolder); diff --git a/SharedProject/Core/Model/ICoverageProject.cs b/SharedProject/Core/Model/ICoverageProject.cs index cfec5c08..95e4885d 100644 --- a/SharedProject/Core/Model/ICoverageProject.cs +++ b/SharedProject/Core/Model/ICoverageProject.cs @@ -11,6 +11,7 @@ internal interface ICoverageProject string FCCOutputFolder { get; } string CoverageOutputFile { get; } string CoverageOutputFolder { get; set; } + string DefaultCoverageOutputFolder { get; } List ExcludedReferencedProjects { get; } string FailureDescription { get; set; } string FailureStage { get; set; }