2
2
using System . IO ;
3
3
4
4
using Xunit ;
5
- using Coverlet . Core . Helpers ;
5
+ using System . Collections . Generic ;
6
+ using System . Linq ;
6
7
7
8
namespace Coverlet . Core . Helpers . Tests
8
9
{
9
10
public class InstrumentationHelperTests
10
- {
11
+ {
11
12
[ Fact ]
12
13
public void TestGetDependencies ( )
13
14
{
@@ -79,5 +80,63 @@ public void TestDeleteHitsFile()
79
80
InstrumentationHelper . DeleteHitsFile ( tempFile ) ;
80
81
Assert . False ( File . Exists ( tempFile ) ) ;
81
82
}
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
+ }
82
139
}
83
- }
140
+ }
141
+
142
+
0 commit comments