Skip to content

Commit

Permalink
Closes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
FortuneN committed Dec 26, 2020
1 parent e434dc2 commit 266ca4f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 2 deletions.
3 changes: 2 additions & 1 deletion FineCodeCoverage/Core/Coverlet/CoverletUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public static bool RunCoverlet(CoverageProject project, bool throwError = false)

coverletSettings.Add($@"--output ""{ project.CoverageOutputFile }""");

coverletSettings.Add($@"--targetargs ""test """"{project.TestDllFile}"""" --nologo --blame --results-directory """"{project.CoverageOutputFolder}"""" --diag """"{project.CoverageOutputFolder}/diagnostics.log"""" """);
var runSettings = !string.IsNullOrWhiteSpace(project.RunSettingsFile) ? $@"--settings """"{project.RunSettingsFile}""""" : default;
coverletSettings.Add($@"--targetargs ""test """"{project.TestDllFile}"""" --nologo --blame {runSettings} --results-directory """"{project.CoverageOutputFolder}"""" --diag """"{project.CoverageOutputFolder}/diagnostics.log"""" """);

Logger.Log($"{title} Arguments {Environment.NewLine}{string.Join($"{Environment.NewLine}", coverletSettings)}");

Expand Down
1 change: 1 addition & 0 deletions FineCodeCoverage/Core/Model/CoverageProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class CoverageProject
public bool HasExcludeFromCodeCoverageAssemblyAttribute { get; set; }
public string AssemblyName { get; set; }
public bool Is64Bit { get; set; }
public string RunSettingsFile { get; set; }

public CoverageProject Step(string stepName, Action<CoverageProject> action)
{
Expand Down
3 changes: 2 additions & 1 deletion FineCodeCoverage/Core/OpenCover/OpenCoverUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ public static bool RunOpenCover(CoverageProject project, bool throwError = false
//filters.Add($@"-[{nameOnlyOfDll}]*");
}

opencoverSettings.Add($@" ""-targetargs:\""{project.TestDllFile}\"""" ");
var runSettings = !string.IsNullOrWhiteSpace(project.RunSettingsFile) ? $@"/Settings:\""{project.RunSettingsFile}\""" : default;
opencoverSettings.Add($@" ""-targetargs:\""{project.TestDllFile}\"" {runSettings}"" ");

opencoverSettings.Add($@" ""-output:{ project.CoverageOutputFile }"" ");

Expand Down
1 change: 1 addition & 0 deletions FineCodeCoverage/FineCodeCoverage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="Core\Model\CoverageProject.cs" />
<Compile Include="Core\FCCEngine.cs" />
<Compile Include="Core\Utilities\XElementUtil.cs" />
<Compile Include="Impl\RunSettingsRetriever.cs" />
<Compile Include="Impl\GlyphFactory.cs" />
<Compile Include="Impl\GlyphFactoryProvider.cs" />
<Compile Include="Impl\GlyphTag.cs" />
Expand Down
72 changes: 72 additions & 0 deletions FineCodeCoverage/Impl/RunSettingsRetriever.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Reflection;
using System.Threading.Tasks;

namespace FineCodeCoverage.Impl
{
internal class RunSettingsRetriever
{
private object userSettings;

public async Task<string> GetRunSettingsFileAsync(object userSettings, object testContainer)
{
this.userSettings = userSettings;

var runSettingsFile = GetDefaultRunSettingsFilePath();
var projectRunSettingsFile = await GetProjectRunSettingFileAsync(testContainer);

if (!string.IsNullOrEmpty(projectRunSettingsFile))
{
return projectRunSettingsFile;
}

return runSettingsFile;
}

private string GetAndUpdateSolutionRunSettingsFilePath()
{
return userSettings.GetType().GetMethod("GetAndUpdateSolutionRunSettingsFilePath", BindingFlags.Public | BindingFlags.Instance).Invoke(userSettings, new object[] { }) as string;
}

private string LastRunSettingsFilePath()
{
return userSettings.GetType().GetProperty("LastRunSettingsFilePath", BindingFlags.Public | BindingFlags.Instance).GetValue(userSettings) as string;
}

private bool AutomaticallyDetectRunSettings()
{
return (bool)userSettings.GetType().GetProperty("AutomaticallyDetectRunSettings", BindingFlags.Public | BindingFlags.Instance).GetValue(userSettings);
}

private string GetDefaultRunSettingsFilePath()
{
string settingsFilePath = GetAndUpdateSolutionRunSettingsFilePath();
var lastRunSettingsFilePath = LastRunSettingsFilePath();

if (!string.IsNullOrEmpty(lastRunSettingsFilePath))
{
return lastRunSettingsFilePath;
}

if (!AutomaticallyDetectRunSettings() || string.IsNullOrEmpty(settingsFilePath))
{
return null;
}

return settingsFilePath;
}

private static async Task<string> GetProjectRunSettingFileAsync(object container)
{
var projectDataProperty = container.GetType().GetProperty("ProjectData");

if (projectDataProperty != null)
{
var projectData = projectDataProperty.GetValue(container);
var projectRunSettingsFile = await (projectData.GetType().GetMethod("GetBuildPropertyAsync", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(projectData, new object[] { "RunSettingsFilePath", (string)null }) as Task<string>);
return projectRunSettingsFile;
}

return null;
}
}
}
4 changes: 4 additions & 0 deletions FineCodeCoverage/Impl/TestContainerDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private void StopCoverageProcess()
}
}

[SuppressMessage("Usage", "VSTHRD102:Implement internal logic asynchronously")]
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e)
{
try
Expand All @@ -150,6 +151,8 @@ private void OperationState_StateChanged(object sender, OperationStateChangedEve
var operationType = e.Operation.GetType();
var darkMode = CurrentTheme.Equals("Dark", StringComparison.OrdinalIgnoreCase);
var testConfiguration = (operationType.GetProperty("Configuration") ?? operationType.GetProperty("Configuration", BindingFlags.Instance | BindingFlags.NonPublic)).GetValue(e.Operation);
var userRunSettings = testConfiguration.GetType().GetProperty("UserRunSettings", BindingFlags.Instance | BindingFlags.Public).GetValue(testConfiguration);
var runSettingsRetriever = new RunSettingsRetriever();
var testContainers = ((IEnumerable<object>)testConfiguration.GetType().GetProperty("Containers").GetValue(testConfiguration)).ToArray();
var projects = new List<CoverageProject>();

Expand All @@ -165,6 +168,7 @@ private void OperationState_StateChanged(object sender, OperationStateChangedEve
project.TestDllFile = containerType.GetProperty("Source").GetValue(container).ToString();
project.Is64Bit = containerType.GetProperty("TargetPlatform").GetValue(container).ToString().ToLower().Equals("x64");
project.ProjectFile = containerDataType.GetProperty("ProjectFilePath", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic).GetValue(containerData).ToString();
project.RunSettingsFile = ThreadHelper.JoinableTaskFactory.Run(() => runSettingsRetriever.GetRunSettingsFileAsync(userRunSettings, container));

try
{
Expand Down

0 comments on commit 266ca4f

Please sign in to comment.