Skip to content

Commit 3987815

Browse files
authored
Merge pull request #378 from tonyhallett/enabled-false-does-not-prevent-coverage
add DisabledNoCoverage ( default true - no breaking change ) option
2 parents 8183f3f + 7b43070 commit 3987815

File tree

8 files changed

+47
-4
lines changed

8 files changed

+47
-4
lines changed

FineCodeCoverageTests/AppOptionsProvider_Tests.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public void Should_Default_Enabled_True()
144144
DefaultTest(appOptions => appOptions.Enabled = true);
145145
}
146146

147+
[Test]
148+
public void Should_Default_DisabledNoCoverage_True()
149+
{
150+
DefaultTest(appOptions => appOptions.DisabledNoCoverage = true);
151+
}
152+
147153
[Test]
148154
public void Should_Default_True_ShowCoverageInOverviewMargin()
149155
{
@@ -198,7 +204,8 @@ public void Should_Not_Default_Any_Other_AppOptions_Properties()
198204
nameof(IAppOptions.ShowUncoveredInOverviewMargin),
199205
nameof(IAppOptions.ShowPartiallyCoveredInOverviewMargin),
200206
nameof(IAppOptions.ShowToolWindowToolbar),
201-
nameof(IAppOptions.Hide0Coverable)
207+
nameof(IAppOptions.Hide0Coverable),
208+
nameof(IAppOptions.DisabledNoCoverage)
202209
};
203210
CollectionAssert.AreEquivalent(expectedSetters.Select(s => $"set_{s}"), invocationNames);
204211
}
@@ -272,6 +279,7 @@ internal void Should_Use_Deseralized_String_From_Store_For_AppOption_Property(Fu
272279
{ nameof(IAppOptions.CoverletConsoleGlobal), true},
273280
{ nameof(IAppOptions.CoverletConsoleLocal), true},
274281
{ nameof(IAppOptions.Enabled), true},
282+
{ nameof(IAppOptions.DisabledNoCoverage), true},
275283
{ nameof(IAppOptions.Exclude), new string[]{"exclude" } },
276284
{ nameof(IAppOptions.ExcludeByAttribute), new string[]{ "ebyatt"} },
277285
{ nameof(IAppOptions.ExcludeByFile), new string[]{ "ebyfile"} },

FineCodeCoverageTests/MsCodeCoverage/RunSettingsTemplateReplacementsFactory_Tests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ internal class TestMsCodeCoverageOptions : IMsCodeCoverageOptions
3232
public bool IncludeReferencedProjects { get; set; }
3333
public string[] ExcludeAssemblies { get; set; }
3434
public string[] IncludeAssemblies { get; set; }
35+
public bool DisabledNoCoverage { get; set; }
3536
}
3637

3738
internal static class ReplacementsAssertions
@@ -699,5 +700,6 @@ internal class TestCoverageProjectOptions : IAppOptions
699700
public bool Hide0Coverage { get; set; }
700701
public string[] ExcludeAssemblies { get; set; }
701702
public string[] IncludeAssemblies { get; set; }
703+
public bool DisabledNoCoverage { get; set; }
702704
}
703705
}

FineCodeCoverageTests/TestContainerDiscovery_Tests.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ private void AssertShouldNotReloadCoverage()
4646
mocker.Verify<IFCCEngine>(engine => engine.ReloadCoverage(It.IsAny<Func<Task<List<ICoverageProject>>>>()), Times.Never());
4747
}
4848

49+
private void AssertReloadsCoverage()
50+
{
51+
mocker.Verify<IFCCEngine>(engine => engine.ReloadCoverage(It.IsAny<Func<Task<List<ICoverageProject>>>>()), Times.Once());
52+
}
53+
4954
private void SetUpOptions(Action<Mock<IAppOptions>> setupAppOptions)
5055
{
5156
var mockAppOptions = new Mock<IAppOptions>();
@@ -252,18 +257,33 @@ public async Task Should_ReloadCoverage_When_TestExecutionStarting_And_Settings_
252257
}
253258

254259
[Test]
255-
public void Should_Not_ReloadCoverage_When_TestExecutionStarting_And_Settings_RunInParallel_Is_True_When_Enabled_is_False()
260+
public void Should_Not_ReloadCoverage_When_TestExecutionStarting_And_Settings_RunInParallel_Is_True_When_Enabled_Is_False_And_DisabledNoCoverage_True()
256261
{
257262
SetUpOptions(mockAppOptions =>
258263
{
259264
mockAppOptions.Setup(o => o.Enabled).Returns(false);
260265
mockAppOptions.Setup(o => o.RunInParallel).Returns(true);
266+
mockAppOptions.Setup(o => o.DisabledNoCoverage).Returns(true);
261267
});
262268

263269
RaiseTestExecutionStarting();
264270
AssertShouldNotReloadCoverage();
265271
}
266272

273+
[Test]
274+
public void Should_ReloadCoverage_When_TestExecutionStarting_And_Settings_RunInParallel_Is_True_When_Enabled_Is_False_And_DisabledNoCoverage_False()
275+
{
276+
SetUpOptions(mockAppOptions =>
277+
{
278+
mockAppOptions.Setup(o => o.Enabled).Returns(false);
279+
mockAppOptions.Setup(o => o.RunInParallel).Returns(true);
280+
mockAppOptions.Setup(o => o.DisabledNoCoverage).Returns(false);
281+
});
282+
283+
RaiseTestExecutionStarting();
284+
AssertReloadsCoverage();
285+
}
286+
267287
[TestCase(true, 10, 1, 0, true, Description = "Should run when tests fail if settings RunWhenTestsFail is true")]
268288
[TestCase(false, 10, 1, 0, false, Description = "Should not run when tests fail if settings RunWhenTestsFail is false")]
269289
[TestCase(false, 0, 1, 1, false, Description = "Should not run when total tests does not exceed the RunWhenTestsExceed setting")]

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ If you are using option 1) then project and global options will only be used whe
246246
|Hide0Coverage|Set to true to hide classes, namespaces and assemblies that have 0% coverage.|
247247
|Hide0Coverable|Set to false to show classes, namespaces and assemblies that are not coverable.|
248248
|Enabled|Specifies whether or not coverage output is enabled|
249+
|DisabledNoCoverage|Set to false for VS Option Enabled=false to not disable coverage|
249250
|RunWhenTestsFail|By default coverage runs when tests fail. Set to false to prevent this. **Cannot be used in conjunction with RunInParallel**|
250251
|RunWhenTestsExceed|Specify a value to only run coverage based upon the number of executing tests. **Cannot be used in conjunction with RunInParallel**|
251252
|RunMsCodeCoverage|Change to IfInRunSettings to only collect with configured runsettings. Yes for runsettings generation.|

SharedProject/Impl/TestContainerDiscovery/TestContainerDiscoverer.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,19 @@ IMsCodeCoverageRunSettingsService msCodeCoverageRunSettingsService
9191
ThreadHelper.JoinableTaskFactory.Run(taskProvider);
9292
};
9393

94+
private bool CoverageDisabled(IAppOptions settings)
95+
{
96+
return !settings.Enabled && settings.DisabledNoCoverage;
97+
}
98+
9499
private async Task TestExecutionStartingAsync(IOperation operation)
95100
{
96101
cancelling = false;
97102
runningInParallel = false;
98103
StopCoverage();
99104

100105
var settings = appOptionsProvider.Get();
101-
if (!settings.Enabled)
106+
if (CoverageDisabled(settings))
102107
{
103108
CombinedLog("Coverage not collected as FCC disabled.");
104109
reportGeneratorUtil.EndOfCoverageRun();
@@ -155,7 +160,7 @@ private async Task TestExecutionFinishedAsync(IOperation operation)
155160
private bool ShouldNotCollectWhenTestExecutionFinished()
156161
{
157162
settings = appOptionsProvider.Get();
158-
return !settings.Enabled || runningInParallel || MsCodeCoverageErrored;
163+
return CoverageDisabled(settings) || runningInParallel || MsCodeCoverageErrored;
159164

160165
}
161166

SharedProject/Options/AppOptionsPage.cs

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ private static IAppOptionsStorageProvider GetAppOptionsStorageProvider()
4747
[Description("Specifies whether or not coverage output is enabled")]
4848
public bool Enabled { get; set; }
4949

50+
[Category(commonRunCategory)]
51+
[Description("Set to false for VS Option Enabled=false to not disable coverage")]
52+
public bool DisabledNoCoverage { get; set; }
53+
5054
[Category(commonRunCategory)]
5155
[Description("Specifies whether or not the ms code coverage is used (BETA). No, IfInRunSettings, Yes")]
5256
public RunMsCodeCoverage RunMsCodeCoverage { get; set; }

SharedProject/Options/AppOptionsProvider.cs

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private void AddDefaults(IAppOptions appOptions)
6464
appOptions.IncludeTestAssembly = true;
6565
appOptions.ExcludeByFile = new[] { "**/Migrations/*" };
6666
appOptions.Enabled = true;
67+
appOptions.DisabledNoCoverage = true;
6768
appOptions.ShowCoverageInOverviewMargin = true;
6869
appOptions.ShowCoveredInOverviewMargin = true;
6970
appOptions.ShowPartiallyCoveredInOverviewMargin = true;
@@ -200,6 +201,7 @@ internal class AppOptions : IAppOptions
200201
public string[] FunctionsExclude { get; set; }
201202

202203
public bool Enabled { get; set; }
204+
public bool DisabledNoCoverage { get; set; }
203205

204206
public bool IncludeTestAssembly { get; set; }
205207

SharedProject/Options/IAppOptions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
internal interface IFCCCommonOptions
44
{
55
bool Enabled { get; set; }
6+
bool DisabledNoCoverage { get; set; }
67
bool IncludeTestAssembly { get; set; }
78
bool IncludeReferencedProjects { get; set; }
89

0 commit comments

Comments
 (0)