From 8e5fcf77acb82b630c6163a6dfb7b66057aa1bd9 Mon Sep 17 00:00:00 2001 From: Bert Date: Sun, 17 Sep 2023 17:35:28 +0200 Subject: [PATCH] remove .runsettings --- Directory.Build.props | 2 +- Directory.Packages.props | 7 +- src/coverlet.core/Exceptions.cs | 2 +- .../InstrumentationTask.cs | 5 +- .../coverlet.core.tests.csproj | 2 + .../DeterministicBuild.cs | 379 +++++++++--------- .../coverlet.msbuild.tasks.tests/.runsettings | 12 - .../coverlet.msbuild.tasks.tests.csproj | 1 - .../.editorconfig | 8 + 9 files changed, 209 insertions(+), 209 deletions(-) delete mode 100644 test/coverlet.msbuild.tasks.tests/.runsettings create mode 100644 test/coverlet.tests.projectsample.wpf6/.editorconfig diff --git a/Directory.Build.props b/Directory.Build.props index 9373b11bf..0a648aa1c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,8 +9,8 @@ true snupkg true - true preview + false true preview $(NoWarn);NU5105;CS1591 diff --git a/Directory.Packages.props b/Directory.Packages.props index d97b7938c..c20289362 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,8 +5,9 @@ - - + + + @@ -58,6 +59,6 @@ - + diff --git a/src/coverlet.core/Exceptions.cs b/src/coverlet.core/Exceptions.cs index 4eefd76ca..8b97ca283 100644 --- a/src/coverlet.core/Exceptions.cs +++ b/src/coverlet.core/Exceptions.cs @@ -6,7 +6,7 @@ namespace Coverlet.Core.Exceptions { [Serializable] - internal class CoverletException : Exception + public class CoverletException : Exception { public CoverletException() { } public CoverletException(string message) : base(message) { } diff --git a/src/coverlet.msbuild.tasks/InstrumentationTask.cs b/src/coverlet.msbuild.tasks/InstrumentationTask.cs index c81c72b7a..7c5940cfb 100644 --- a/src/coverlet.msbuild.tasks/InstrumentationTask.cs +++ b/src/coverlet.msbuild.tasks/InstrumentationTask.cs @@ -116,8 +116,9 @@ public override bool Execute() ServiceProvider.GetService()); CoveragePrepareResult prepareResult = coverage.PrepareModules(); - InstrumenterState = new TaskItem(System.IO.Path.GetTempFileName()); - using Stream instrumentedStateFile = fileSystem.NewFileStream(InstrumenterState.ItemSpec, FileMode.Open, FileAccess.Write); + string randomPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName()); + InstrumenterState = new TaskItem(randomPath); + using Stream instrumentedStateFile = fileSystem.NewFileStream(InstrumenterState.ItemSpec, FileMode.CreateNew, FileAccess.Write); using Stream serializedState = CoveragePrepareResult.Serialize(prepareResult); serializedState.CopyTo(instrumentedStateFile); } diff --git a/test/coverlet.core.tests/coverlet.core.tests.csproj b/test/coverlet.core.tests/coverlet.core.tests.csproj index 32e4ee527..b53eaf93c 100644 --- a/test/coverlet.core.tests/coverlet.core.tests.csproj +++ b/test/coverlet.core.tests/coverlet.core.tests.csproj @@ -22,6 +22,8 @@ + + diff --git a/test/coverlet.integration.tests/DeterministicBuild.cs b/test/coverlet.integration.tests/DeterministicBuild.cs index d5f02f39d..96d8314cb 100644 --- a/test/coverlet.integration.tests/DeterministicBuild.cs +++ b/test/coverlet.integration.tests/DeterministicBuild.cs @@ -12,207 +12,208 @@ namespace Coverlet.Integration.Tests { - public class DeterministicBuild : BaseTest, IDisposable - { - private readonly string _testProjectPath = Path.GetFullPath("../../../../coverlet.integration.determisticbuild"); - private string? _testProjectTfm; - private const string PropsFileName = "DeterministicTest.props"; - private readonly string _buildConfiguration; - private readonly ITestOutputHelper _output; + public class DeterministicBuild : BaseTest, IDisposable + { + private readonly string _testProjectPath = Path.GetFullPath("../../../../coverlet.integration.determisticbuild"); + private string? _testProjectTfm; + private const string PropsFileName = "DeterministicTest.props"; + private readonly string _buildConfiguration; + private readonly ITestOutputHelper _output; public DeterministicBuild(ITestOutputHelper output) - { - _buildConfiguration = GetAssemblyBuildConfiguration().ToString(); - _output = output; - } + { + _buildConfiguration = GetAssemblyBuildConfiguration().ToString(); + _output = output; + } - private void CreateDeterministicTestPropsFile() - { - var deterministicTestProps = new XDocument(); - deterministicTestProps.Add( - new XElement("Project", - new XElement("PropertyGroup", - new XElement("coverletMsbuilVersion", GetPackageVersion("*msbuild*.nupkg")), - new XElement("coverletCollectorsVersion", GetPackageVersion("*collector*.nupkg"))))); - _testProjectTfm = XElement.Load(Path.Combine(_testProjectPath, "coverlet.integration.determisticbuild.csproj"))!. - Descendants("PropertyGroup")!.Single().Element("TargetFramework")!.Value; - - deterministicTestProps.Save(Path.Combine(_testProjectPath, PropsFileName)); - } + private void CreateDeterministicTestPropsFile() + { + var deterministicTestProps = new XDocument(); + deterministicTestProps.Add( + new XElement("Project", + new XElement("PropertyGroup", + new XElement("coverletMsbuilVersion", GetPackageVersion("*msbuild*.nupkg")), + new XElement("coverletCollectorsVersion", GetPackageVersion("*collector*.nupkg"))))); + _testProjectTfm = XElement.Load(Path.Combine(_testProjectPath, "coverlet.integration.determisticbuild.csproj"))!. + Descendants("PropertyGroup")!.Single().Element("TargetFramework")!.Value; + + deterministicTestProps.Save(Path.Combine(_testProjectPath, PropsFileName)); + } - private protected void AssertCoverage(string standardOutput = "", bool checkDeterministicReport = true) + private protected void AssertCoverage(string standardOutput = "", bool checkDeterministicReport = true) + { + if (_buildConfiguration == "Debug") + { + bool coverageChecked = false; + string reportFilePath = ""; + foreach (string coverageFile in Directory.GetFiles(_testProjectPath, "coverage.json", SearchOption.AllDirectories)) { - if (_buildConfiguration == "Debug") - { - bool coverageChecked = false; - string reportFilePath = ""; - foreach (string coverageFile in Directory.GetFiles(_testProjectPath, "coverage.json", SearchOption.AllDirectories)) - { - Classes? document = JsonConvert.DeserializeObject(File.ReadAllText(coverageFile))?.Document("DeepThought.cs"); - if (document != null) - { - document.Class("Coverlet.Integration.DeterministicBuild.DeepThought") - .Method("System.Int32 Coverlet.Integration.DeterministicBuild.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()") - .AssertLinesCovered((6, 1), (7, 1), (8, 1)); - coverageChecked = true; - reportFilePath = coverageFile; - } - } - Assert.True(coverageChecked, $"Coverage check fail\n{standardOutput}"); - File.Delete(reportFilePath); - Assert.False(File.Exists(reportFilePath)); - - if (checkDeterministicReport) - { - // Verify deterministic report - foreach (string coverageFile in Directory.GetFiles(_testProjectPath, "coverage.cobertura.xml", SearchOption.AllDirectories)) - { - Assert.Contains("/_/test/coverlet.integration.determisticbuild/DeepThought.cs", File.ReadAllText(coverageFile)); - File.Delete(coverageFile); - } - } - } + Classes? document = JsonConvert.DeserializeObject(File.ReadAllText(coverageFile))?.Document("DeepThought.cs"); + if (document != null) + { + document.Class("Coverlet.Integration.DeterministicBuild.DeepThought") + .Method("System.Int32 Coverlet.Integration.DeterministicBuild.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()") + .AssertLinesCovered((6, 1), (7, 1), (8, 1)); + coverageChecked = true; + reportFilePath = coverageFile; + } } + Assert.True(coverageChecked, $"Coverage check fail\n{standardOutput}"); + File.Delete(reportFilePath); + Assert.False(File.Exists(reportFilePath)); - [Fact] - public void Msbuild() + if (checkDeterministicReport) { - CreateDeterministicTestPropsFile(); - DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); - Assert.Contains("Build succeeded.", standardOutput); - string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); - Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); - Assert.True(!string.IsNullOrEmpty(File.ReadAllText(sourceRootMappingFilePath)), "Empty CoverletSourceRootsMapping file"); - Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath)); - - DotnetCli($"test -c {_buildConfiguration} --no-build /p:CollectCoverage=true /p:DeterministicReport=true /p:CoverletOutputFormat=\"cobertura%2cjson\" /p:Include=\"[coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true", out standardOutput, out standardError, _testProjectPath); - if (!string.IsNullOrEmpty(standardError)) - { - _output.WriteLine(standardError); - } - else - { - _output.WriteLine(standardOutput); - } - Assert.Contains("Passed!", standardOutput); - Assert.Contains("| coverletsample.integration.determisticbuild | 100% | 100% | 100% |", standardOutput); - Assert.True(File.Exists(Path.Combine(_testProjectPath, "coverage.json"))); - AssertCoverage(standardOutput); - - // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested - // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); - // Assert.False(File.Exists(sourceRootMappingFilePath)); - RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); + // Verify deterministic report + foreach (string coverageFile in Directory.GetFiles(_testProjectPath, "coverage.cobertura.xml", SearchOption.AllDirectories)) + { + Assert.Contains("/_/test/coverlet.integration.determisticbuild/DeepThought.cs", File.ReadAllText(coverageFile), StringComparison.OrdinalIgnoreCase); + File.Delete(coverageFile); + } } + } + } - [Fact] - public void Msbuild_SourceLink() - { - CreateDeterministicTestPropsFile(); - DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); - Assert.Contains("Build succeeded.", standardOutput); - string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); - Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); - Assert.True(!string.IsNullOrEmpty(File.ReadAllText(sourceRootMappingFilePath)), "Empty CoverletSourceRootsMapping file"); - Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath)); - - DotnetCli($"test -c {_buildConfiguration} --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=\"cobertura%2cjson\" /p:UseSourceLink=true /p:Include=\"[coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true", out standardOutput, out standardError, _testProjectPath); - if (!string.IsNullOrEmpty(standardError)) - { - _output.WriteLine(standardError); - } - else - { - _output.WriteLine(standardOutput); - } - Assert.Contains("Passed!", standardOutput); - Assert.Contains("| coverletsample.integration.determisticbuild | 100% | 100% | 100% |", standardOutput); - Assert.True(File.Exists(Path.Combine(_testProjectPath, "coverage.json"))); - Assert.Contains("raw.githubusercontent.com", File.ReadAllText(Path.Combine(_testProjectPath, "coverage.json"))); - AssertCoverage(standardOutput, checkDeterministicReport: false); - - // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested - // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); - // Assert.False(File.Exists(sourceRootMappingFilePath)); - RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); - } + [Fact] + public void Msbuild() + { + CreateDeterministicTestPropsFile(); + DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + Assert.Contains("Build succeeded.", standardOutput, StringComparison.OrdinalIgnoreCase); + string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); + Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); + Assert.True(!string.IsNullOrEmpty(File.ReadAllText(sourceRootMappingFilePath)), "Empty CoverletSourceRootsMapping file"); + Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath), StringComparison.OrdinalIgnoreCase); + + DotnetCli($"test -c {_buildConfiguration} --no-build /p:CollectCoverage=true /p:DeterministicReport=true /p:CoverletOutputFormat=\"cobertura%2cjson\" /p:Include=\"[coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true", out standardOutput, out standardError, _testProjectPath); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + Assert.Contains("Passed!", standardOutput, StringComparison.OrdinalIgnoreCase); + Assert.Contains("| coverletsample.integration.determisticbuild | 100% | 100% | 100% |", standardOutput, StringComparison.OrdinalIgnoreCase); + Assert.True(File.Exists(Path.Combine(_testProjectPath, "coverage.json"))); + AssertCoverage(standardOutput); + + // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested + // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); + // Assert.False(File.Exists(sourceRootMappingFilePath)); + RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); + } - [Fact] - public void Collectors() - { - CreateDeterministicTestPropsFile(); - DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); - Assert.Contains("Build succeeded.", standardOutput); - string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); - Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); - Assert.NotEmpty(File.ReadAllText(sourceRootMappingFilePath)); - Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath)); - - string runSettingsPath = AddCollectorRunsettingsFile(_testProjectPath, "[coverletsample.integration.determisticbuild]*DeepThought", deterministicReport: true); - Assert.True(DotnetCli($"test -c {_buildConfiguration} --no-build \"{_testProjectPath}\" --collect:\"XPlat Code Coverage\" --settings \"{runSettingsPath}\" --diag:{Path.Combine(_testProjectPath, "log.txt")}", out standardOutput, out standardError), standardOutput); - if (!string.IsNullOrEmpty(standardError)) - { - _output.WriteLine(standardError); - } - else - { - _output.WriteLine(standardOutput); - } - Assert.Contains("Passed!", standardOutput); - AssertCoverage(standardOutput); - - // Check out/in process collectors injection - string dataCollectorLogContent = File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.datacollector.*.txt").Single()); - Assert.Contains("[coverlet]Initializing CoverletCoverageDataCollector with configuration:", dataCollectorLogContent); - Assert.Contains("[coverlet]Initialize CoverletInProcDataCollector", File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.host.*.txt").Single())); - Assert.Contains("[coverlet]Mapping resolved", dataCollectorLogContent); - - // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested - // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); - // Assert.False(File.Exists(sourceRootMappingFilePath)); - RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); - } + [Fact] + public void Msbuild_SourceLink() + { + CreateDeterministicTestPropsFile(); + DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + Assert.Contains("Build succeeded.", standardOutput, StringComparison.OrdinalIgnoreCase); + string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); + Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); + Assert.True(!string.IsNullOrEmpty(File.ReadAllText(sourceRootMappingFilePath)), "Empty CoverletSourceRootsMapping file"); + Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath), StringComparison.OrdinalIgnoreCase); + + DotnetCli($"test -c {_buildConfiguration} --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=\"cobertura%2cjson\" /p:UseSourceLink=true /p:Include=\"[coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true", out standardOutput, out standardError, _testProjectPath); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + Assert.Contains("Passed!", standardOutput, StringComparison.OrdinalIgnoreCase); + Assert.Contains("| coverletsample.integration.determisticbuild | 100% | 100% | 100% |", standardOutput, StringComparison.OrdinalIgnoreCase); + Assert.True(File.Exists(Path.Combine(_testProjectPath, "coverage.json"))); + Assert.Contains("raw.githubusercontent.com", File.ReadAllText(Path.Combine(_testProjectPath, "coverage.json")), StringComparison.OrdinalIgnoreCase); + AssertCoverage(standardOutput, checkDeterministicReport: false); + + // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested + // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); + // Assert.False(File.Exists(sourceRootMappingFilePath)); + RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); + } - [Fact] - public void Collectors_SourceLink() - { - CreateDeterministicTestPropsFile(); - DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); - Assert.Contains("Build succeeded.", standardOutput); - string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); - Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); - Assert.NotEmpty(File.ReadAllText(sourceRootMappingFilePath)); - Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath)); - - string runSettingsPath = AddCollectorRunsettingsFile(_testProjectPath, "[coverletsample.integration.determisticbuild]*DeepThought", sourceLink: true); - Assert.True(DotnetCli($"test -c {_buildConfiguration} --no-build \"{_testProjectPath}\" --collect:\"XPlat Code Coverage\" --settings \"{runSettingsPath}\" --diag:{Path.Combine(_testProjectPath, "log.txt")}", out standardOutput, out standardError), standardOutput); - if (!string.IsNullOrEmpty(standardError)) - { - _output.WriteLine(standardError); - } - else - { - _output.WriteLine(standardOutput); - } - Assert.Contains("Passed!", standardOutput); - AssertCoverage(standardOutput, checkDeterministicReport: false); - Assert.Contains("raw.githubusercontent.com", File.ReadAllText(Directory.GetFiles(_testProjectPath, "coverage.cobertura.xml", SearchOption.AllDirectories).Single())); - - // Check out/in process collectors injection - string dataCollectorLogContent = File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.datacollector.*.txt").Single()); - Assert.Contains("[coverlet]Initializing CoverletCoverageDataCollector with configuration:", dataCollectorLogContent); - Assert.Contains("[coverlet]Initialize CoverletInProcDataCollector", File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.host.*.txt").Single())); - Assert.Contains("[coverlet]Mapping resolved", dataCollectorLogContent); - - // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested - // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); - // Assert.False(File.Exists(sourceRootMappingFilePath)); - RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); - } + [Fact] + public void Collectors() + { + CreateDeterministicTestPropsFile(); + DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + Assert.Contains("Build succeeded.", standardOutput, StringComparison.OrdinalIgnoreCase); + string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); + Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); + Assert.NotEmpty(File.ReadAllText(sourceRootMappingFilePath)); + Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath), StringComparison.OrdinalIgnoreCase); + + string runSettingsPath = AddCollectorRunsettingsFile(_testProjectPath, "[coverletsample.integration.determisticbuild]*DeepThought", deterministicReport: true); + Assert.True(DotnetCli($"test -c {_buildConfiguration} --no-build \"{_testProjectPath}\" --collect:\"XPlat Code Coverage\" --settings \"{runSettingsPath}\" --diag:{Path.Combine(_testProjectPath, "log.txt")}", out standardOutput, out standardError), standardOutput); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + Assert.Contains("Passed!", standardOutput, StringComparison.OrdinalIgnoreCase); + AssertCoverage(standardOutput); + + // Check out/in process collectors injection + string dataCollectorLogContent = File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.datacollector.*.txt").Single()); + Assert.Contains("[coverlet]Initializing CoverletCoverageDataCollector with configuration:", dataCollectorLogContent, StringComparison.OrdinalIgnoreCase); + Assert.Contains("[coverlet]Initialize CoverletInProcDataCollector", File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.host.*.txt").Single()), StringComparison.OrdinalIgnoreCase); + Assert.Contains("[coverlet]Mapping resolved", dataCollectorLogContent, StringComparison.OrdinalIgnoreCase); + + // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested + // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); + // Assert.False(File.Exists(sourceRootMappingFilePath)); + RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); + } - public void Dispose() - { - File.Delete(Path.Combine(_testProjectPath, PropsFileName)); - } + [Fact] + public void Collectors_SourceLink() + { + CreateDeterministicTestPropsFile(); + DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string standardError, _testProjectPath); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + Assert.Contains("Build succeeded.", standardOutput, StringComparison.OrdinalIgnoreCase); + string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild"); + Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath); + Assert.NotEmpty(File.ReadAllText(sourceRootMappingFilePath)); + Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath), StringComparison.OrdinalIgnoreCase); + + string runSettingsPath = AddCollectorRunsettingsFile(_testProjectPath, "[coverletsample.integration.determisticbuild]*DeepThought", sourceLink: true); + Assert.True(DotnetCli($"test -c {_buildConfiguration} --no-build \"{_testProjectPath}\" --collect:\"XPlat Code Coverage\" --settings \"{runSettingsPath}\" --diag:{Path.Combine(_testProjectPath, "log.txt")}", out standardOutput, out standardError), standardOutput); + if (!string.IsNullOrEmpty(standardError)) + { + _output.WriteLine(standardError); + } + + Assert.Contains("Passed!", standardOutput, StringComparison.OrdinalIgnoreCase); + AssertCoverage(standardOutput, checkDeterministicReport: false); + Assert.Contains("raw.githubusercontent.com", File.ReadAllText(Directory.GetFiles(_testProjectPath, "coverage.cobertura.xml", SearchOption.AllDirectories).Single()), StringComparison.OrdinalIgnoreCase); + + // Check out/in process collectors injection + string dataCollectorLogContent = File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.datacollector.*.txt").Single()); + Assert.Contains("[coverlet]Initializing CoverletCoverageDataCollector with configuration:", dataCollectorLogContent, StringComparison.OrdinalIgnoreCase); + Assert.Contains("[coverlet]Initialize CoverletInProcDataCollector", File.ReadAllText(Directory.GetFiles(_testProjectPath, "log.host.*.txt").Single()), StringComparison.OrdinalIgnoreCase); + Assert.Contains("[coverlet]Mapping resolved", dataCollectorLogContent, StringComparison.OrdinalIgnoreCase); + + // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested + // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath); + // Assert.False(File.Exists(sourceRootMappingFilePath)); + RunCommand("git", "clean -fdx", out _, out _, _testProjectPath); + } + + public void Dispose() + { + File.Delete(Path.Combine(_testProjectPath, PropsFileName)); } + } } diff --git a/test/coverlet.msbuild.tasks.tests/.runsettings b/test/coverlet.msbuild.tasks.tests/.runsettings deleted file mode 100644 index 867c32ec6..000000000 --- a/test/coverlet.msbuild.tasks.tests/.runsettings +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - detailed - - - - - diff --git a/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj b/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj index 96b0f05c3..22fd4f5ae 100644 --- a/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj +++ b/test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj @@ -6,7 +6,6 @@ enable true false - $(MSBuildThisFileDirectory).runsettings diff --git a/test/coverlet.tests.projectsample.wpf6/.editorconfig b/test/coverlet.tests.projectsample.wpf6/.editorconfig new file mode 100644 index 000000000..d66ee0772 --- /dev/null +++ b/test/coverlet.tests.projectsample.wpf6/.editorconfig @@ -0,0 +1,8 @@ +# top-most EditorConfig file +# We don't want to import other EditorConfig files and we want +# to ensure no rules are enabled for these asset source files. +root = true + +[*.cs] +# Default severity for all analyzer diagnostics +dotnet_analyzer_diagnostic.severity = none