Skip to content

Commit afa590d

Browse files
authored
Fixes reporting issues without priority to console (#1254)
1 parent 624ae9d commit afa590d

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/Cake.Issues.Reporting.Console.Tests/ConsoleIssueReportGeneratorTests.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,67 @@ public void Should_Not_Filter_Issues_With_Existing_File()
192192
// Then
193193
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.");
194194
}
195+
196+
[Fact]
197+
public void Should_Work_Without_Priority()
198+
{
199+
// Given
200+
using var tempSourceFile = new TemporarySourceFile("Testfiles.TestFile.txt");
201+
var filePath = tempSourceFile.FilePath;
202+
output.WriteLine($"File path: {filePath}");
203+
var directory = Path.GetDirectoryName(filePath)!;
204+
var fileName = Path.GetFileName(filePath);
205+
var fixture = new ConsoleIssueReportFixture
206+
{
207+
ConsoleIssueReportFormatSettings =
208+
{
209+
ShowDiagnostics = true
210+
}
211+
};
212+
var issues =
213+
new List<IIssue>
214+
{
215+
IssueBuilder
216+
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
217+
.InFile(fileName, 1, 1)
218+
.Create(),
219+
};
220+
// When
221+
_ = fixture.CreateReport(issues, directory);
222+
223+
// Then
224+
}
225+
226+
[Fact]
227+
public void Should_Work_With_Priority()
228+
{
229+
// Given
230+
using var tempSourceFile = new TemporarySourceFile("Testfiles.TestFile.txt");
231+
var filePath = tempSourceFile.FilePath;
232+
output.WriteLine($"File path: {filePath}");
233+
var directory = Path.GetDirectoryName(filePath)!;
234+
var fileName = Path.GetFileName(filePath);
235+
var fixture = new ConsoleIssueReportFixture
236+
{
237+
ConsoleIssueReportFormatSettings =
238+
{
239+
ShowDiagnostics = true
240+
}
241+
};
242+
var issues =
243+
new List<IIssue>
244+
{
245+
IssueBuilder
246+
.NewIssue("Message Foo", "ProviderType Foo", "ProviderName Foo")
247+
.InFile(fileName, 1, 1)
248+
.WithPriority(IssuePriority.Error)
249+
.Create(),
250+
};
251+
// When
252+
_ = fixture.CreateReport(issues, directory);
253+
254+
// Then
255+
}
195256
}
196257
}
197258
}

src/Cake.Issues.Reporting.Console/IssueDiagnostic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public IssueDiagnostic(IEnumerable<IIssue> issues)
4242
(int)IssuePriority.Warning => Color.Yellow,
4343
(int)IssuePriority.Suggestion => Color.Blue,
4444
(int)IssuePriority.Hint => Color.LightSkyBlue1,
45-
_ => throw new Exception(),
45+
_ => this.Color,
4646
};
4747

4848
var noteComponents = new List<string>();
@@ -108,7 +108,7 @@ private void CreateLabels()
108108
(int)IssuePriority.Error => Color.Red,
109109
(int)IssuePriority.Warning => Color.Yellow,
110110
(int)IssuePriority.Suggestion or (int)IssuePriority.Hint => Color.Blue,
111-
_ => throw new Exception(),
111+
_ => Color.White,
112112
};
113113

114114
foreach (var issue in this.issues)

0 commit comments

Comments
 (0)