Skip to content

Commit

Permalink
Merge pull request #208 from tonyhallett/adjacent-fcc-build-output-di…
Browse files Browse the repository at this point in the history
…rectory

Adjacent fcc build output directory
  • Loading branch information
tonyhallett authored Nov 18, 2021
2 parents 58f8acd + 53c5327 commit bce7a33
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CoverageToolOutputManager_Tests
private Mock<ICoverageProject> mockProject2;
private List<ICoverageProject> coverageProjects;
private List<int> callOrder;
private const string DefaultCoverageFolder = "defaultFolder";

[SetUp]
public void SetUp()
Expand All @@ -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<ICoverageProject>();
mockProject2.Setup(p => p.FCCOutputFolder).Returns("p2output");
mockProject2.Setup(p => p.ProjectName).Returns("project2");
mockProject2.Setup(p => p.DefaultCoverageOutputFolder).Returns(DefaultCoverageFolder);
coverageProjects = new List<ICoverageProject> { mockProject1.Object, mockProject2.Object };
}

Expand Down Expand Up @@ -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>();
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]
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICoverageProject> coverageProjects;
private readonly IOrderedEnumerable<Lazy<ICoverageToolOutputFolderProvider, IOrderMetadata>> outputFolderProviders;
Expand All @@ -29,12 +28,12 @@ public CoverageToolOutputManager(IFileUtil fileUtil, ILogger logger,[ImportMany]
public void SetProjectCoverageOutputFolder(List<ICoverageProject> 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
Expand All @@ -49,7 +48,7 @@ public void SetProjectCoverageOutputFolder(List<ICoverageProject> coverageProjec



private void DetermineOutputFolder()
private void DetermineOutputFolderForAllProjects()
{
outputFolderForAllProjects = outputFolderProviders.SelectFirstNonNull(p => p.Value.Provide(coverageProjects));
if(outputFolderForAllProjects != null)
Expand Down
33 changes: 29 additions & 4 deletions SharedProject/Core/Model/CoverageProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -311,7 +336,7 @@ Process PropertyGroup settings
}
}
public string CoverageOutputFolder { get; set; }

public string DefaultCoverageOutputFolder => Path.Combine(FCCOutputFolder, coverageToolOutputFolderName);

public XElement ProjectFileXElement
{
Expand Down Expand Up @@ -357,7 +382,7 @@ public async System.Threading.Tasks.Task StepAsync(string stepName, Func<ICovera
public async System.Threading.Tasks.Task PrepareForCoverageAsync()
{
EnsureDirectories();
CleanDirectory();
CleanFCCDirectory();
SynchronizeBuildOutput();
await SetExcludedReferencedProjectsAsync();
}
Expand Down Expand Up @@ -535,7 +560,7 @@ private void EnsureEmptyOutputFolder()
Directory.CreateDirectory(CoverageOutputFolder);
}
}
private void CleanDirectory()
private void CleanFCCDirectory()
{
var exclusions = new List<string> { buildOutputFolderName, coverageToolOutputFolderName };
var fccDirectory = new DirectoryInfo(FCCOutputFolder);
Expand Down
1 change: 1 addition & 0 deletions SharedProject/Core/Model/ICoverageProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal interface ICoverageProject
string FCCOutputFolder { get; }
string CoverageOutputFile { get; }
string CoverageOutputFolder { get; set; }
string DefaultCoverageOutputFolder { get; }
List<string> ExcludedReferencedProjects { get; }
string FailureDescription { get; set; }
string FailureStage { get; set; }
Expand Down
7 changes: 5 additions & 2 deletions SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}}
";

}
Expand Down
4 changes: 4 additions & 0 deletions SharedProject/Options/AppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions SharedProject/Options/IAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public interface IAppOptions
bool StickyCoverageTable { get; }
bool NamespacedClasses { get; }
bool HideFullyCovered { get; }
bool AdjacentBuildOutput { get; }
}
}

0 comments on commit bce7a33

Please sign in to comment.