Skip to content

Commit

Permalink
remove exception for invalid mergeWith parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertk committed Jan 31, 2024
1 parent ab442d2 commit f24921c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 53 deletions.
17 changes: 10 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@
This includes System.Reflection.Metadata, System.Collections.Immutable, NuGet, Newtonsoft.Json, and others.
See example: dependencies.props (https://github.com/aspnet/BuildTools/blob/1f3f14382764e06b7e691e5ee89d12a280249284/build/dependencies.props#L19-L29)
.NET 8.0.3xx core-sdk-tasks https://github.com/dotnet/installer/blob/release/8.0.3xx/src/core-sdk-tasks/core-sdk-tasks.csproj
-->
<MicrosoftBuildTaskVersion>15.7.179</MicrosoftBuildTaskVersion>
<MicrosoftBuildTaskUtilitiesCoreVersion>15.7.179</MicrosoftBuildTaskUtilitiesCoreVersion>
<NuGetBuildTasksPackageVersion>6.9.0-rc.86</NuGetBuildTasksPackageVersion>
<MicrosoftBuildTaskSystemReflectionMetaData>1.4.2</MicrosoftBuildTaskSystemReflectionMetaData> <!-- 1.4.2 ???-->
<!--<MicrosoftBuildTaskSystemCollectionImmutable>1.5.0</MicrosoftBuildTaskSystemCollectionImmutable>--> <!-- >= 1.3.1 -->
.NET 8.0.3xx core-sdk-tasks https://github.com/dotnet/installer/blob/release/8.0.3xx/src/core-sdk-tasks/core-sdk-tasks.csproj
align package versions coverlet.core with coverlet.collector (vstest) and coverlet.msbuild.tasks (.NET SDK MSBuild)
<MicrosoftBuildTaskVersion>15.7.179</MicrosoftBuildTaskVersion>
<MicrosoftBuildTaskUtilitiesCoreVersion>15.7.179</MicrosoftBuildTaskUtilitiesCoreVersion>
<NuGetBuildTasksPackageVersion>6.9.0-rc.86</NuGetBuildTasksPackageVersion>
<MicrosoftBuildTaskSystemReflectionMetaData>1.4.2</MicrosoftBuildTaskSystemReflectionMetaData>
<MicrosoftBuildTaskSystemCollectionImmutable>1.5.0</MicrosoftBuildTaskSystemCollectionImmutable> >= 1.3.1
-->
</PropertyGroup>

</Project>
3 changes: 1 addition & 2 deletions src/coverlet.collector/DataCollection/AttachmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ private string SaveCoverageReport(string report, string reportFileName)
}
catch (Exception ex)
{
string errorMessage = $"{CoverletConstants.DataCollectorName}: Failed to save coverage report '{reportFileName}' in directory '{_reportDirectory}'";
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to save coverage report '{reportFileName}' in directory '{_reportDirectory}'", ex);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/coverlet.collector/DataCollection/CoverageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public void InstrumentModules()
}
catch (Exception ex)
{
string errorMessage = $"{CoverletConstants.DataCollectorName}: Failed to instrument modules";
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to instrument modules", ex);
}
}

Expand All @@ -95,8 +94,7 @@ private CoverageResult GetCoverageResult()
}
catch (Exception ex)
{
string errorMessage = $"{CoverletConstants.DataCollectorName}: Failed to get coverage result";
throw new CoverletDataCollectorException(errorMessage, ex);
throw new CoverletDataCollectorException($"{CoverletConstants.DataCollectorName}: Failed to get coverage result", ex);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/coverlet.core/Coverage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ public CoverageResult GetCoverageResult()
{
if (_fileSystem.Exists(_parameters.MergeWith))
{
_logger.LogInformation($"MergeWith: '{_parameters.MergeWith}'");
_logger.LogInformation($"MergeWith: '{_parameters.MergeWith}'.");
string json = _fileSystem.ReadAllText(_parameters.MergeWith);
coverageResult.Merge(JsonSerializer.Deserialize<Modules>(json));
} else
{
throw new ArgumentException($"MergeWith - file '{_parameters.MergeWith}' does not exist");
_logger.LogInformation($"MergeWith: file '{_parameters.MergeWith}' does not exist.");
}
}

Expand Down
38 changes: 0 additions & 38 deletions test/coverlet.core.tests/Coverage/CoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,44 +110,6 @@ public void TestCoverageWithTestAssembly()
directory.Delete(true);
}

[Fact]
public void TestCoverageWrongMergeWithParameter()
{
string module = GetType().Assembly.Location;
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");

DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));

File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true);
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true);

// TODO: Find a way to mimick hits
var instrumentationHelper =
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object,
new SourceRootTranslator(module, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter()));

var parameters = new CoverageParameters
{
IncludeFilters = new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" },
IncludeDirectories = Array.Empty<string>(),
ExcludeFilters = Array.Empty<string>(),
ExcludedSourceFiles = Array.Empty<string>(),
ExcludeAttributes = Array.Empty<string>(),
IncludeTestAssembly = false,
SingleHit = false,
MergeWith = "blabla",
UseSourceLink = false
};

var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), parameters, _mockLogger.Object, instrumentationHelper, new FileSystem(), new SourceRootTranslator(_mockLogger.Object, new FileSystem()), new CecilSymbolHelper());
coverage.PrepareModules();

ArgumentException exception = Assert.Throws<ArgumentException>(() => coverage.GetCoverageResult());
Assert.Contains("blabla", exception.Message);

directory.Delete(true);
}

[Fact]
public void TestCoverageMergeWithParameter()
{
Expand Down

0 comments on commit f24921c

Please sign in to comment.