Skip to content

Commit d9621e2

Browse files
JosephSun2003Joseph Sun
and
Joseph Sun
authored
Revert (#3)
* Revert "Revert changes to CoverageWrapper.cs and ICoverageWrapper.cs" This reverts commit 25feb24. * Revert "Adjust arguement name to trigger the skip of coverage calculation" This reverts commit c54c5cf. * Revert "Add unit tests to new methods" This reverts commit c3905a1. * Revert "Revert refactorings caught by Geotab Analyzers" This reverts commit cbe14cc. * Revert "add unload modules unique specifically for use in coverlet.console" This reverts commit 98f1f75. * Revert "Remove possibly unneeded variables" This reverts commit 6d2dd57. * Revert "Unrollback change removals to integrate new changes with VSTest Integration" This reverts commit 9d4de10. * Revert "Refactor explicit and implicit variable usage to comply with dotnet code style rules" This reverts commit e67ba69. * Revert "Add minor documentation corrections and remove unneeded changes" This reverts commit da1257e. * Revert "Update documentation to clarify the modifications made and add some basic code clean up" This reverts commit 0dfef6f. * Revert "Fix problems encountered with newly added method and variables from unit testing with existing tests" This reverts commit dcc3c29. * Revert "Add new method to manually call the unloading of modules" This reverts commit 88a5782. --------- Co-authored-by: Joseph Sun <[email protected]>
1 parent 25feb24 commit d9621e2

File tree

3 files changed

+5
-132
lines changed

3 files changed

+5
-132
lines changed

src/coverlet.console/Program.cs

+4-14
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static int Main(string[] args)
4949
var doesNotReturnAttributes = new Option<string[]>("--does-not-return-attribute", "Attributes that mark methods that do not return") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true };
5050
var excludeAssembliesWithoutSources = new Option<string>("--exclude-assemblies-without-sources", "Specifies behaviour of heuristic to ignore assemblies with missing source documents.") { Arity = ArgumentArity.ZeroOrOne };
5151
var sourceMappingFile = new Option<string>("--source-mapping-file", "Specifies the path to a SourceRootsMappings file.") { Arity = ArgumentArity.ZeroOrOne };
52-
var unloadCoverletFromModulesOnly = new Option<bool>("---only-unload-modules", "Specifies Whether or not coverlet will only unload after unit tests are finished and skip coverage calculation"){ Arity = ArgumentArity.ZeroOrOne };
5352

5453
RootCommand rootCommand = new()
5554
{
@@ -74,8 +73,7 @@ static int Main(string[] args)
7473
useSourceLink,
7574
doesNotReturnAttributes,
7675
excludeAssembliesWithoutSources,
77-
sourceMappingFile,
78-
unloadCoverletFromModulesOnly
76+
sourceMappingFile
7977
};
8078

8179
rootCommand.Description = "Cross platform .NET Core code coverage tool";
@@ -104,7 +102,6 @@ static int Main(string[] args)
104102
string[] doesNotReturnAttributesValue = context.ParseResult.GetValueForOption(doesNotReturnAttributes);
105103
string excludeAssembliesWithoutSourcesValue = context.ParseResult.GetValueForOption(excludeAssembliesWithoutSources);
106104
string sourceMappingFileValue = context.ParseResult.GetValueForOption(sourceMappingFile);
107-
bool unloadCoverletFromModulesOnlyBool = context.ParseResult.GetValueForOption(unloadCoverletFromModulesOnly);
108105

109106
if (string.IsNullOrEmpty(moduleOrAppDirectoryValue) || string.IsNullOrWhiteSpace(moduleOrAppDirectoryValue))
110107
throw new ArgumentException("No test assembly or application directory specified.");
@@ -130,8 +127,7 @@ static int Main(string[] args)
130127
useSourceLinkValue,
131128
doesNotReturnAttributesValue,
132129
excludeAssembliesWithoutSourcesValue,
133-
sourceMappingFileValue,
134-
unloadCoverletFromModulesOnlyBool);
130+
sourceMappingFileValue);
135131
context.ExitCode = taskStatus;
136132

137133
});
@@ -158,8 +154,7 @@ private static Task<int> HandleCommand(string moduleOrAppDirectory,
158154
bool useSourceLink,
159155
string[] doesNotReturnAttributes,
160156
string excludeAssembliesWithoutSources,
161-
string sourceMappingFile,
162-
bool unloadCoverletFromModulesOnly
157+
string sourceMappingFile
163158
)
164159
{
165160

@@ -237,12 +232,6 @@ bool unloadCoverletFromModulesOnly
237232

238233
string dOutput = output != null ? output : Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar.ToString();
239234

240-
if (unloadCoverletFromModulesOnly)
241-
{
242-
int unloadModuleExitCode = coverage.UnloadModules();
243-
return Task.FromResult(unloadModuleExitCode);
244-
}
245-
246235
logger.LogInformation("\nCalculating coverage result...");
247236

248237
CoverageResult result = coverage.GetCoverageResult();
@@ -396,6 +385,7 @@ bool unloadCoverletFromModulesOnly
396385

397386
return Task.FromResult(exitCode);
398387

388+
399389
}
400390

401391
catch (Win32Exception we) when (we.Source == "System.Diagnostics.Process")

src/coverlet.core/Coverage.cs

+1-47
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public CoverageResult GetCoverageResult()
241241
}
242242

243243
modules.Add(Path.GetFileName(result.ModulePath), documents);
244-
UnloadModule(result.ModulePath);
244+
_instrumentationHelper.RestoreOriginalModule(result.ModulePath, Identifier);
245245
}
246246

247247
// In case of anonymous delegate compiler generate a custom class and passes it as type.method delegate.
@@ -326,52 +326,6 @@ public CoverageResult GetCoverageResult()
326326
return coverageResult;
327327
}
328328

329-
/// <summary>
330-
/// unloads all modules that were instrumented
331-
/// </summary>
332-
/// <returns> exit code of module unloading </returns>
333-
public int UnloadModules()
334-
{
335-
string[] modules = _instrumentationHelper.GetCoverableModules(_moduleOrAppDirectory,
336-
_parameters.IncludeDirectories, _parameters.IncludeTestAssembly);
337-
338-
var validModules = _instrumentationHelper
339-
.SelectModules(modules, _parameters.IncludeFilters, _parameters.ExcludeFilters);
340-
var validModulesAsList = validModules.ToList();
341-
foreach (string modulePath in validModulesAsList) {
342-
try
343-
{
344-
_instrumentationHelper.RestoreOriginalModule(modulePath, Identifier);
345-
_logger.LogVerbose("All Modules unloaded.");
346-
}
347-
catch (Exception e)
348-
{
349-
_logger.LogVerbose($"{e.InnerException} occured, module unloading aborted.");
350-
return -1;
351-
}
352-
}
353-
354-
return 0;
355-
}
356-
357-
/// <summary>
358-
/// Invoke the unloading of modules and restoration of the original assembly files
359-
/// </summary>
360-
/// <param name="modulePath"></param>
361-
/// <returns> exist code of unloading modules </returns>
362-
public void UnloadModule(string modulePath)
363-
{
364-
try
365-
{
366-
_instrumentationHelper.RestoreOriginalModule(modulePath, Identifier);
367-
_logger.LogVerbose($"Module at {modulePath} is unloaded.");
368-
}
369-
catch (Exception e)
370-
{
371-
_logger.LogVerbose($"{e.InnerException} occured, module unloading aborted.");
372-
}
373-
}
374-
375329
private bool BranchInCompilerGeneratedClass(string methodName)
376330
{
377331
foreach (InstrumenterResult instrumentedResult in _results)

test/coverlet.core.tests/Coverage/CoverageTests.cs

-71
Original file line numberDiff line numberDiff line change
@@ -177,77 +177,6 @@ public void TestCoverageMergeWithWrongParameter()
177177

178178
directory.Delete(true);
179179
}
180-
181-
[Fact]
182-
public void TestCoverageUnloadWithParameters()
183-
{
184-
string module = GetType().Assembly.Location;
185-
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");
186-
187-
DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
188-
189-
File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true);
190-
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true);
191-
192-
var mockInstrumentationHelper = new Mock<IInstrumentationHelper>();
193-
194-
var parameters = new CoverageParameters
195-
{
196-
IncludeFilters = new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" },
197-
IncludeDirectories = Array.Empty<string>(),
198-
ExcludeFilters = Array.Empty<string>(),
199-
ExcludedSourceFiles = Array.Empty<string>(),
200-
ExcludeAttributes = Array.Empty<string>(),
201-
IncludeTestAssembly = false,
202-
SingleHit = false,
203-
MergeWith = string.Empty,
204-
UseSourceLink = false
205-
};
206-
207-
var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), parameters, _mockLogger.Object, mockInstrumentationHelper.Object, new FileSystem(), new SourceRootTranslator(_mockLogger.Object, new FileSystem()), new CecilSymbolHelper());
208-
coverage.PrepareModules();
209-
coverage.UnloadModule(Path.Combine(directory.FullName, Path.GetFileName(module)));
210-
211-
mockInstrumentationHelper.Verify(i => i.RestoreOriginalModule(It.Is<string>(v => v.Equals(Path.Combine(directory.FullName, Path.GetFileName(module)))), It.IsAny<string>()), Times.Once);
212-
_mockLogger.Verify(l => l.LogVerbose(It.Is<string>(v => v.Equals($"Module at {Path.Combine(directory.FullName, Path.GetFileName(module))} is unloaded."))), Times.Once);
213-
}
214-
215-
[Fact]
216-
public void TestCoverageUnloadWithNoParameters()
217-
{
218-
string module = GetType().Assembly.Location;
219-
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");
220-
221-
DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
222-
223-
File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true);
224-
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true);
225-
226-
var mockInstrumentationHelper = new Mock<IInstrumentationHelper>();
227-
mockInstrumentationHelper
228-
.Setup(x => x.SelectModules(It.IsAny<IEnumerable<string>>(), It.IsAny<string[]>(), It.IsAny<string[]>()))
229-
.Returns(new List<string>(){"ModuleX"});
230-
231-
var parameters = new CoverageParameters
232-
{
233-
IncludeFilters = new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" },
234-
IncludeDirectories = Array.Empty<string>(),
235-
ExcludeFilters = Array.Empty<string>(),
236-
ExcludedSourceFiles = Array.Empty<string>(),
237-
ExcludeAttributes = Array.Empty<string>(),
238-
IncludeTestAssembly = false,
239-
SingleHit = false,
240-
MergeWith = string.Empty,
241-
UseSourceLink = false
242-
};
243-
244-
var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), parameters, _mockLogger.Object, mockInstrumentationHelper.Object, new FileSystem(), new SourceRootTranslator(_mockLogger.Object, new FileSystem()), new CecilSymbolHelper());
245-
coverage.PrepareModules();
246-
coverage.UnloadModules();
247-
248-
mockInstrumentationHelper.Verify(i => i.RestoreOriginalModule(It.Is<string>(v => v.Equals("ModuleX")), It.IsAny<string>()), Times.Once);
249-
_mockLogger.Verify(l => l.LogVerbose(It.Is<string>(v => v.Equals("All Modules unloaded."))), Times.Once);
250-
}
251180
}
252181
}
253182

0 commit comments

Comments
 (0)