Skip to content

Commit 23dca2a

Browse files
committed
Add tests; modify readme
1 parent 529c79e commit 23dca2a

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ You can ignore a method or an entire class from code coverage by creating and ap
8787
Coverlet just uses the type name, so the attributes can be created under any namespace of your choosing.
8888

8989
#### File Path
90-
You can also ignore code coverage by specifing files using the `Exclude` property
90+
You can also ignore specific source files from code coverage using the `Exclude` property
9191
- Use single or multiple paths (separate by comma)
9292
- Use absolute or relative paths (relative to the project directory)
9393
- Use file path or directory path with globbing (e.g `dir1/*.cs`)

test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
using System.IO;
33

44
using Xunit;
5-
using Coverlet.Core.Helpers;
5+
using System.Collections.Generic;
6+
using System.Linq;
67

78
namespace Coverlet.Core.Helpers.Tests
89
{
910
public class InstrumentationHelperTests
10-
{
11+
{
1112
[Fact]
1213
public void TestGetDependencies()
1314
{
@@ -79,5 +80,63 @@ public void TestDeleteHitsFile()
7980
InstrumentationHelper.DeleteHitsFile(tempFile);
8081
Assert.False(File.Exists(tempFile));
8182
}
83+
84+
85+
public static IEnumerable<object[]> GetExcludedFilesReturnsEmptyArgs =>
86+
new[]
87+
{
88+
new object[]{null},
89+
new object[]{new List<string>()},
90+
new object[]{new List<string>(){ Path.GetRandomFileName() }},
91+
new object[]{new List<string>(){Path.GetRandomFileName(),
92+
Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName())}
93+
}
94+
};
95+
96+
[Theory]
97+
[MemberData(nameof(GetExcludedFilesReturnsEmptyArgs))]
98+
public void TestGetExcludedFilesReturnsEmpty(IEnumerable<string> excludedFiles)
99+
{
100+
Assert.False(InstrumentationHelper.GetExcludedFiles(excludedFiles)?.Any());
101+
}
102+
103+
[Fact]
104+
public void TestGetExcludedFilesUsingAbsFile()
105+
{
106+
var file = Path.GetRandomFileName();
107+
File.Create(file).Dispose();
108+
var excludeFiles = InstrumentationHelper.GetExcludedFiles(
109+
new List<string>() {Path.Combine(Directory.GetCurrentDirectory(), file)}
110+
);
111+
File.Delete(file);
112+
Assert.Single(excludeFiles);
113+
}
114+
115+
[Fact]
116+
public void TestGetExcludedFilesUsingGlobbing()
117+
{
118+
var fileExtension = Path.GetRandomFileName();
119+
var paths = new string[]{
120+
$"{Path.GetRandomFileName()}.{fileExtension}",
121+
$"{Path.GetRandomFileName()}.{fileExtension}"
122+
};
123+
124+
foreach (var path in paths)
125+
{
126+
File.Create(path).Dispose();
127+
}
128+
129+
var excludeFiles = InstrumentationHelper.GetExcludedFiles(
130+
new List<string>(){$"*.{fileExtension}"});
131+
132+
foreach (var path in paths)
133+
{
134+
File.Delete(path);
135+
}
136+
137+
Assert.Equal(paths.Length, excludeFiles.Count());
138+
}
82139
}
83-
}
140+
}
141+
142+

0 commit comments

Comments
 (0)