1
1
namespace Cake . Issues . Reporting . Console . Tests ;
2
2
3
+ using System . Text . RegularExpressions ;
4
+ using Cake . Core . Diagnostics ;
5
+ using Spectre . Console ;
6
+ using Spectre . Console . Testing ;
3
7
using Xunit . Abstractions ;
4
8
5
- public sealed class ConsoleIssueReportGeneratorTests
9
+ public sealed partial class ConsoleIssueReportGeneratorTests
6
10
{
7
11
public sealed class TheCtor
8
12
{
13
+ [ Fact ]
14
+ public void Should_Throw_If_Console_Is_Null ( )
15
+ {
16
+ // Given
17
+ IAnsiConsole console = null ;
18
+ var log = new FakeLog ( ) ;
19
+ var settings = new ConsoleIssueReportFormatSettings ( ) ;
20
+
21
+ // When
22
+ var result = Record . Exception ( ( ) =>
23
+ new ConsoleIssueReportGenerator (
24
+ console ,
25
+ log ,
26
+ settings ) ) ;
27
+
28
+ // Then
29
+ result . IsArgumentNullException ( "console" ) ;
30
+ }
31
+
9
32
[ Fact ]
10
33
public void Should_Throw_If_Log_Is_Null ( )
11
34
{
12
- // Given / When
35
+ // Given
36
+ var console = new TestConsole ( ) ;
37
+ ICakeLog log = null ;
38
+ var settings = new ConsoleIssueReportFormatSettings ( ) ;
39
+
40
+ // When
13
41
var result = Record . Exception ( ( ) =>
14
42
new ConsoleIssueReportGenerator (
15
- null ,
16
- new ConsoleIssueReportFormatSettings ( ) ) ) ;
43
+ console ,
44
+ log ,
45
+ settings ) ) ;
17
46
18
47
// Then
19
48
result . IsArgumentNullException ( "log" ) ;
@@ -22,18 +51,24 @@ public void Should_Throw_If_Log_Is_Null()
22
51
[ Fact ]
23
52
public void Should_Throw_If_Settings_Are_Null ( )
24
53
{
25
- // Given / When
54
+ // Given
55
+ var console = new TestConsole ( ) ;
56
+ var log = new FakeLog ( ) ;
57
+ ConsoleIssueReportFormatSettings settings = null ;
58
+
59
+ // When
26
60
var result = Record . Exception ( ( ) =>
27
61
new ConsoleIssueReportGenerator (
28
- new FakeLog ( ) ,
29
- null ) ) ;
62
+ console ,
63
+ log ,
64
+ settings ) ) ;
30
65
31
66
// Then
32
67
result . IsArgumentNullException ( "settings" ) ;
33
68
}
34
69
}
35
70
36
- public sealed class TheInternalCreateReportMethod
71
+ public sealed partial class TheInternalCreateReportMethod
37
72
{
38
73
public static IEnumerable < object [ ] > ReportFormatSettingsCombinations =>
39
74
from b1 in boolArray
@@ -68,7 +103,7 @@ public void Should_Generate_Report(
68
103
} ;
69
104
70
105
// When
71
- _ = fixture . CreateReportForTestfile (
106
+ fixture . CreateReportForTestfile (
72
107
"Testfiles.issues.json" ,
73
108
@"c:\Source\Cake.Issues.Reporting.Console" ) ;
74
109
@@ -98,15 +133,21 @@ public void Should_Generate_Report_With_No_Issues(
98
133
} ;
99
134
100
135
// When
101
- _ = fixture . CreateReport (
136
+ fixture . CreateReport (
102
137
[ ] ,
103
138
@"c:\Source\Cake.Issues.Reporting.Console" ) ;
104
139
105
140
// Then
106
141
}
107
142
108
- public sealed class WithShowDiagnosticsEnabled ( ITestOutputHelper output )
143
+ public sealed partial class WithShowDiagnosticsEnabled ( ITestOutputHelper output )
109
144
{
145
+ // (?<=┌─\[) — positive lookbehind to assert the match is preceded by ┌─[
146
+ // [^\]]+ — matches one or more characters that are not a closing bracket ]
147
+ // (?=\]) — positive lookahead to assert the match is followed by ]
148
+ [ GeneratedRegex ( @"(?<=┌─\[)[^\]]+(?=\])" ) ]
149
+ private static partial Regex DiagnosticRegEx ( ) ;
150
+
110
151
[ Fact ]
111
152
public void Should_Filter_Issues_Without_FilePath ( )
112
153
{
@@ -128,7 +169,7 @@ public void Should_Filter_Issues_Without_FilePath()
128
169
} ;
129
170
130
171
// When
131
- _ = fixture . CreateReport ( issues , @"c:\Source\Cake.Issues.Reporting.Console" ) ;
172
+ fixture . CreateReport ( issues , @"c:\Source\Cake.Issues.Reporting.Console" ) ;
132
173
133
174
// Then
134
175
fixture . Log . Entries . ShouldContain ( x => x . Message == "1 issue(s) were filtered because they either don't belong to a file or the file does not exist." ) ;
@@ -155,7 +196,7 @@ public void Should_Filter_Issues_Where_File_Does_Not_Exist()
155
196
} ;
156
197
157
198
// When
158
- _ = fixture . CreateReport ( issues , @"c:\Source\Cake.Issues.Reporting.Console" ) ;
199
+ fixture . CreateReport ( issues , @"c:\Source\Cake.Issues.Reporting.Console" ) ;
159
200
160
201
// Then
161
202
fixture . Log . Entries . ShouldContain ( x => x . Message == "1 issue(s) were filtered because they either don't belong to a file or the file does not exist." ) ;
@@ -187,7 +228,7 @@ public void Should_Not_Filter_Issues_With_Existing_File()
187
228
} ;
188
229
189
230
// When
190
- _ = fixture . CreateReport ( issues , directory ) ;
231
+ fixture . CreateReport ( issues , directory ) ;
191
232
192
233
// Then
193
234
fixture . Log . Entries . ShouldContain ( x => x . Message == "0 issue(s) were filtered because they either don't belong to a file or the file does not exist." ) ;
@@ -218,7 +259,7 @@ public void Should_Work_Without_Priority()
218
259
. Create ( ) ,
219
260
} ;
220
261
// When
221
- _ = fixture . CreateReport ( issues , directory ) ;
262
+ fixture . CreateReport ( issues , directory ) ;
222
263
223
264
// Then
224
265
}
@@ -249,10 +290,49 @@ public void Should_Work_With_Priority()
249
290
. Create ( ) ,
250
291
} ;
251
292
// When
252
- _ = fixture . CreateReport ( issues , directory ) ;
293
+ fixture . CreateReport ( issues , directory ) ;
253
294
254
295
// Then
255
296
}
297
+
298
+ [ Fact ]
299
+ public Task Should_Work_With_Issue_On_End_Of_Line ( )
300
+ {
301
+ // Given
302
+ using var tempSourceFile = new TemporarySourceFile ( "Testfiles.TestFile.txt" ) ;
303
+ var filePath = tempSourceFile . FilePath ;
304
+ output . WriteLine ( $ "File path: { filePath } ") ;
305
+ var directory = Path . GetDirectoryName ( filePath ) ! ;
306
+ var fileName = Path . GetFileName ( filePath ) ;
307
+ var fixture = new ConsoleIssueReportFixture
308
+ {
309
+ ConsoleIssueReportFormatSettings =
310
+ {
311
+ ShowDiagnostics = true
312
+ }
313
+ } ;
314
+ var issues =
315
+ new List < IIssue >
316
+ {
317
+ IssueBuilder
318
+ . NewIssue ( "Message Foo" , "ProviderType Foo" , "ProviderName Foo" )
319
+ . InFile ( fileName , 1 , 57 ) // Position after the last character on line 1
320
+ . Create ( ) ,
321
+ } ;
322
+ // When
323
+ fixture . CreateReport ( issues , directory ) ;
324
+
325
+ // Then
326
+ // Add a scrubber that replaces the dynamic ID in the output
327
+ var settings = new VerifySettings ( ) ;
328
+ settings . AddScrubber ( builder =>
329
+ {
330
+ var updated = DiagnosticRegEx ( ) . Replace ( builder . ToString ( ) , "<DYNAMIC_ID>" ) ;
331
+
332
+ _ = builder . Clear ( ) . Append ( updated ) ;
333
+ } ) ;
334
+ return Verify ( fixture . Console . Output , settings ) ;
335
+ }
256
336
}
257
337
}
258
338
}
0 commit comments