Skip to content

Commit

Permalink
Skip coverage targets when opt-out ReportGenerator (#70)
Browse files Browse the repository at this point in the history
* Skip coverage targets when opt-out ReportGenerator

* Bump to next patch

* Added tests to check report coverage options
  • Loading branch information
binick authored Mar 26, 2023
1 parent 32dee56 commit 56c85fa
Show file tree
Hide file tree
Showing 30 changed files with 156 additions and 78 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ tab_width = 4
[*.{*proj,xml,props,targets,tasks,yml,yaml}]
indent_size = 2
tab_width = 2

10 changes: 9 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@

<PropertyGroup>
<NoWarn>$(NoWarn);SA1311;SA1413</NoWarn>
<NoWarn Condition="'$(IsShippable)' != 'true'">$(NoWarn);SA0001;SA1600</NoWarn>
<_SkipUpgradeNetAnalyzersNuGetWarning>true</_SkipUpgradeNetAnalyzersNuGetWarning>
</PropertyGroup>

<PropertyGroup Condition="'$(IsShippable)' != 'true'">
<NoWarn>$(NoWarn);SA0001;SA1600</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<NoWarn>$(NoWarn);CA1711</NoWarn>
<NoWarn>$(NoWarn);IL2026</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="$(MicrosoftSourceLinkGitHubVersion)" PrivateAssets="All"/>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/themes/book
Submodule book updated 1 files
+1 −1 README.md
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"allowPrerelease": false
},
"tools": {
"dotnet": "7.0.100"
"dotnet": "7.0.202"
},
"msbuild-sdks": {
"MsBullet.Sdk": "0.6.3"
"MsBullet.Sdk": "0.6.5"
}
}
3 changes: 1 addition & 2 deletions src/Common/MockEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Build.Framework;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace MsBullet.Sdk.IntegrationTests.Utilities
{
internal class MockEngine : IBuildEngine5
internal sealed class MockEngine : IBuildEngine5
{
private readonly ITestOutputHelper output;

Expand Down
10 changes: 3 additions & 7 deletions src/Common/Sandbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Sandbox(string workDir, string[] sourceDirectories)

foreach (string dir in sourceDirectories)
{
this.CopyRecursive(dir, workDir);
Sandbox.CopyRecursive(dir, workDir);
}
}

Expand Down Expand Up @@ -52,15 +52,11 @@ protected virtual void Dispose(bool disposing)
}
}

private void CopyRecursive(string srcDir, string destDir)
private static void CopyRecursive(string srcDir, string destDir)
{
foreach (string srcFileName in Directory.EnumerateFiles(srcDir, "*", SearchOption.AllDirectories))
{
string destFileName = Path.Combine(destDir, srcFileName.Substring(srcDir.Length).TrimStart(new[]
{
Path.AltDirectorySeparatorChar,
Path.DirectorySeparatorChar
}));
string destFileName = Path.Combine(destDir, srcFileName.Substring(srcDir.Length).TrimStart(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));

Directory.CreateDirectory(Path.GetDirectoryName(destFileName));
File.Copy(srcFileName, destFileName);
Expand Down
16 changes: 1 addition & 15 deletions src/MsBullet.Sdk.IntegrationTests/MinimalRepoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ public void MinimalRepoBuildsWithoutErrors()
public void MinimalRepoPackWithoutErrors(bool isShippable, string destinationFolder)
{
// Given
#pragma warning disable CA2000 // Dispose objects before losing scope
TestApp app = this.fixture.ProvideTestApp("MinimalRepo")
.WithPreCreate("git", "init")
.WithPreCreate("git", "remote", "add", "origin", "http://localhost")
.WithPreCreate("git", "checkout", "-b", "main")
.WithPreCreate("git", "commit", "--allow-empty", "-m", "Dummy happy empty commit.")
.Create(this.output);

#pragma warning restore CA2000 // Dispose objects before losing scope
var expectedVersion = "1.0.0-local.*";
var packageFileName = $"ClassLib1.{expectedVersion}.nupkg";

Expand All @@ -66,20 +64,11 @@ public void MinimalRepoPackWithoutErrors(bool isShippable, string destinationFol
Assert.Single(Directory.GetFiles(Path.Combine(app.WorkingDirectory, "artifacts", "packages", "Debug", destinationFolder), packageFileName));
}

[Fact]
[Fact(Skip = "This feature will be released on future version")]
public void MinimalRepoSignsWithoutErrors()
{
#pragma warning disable CA1303 // Do not pass literals as localized parameters
this.output.WriteLine("This feature will be released on future version");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
return;

#pragma warning disable CS0162 // Unreachable code detected

// Given
#pragma warning disable CA2000 // Dispose objects before losing scope
TestApp app = this.fixture.ProvideTestApp("MinimalRepo").Create(this.output);
#pragma warning restore CA2000 // Dispose objects before losing scope

// When
int exitCode = app.ExecuteBuild(
Expand All @@ -98,16 +87,13 @@ public void MinimalRepoSignsWithoutErrors()
#pragma warning disable SYSLIB0024 // Type or member is obsolete
AppDomain.Unload(domain);
#pragma warning restore SYSLIB0024 // Type or member is obsolete
#pragma warning restore CS0162 // Unreachable code detected
}

[Fact]
public void MinimalRepoVersionWithoutErrors()
{
// Given
#pragma warning disable CA2000 // Dispose objects before losing scope
TestApp app = this.fixture.ProvideTestApp("MinimalRepo").Create(this.output);
#pragma warning restore CA2000 // Dispose objects before losing scope

// When
int exitCode = app.ExecuteBuild(
Expand Down
69 changes: 65 additions & 4 deletions src/MsBullet.Sdk.IntegrationTests/MinimalRepoWithTestsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ public MinimalRepoWithTestsTests(ITestOutputHelper output, TestProjectFixture fi
this.fixture = fixture;
}

[Fact]
public void MinimalRepoBuildsWithoutErrors()
{
// Given
#pragma warning disable CA2000 // Dispose objects before losing scope.
TestApp app = this.fixture.ProvideTestApp("MinimalRepoWithTests").Create(this.output);
#pragma warning restore CA2000 // Dispose objects before losing scope

// When
int exitCode = app.ExecuteBuild(this.output);

// Then
Assert.Equal(0, exitCode);
}

[Fact]
public void MinimalRepoRunTestsWithoutError()
{
Expand Down Expand Up @@ -58,7 +73,7 @@ public void MinimalRepoRunTestsShoudProduceTestsResults(string configuration, st
Assert.Equal(0, exitCode);
Assert.True(Directory.Exists(outDir));

var outDirPahts = Directory.EnumerateFiles(outDir).Select(path => Path.GetFileName(path));
var outDirPahts = Directory.EnumerateFiles(outDir).Select(Path.GetFileName);
foreach (var report in reports)
{
Assert.Contains(report, outDirPahts);
Expand Down Expand Up @@ -86,7 +101,7 @@ public void MinimalRepoRunTestsShoudProduceLogResults(string configuration, stri
// Then
Assert.Equal(0, exitCode);
Assert.True(Directory.Exists(outDir));
Assert.Contains(fileName, Directory.EnumerateFiles(outDir).Select(path => Path.GetFileName(path)));
Assert.Contains(fileName, Directory.EnumerateFiles(outDir).Select(Path.GetFileName));
}

[Theory]
Expand All @@ -108,7 +123,7 @@ public void MinimalRepoRunTestsShoudCollectCoverageMetrics(string configuration,
// Then
Assert.Equal(0, exitCode);
Assert.True(Directory.Exists(outDir));
Assert.Contains(fileName, Directory.EnumerateFiles(outDir).Select(path => Path.GetFileName(path)));
Assert.Contains(fileName, Directory.EnumerateFiles(outDir).Select(Path.GetFileName));
}

[Theory]
Expand All @@ -131,7 +146,53 @@ public void MinimalRepoRunTestsShoudGenerateCoverageReports(string configuration
// Then
Assert.Equal(0, exitCode);
Assert.True(Directory.Exists(outDir));
Assert.Contains(fileName, Directory.EnumerateFiles(outDir).Select(path => Path.GetFileName(path)));
Assert.Contains(fileName, Directory.EnumerateFiles(outDir).Select(Path.GetFileName));
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void MinimalRepoRunTestsShoudNotGenerateCoverageSummaryReportsWhenItsPropertyIsFalse(string configuration)
{
// Given
TestApp app = this.fixture.ProvideTestApp("MinimalRepoWithTests").Create(this.output);
var outDir = Path.Combine(app.WorkingDirectory, "artifacts", "TestResults", configuration, "Reports");

// When
int exitCode = app.ExecuteBuild(
this.output,
"-test",
$"-configuration {configuration}",
"/p:GenerateCoverageReportSummary=false");

// Then
Assert.Equal(0, exitCode);
Assert.True(Directory.Exists(outDir));
Assert.DoesNotContain("Summary", Directory.EnumerateDirectories(outDir));
}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void MinimalRepoRunTestsShoudNotGenerateCoverageReportsWhenReportGeneratorToolIsOptedOut(string configuration)
{
// Given
#pragma warning disable CA2000 // Dispose objects before losing scope
TestApp app = this.fixture.ProvideTestApp("MinimalRepoWithTests").Create(this.output);
#pragma warning restore CA2000 // Dispose objects before losing scope
var outDir = Path.Combine(app.WorkingDirectory, "artifacts", "TestResults", configuration);

// When
int exitCode = app.ExecuteBuild(
this.output,
"-test",
$"-configuration {configuration}",
"/p:UsingToolReportGenerator=false");

// Then
Assert.Equal(0, exitCode);
Assert.True(Directory.Exists(outDir));
Assert.DoesNotContain("Reports", Directory.EnumerateDirectories(outDir));
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// See the LICENSE.TXT file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Xunit;
Expand All @@ -24,7 +25,7 @@ public MultipleProjectsWithTestsTests(ITestOutputHelper output, TestProjectFixtu
[InlineData("Release", "", "index.html", "Summary.tex", "Cobertura.xml")]
[InlineData("Debug", "Html", "index.html", "Cobertura.xml")]
[InlineData("Release", "Html", "index.html", "Cobertura.xml")]
public void MinimalRepoRunTestsShoudGenerateCoverageReportSummary(string configuration, string reportTypes, params string[] reports)
public void MinimalRepoRunTestsShoudGenerateCoverageReportSummary(string configuration, string reportTypes, [NotNull] params string[] reports)
{
// Given
TestApp app = this.fixture.ProvideTestApp("MultipleProjectsWithTests").Create(this.output);
Expand Down Expand Up @@ -57,7 +58,9 @@ public void MinimalRepoRunTestsShoudGenerateCoverageReportSummary(string configu
public void ShouldBeEvaluateReportCoverageOnlyWhenIsTestProject()
{
// Given
#pragma warning disable CA2000 // Dispose objects before losing scope
TestApp app = this.fixture.ProvideTestApp("MultipleProjectsWithTests").Create(this.output);
#pragma warning restore CA2000 // Dispose objects before losing scope
var args = new[]
{
"/t:CollectCoverage"
Expand Down
10 changes: 2 additions & 8 deletions src/MsBullet.Sdk.IntegrationTests/Utilities/TestApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void Write(object sender, DataReceivedEventArgs e)
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.Environment["PATH"] = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH");
psi.Environment["PATH"] = Path.GetDirectoryName(Environment.ProcessPath) + Path.PathSeparator + Environment.GetEnvironmentVariable("PATH");

var process = new Process
{
Expand Down Expand Up @@ -101,9 +101,7 @@ protected virtual int ExecuteScript(ITestOutputHelper output, string fileName, I

if (string.IsNullOrEmpty(fileName))
{
#pragma warning disable CA1303 // Do not pass literals as localized parameters
throw new ArgumentException("Script file is not valorized.", nameof(fileName));
#pragma warning restore CA1303 // Do not pass literals as localized parameters
}

if (scriptArgs is null)
Expand Down Expand Up @@ -148,11 +146,7 @@ private static void Copy(string srcDir, string destDir)
{
foreach (string srcFileName in Directory.EnumerateFiles(srcDir, "*", SearchOption.AllDirectories))
{
string destFileName = Path.Combine(destDir, srcFileName.Substring(srcDir.Length).TrimStart(new[]
{
Path.AltDirectorySeparatorChar,
Path.DirectorySeparatorChar
}));
string destFileName = Path.Combine(destDir, srcFileName.Substring(srcDir.Length).TrimStart(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));

Directory.CreateDirectory(Path.GetDirectoryName(destFileName));
File.Copy(srcFileName, destFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
while (this.disposables.Count > 0)
while (!this.disposables.IsEmpty)
{
if (this.disposables.TryDequeue(out IDisposable disposable))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>

<NoWarn>$(NoWarn);SA0001;SA1633;SA1200</NoWarn>
<NoWarn>$(NoWarn);S2094</NoWarn>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>

<NoWarn>$(NoWarn);SA0001;SA1633;SA1200</NoWarn>
<NoWarn>$(NoWarn);SA0001;SA1633;SA1200;SA1600</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<IsPackable>true</IsPackable>

<NoWarn>$(NoWarn);CA1822;SA0001;SA1633;SA1200;S3400</NoWarn>
<NoWarn>$(NoWarn);CA1822;SA0001;SA1633;SA1200;SA1600;S3400</NoWarn>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>

<NoWarn>$(NoWarn);SA0001;SA1633;SA1200</NoWarn>
<NoWarn>$(NoWarn);SA0001;SA1633;SA1200;SA1600</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<IsPackable>true</IsPackable>

<NoWarn>$(NoWarn);CA1822;SA0001;SA1633;SA1200;S3400</NoWarn>
<NoWarn>$(NoWarn);CA1822;SA0001;SA1633;SA1200;SA1600;S3400</NoWarn>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>

<NoWarn>$(NoWarn);SA0001;SA1633;SA1200</NoWarn>
<NoWarn>$(NoWarn);SA0001;SA1633;SA1200;SA1600</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<IsPackable>true</IsPackable>

<NoWarn>$(NoWarn);CA1822;SA0001;SA1633;SA1200;S3400</NoWarn>
<NoWarn>$(NoWarn);CA1822;SA0001;SA1633;SA1200;SA1600;S3400</NoWarn>
</PropertyGroup>

</Project>
Loading

0 comments on commit 56c85fa

Please sign in to comment.