forked from coverlet-coverage/coverlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request coverlet-coverage#112 from derhally/master
Add support of ExcludeFromCodeCoverage attribute
- Loading branch information
Showing
6 changed files
with
155 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 48 additions & 6 deletions
54
test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,75 @@ | ||
using System; | ||
using System.IO; | ||
|
||
using System.Linq; | ||
using Xunit; | ||
using Coverlet.Core.Instrumentation; | ||
using Coverlet.Core.Samples.Tests; | ||
|
||
namespace Coverlet.Core.Instrumentation.Tests | ||
{ | ||
public class InstrumenterTests | ||
{ | ||
[Fact] | ||
public void TestInstrument() | ||
{ | ||
var instrumenterTest = CreateInstrumentor(); | ||
|
||
var result = instrumenterTest.Instrumenter.Instrument(); | ||
|
||
Assert.Equal(Path.GetFileNameWithoutExtension(instrumenterTest.Module), result.Module); | ||
Assert.Equal(instrumenterTest.Module, result.ModulePath); | ||
|
||
instrumenterTest.Directory.Delete(true); | ||
} | ||
|
||
[Theory] | ||
[InlineData(typeof(ClassExcludedByCodeAnalysisCodeCoverageAttr))] | ||
[InlineData(typeof(ClassExcludedByCoverletCodeCoverageAttr))] | ||
public void TestInstrument_ClassesWithExcludeAttributeAreExcluded(Type excludedType) | ||
{ | ||
var instrumenterTest = CreateInstrumentor(); | ||
var result = instrumenterTest.Instrumenter.Instrument(); | ||
|
||
var doc = result.Documents.FirstOrDefault(d => Path.GetFileName(d.Path) == "Samples.cs"); | ||
Assert.NotNull(doc); | ||
|
||
var found = doc.Lines.Any(l => l.Class == excludedType.FullName); | ||
Assert.False(found, "Class decorated with with exclude attribute should be excluded"); | ||
|
||
instrumenterTest.Directory.Delete(true); | ||
} | ||
|
||
private InstrumenterTest CreateInstrumentor() | ||
{ | ||
string module = GetType().Assembly.Location; | ||
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb"); | ||
string identifier = Guid.NewGuid().ToString(); | ||
|
||
var directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), identifier)); | ||
DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), identifier)); | ||
|
||
File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true); | ||
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true); | ||
|
||
module = Path.Combine(directory.FullName, Path.GetFileName(module)); | ||
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>()); | ||
var result = instrumenter.Instrument(); | ||
return new InstrumenterTest | ||
{ | ||
Instrumenter = instrumenter, | ||
Module = module, | ||
Identifier = identifier, | ||
Directory = directory | ||
}; | ||
} | ||
|
||
class InstrumenterTest | ||
{ | ||
public Instrumenter Instrumenter { get; set; } | ||
|
||
public string Module { get; set; } | ||
|
||
Assert.Equal(Path.GetFileNameWithoutExtension(module), result.Module); | ||
Assert.Equal(module, result.ModulePath); | ||
public string Identifier { get; set; } | ||
|
||
directory.Delete(true); | ||
public DirectoryInfo Directory { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters