Skip to content

Commit d481c08

Browse files
Copilotpascalberger
andcommitted
Fix build warnings in JUnit provider code
Co-authored-by: pascalberger <[email protected]>
1 parent 7f2beaa commit d481c08

File tree

3 files changed

+159
-159
lines changed

3 files changed

+159
-159
lines changed

src/Cake.Issues.JUnit/LogFileFormat/CppLintLogFileFormat.cs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,41 @@ public override IEnumerable<IIssue> ReadIssues(
5656
return result;
5757
}
5858

59+
/// <summary>
60+
/// Normalizes XML content by removing XML formatting indentation while preserving intentional structure.
61+
/// </summary>
62+
/// <param name="content">The XML content to normalize.</param>
63+
/// <returns>The normalized content.</returns>
64+
private static string NormalizeXmlContent(string content)
65+
{
66+
if (string.IsNullOrEmpty(content))
67+
{
68+
return string.Empty;
69+
}
70+
71+
// Split by lines, trim each line to remove XML indentation, then rejoin
72+
var lines = content.Split(['\r', '\n'], StringSplitOptions.None);
73+
var normalizedLines = new List<string>();
74+
75+
foreach (var line in lines)
76+
{
77+
// Trim leading and trailing whitespace (including tabs) from each line
78+
var trimmedLine = line.Trim();
79+
normalizedLines.Add(trimmedLine);
80+
}
81+
82+
// Join lines back together and clean up multiple consecutive empty lines
83+
var result = string.Join("\n", normalizedLines);
84+
85+
// Remove leading and trailing empty lines
86+
result = result.Trim('\n');
87+
88+
// Normalize multiple consecutive newlines to double newlines maximum
89+
result = Regex.Replace(result, @"\n{3,}", "\n\n");
90+
91+
return result;
92+
}
93+
5994
/// <summary>
6095
/// Recursively processes a testsuite element and its nested testsuites and testcases.
6196
/// </summary>
@@ -78,7 +113,7 @@ private void ProcessTestSuite(XElement testSuite, List<IIssue> result, IReposito
78113
// Process failures
79114
foreach (var failure in testCase.Elements("failure"))
80115
{
81-
var issue = this.ProcessCppLintFailure(failure, className, testName, IssuePriority.Error, repositorySettings);
116+
var issue = this.ProcessCppLintFailure(failure, testName, IssuePriority.Error, repositorySettings);
82117
if (issue != null)
83118
{
84119
result.Add(issue);
@@ -88,7 +123,7 @@ private void ProcessTestSuite(XElement testSuite, List<IIssue> result, IReposito
88123
// Process errors
89124
foreach (var error in testCase.Elements("error"))
90125
{
91-
var issue = this.ProcessCppLintFailure(error, className, testName, IssuePriority.Error, repositorySettings);
126+
var issue = this.ProcessCppLintFailure(error, testName, IssuePriority.Error, repositorySettings);
92127
if (issue != null)
93128
{
94129
result.Add(issue);
@@ -103,51 +138,15 @@ private void ProcessTestSuite(XElement testSuite, List<IIssue> result, IReposito
103138
}
104139
}
105140

106-
/// <summary>
107-
/// Normalizes XML content by removing XML formatting indentation while preserving intentional structure.
108-
/// </summary>
109-
/// <param name="content">The XML content to normalize.</param>
110-
/// <returns>The normalized content.</returns>
111-
private static string NormalizeXmlContent(string content)
112-
{
113-
if (string.IsNullOrEmpty(content))
114-
{
115-
return string.Empty;
116-
}
117-
118-
// Split by lines, trim each line to remove XML indentation, then rejoin
119-
var lines = content.Split(new[] { '\r', '\n' }, StringSplitOptions.None);
120-
var normalizedLines = new List<string>();
121-
122-
foreach (var line in lines)
123-
{
124-
// Trim leading and trailing whitespace (including tabs) from each line
125-
var trimmedLine = line.Trim();
126-
normalizedLines.Add(trimmedLine);
127-
}
128-
129-
// Join lines back together and clean up multiple consecutive empty lines
130-
var result = string.Join("\n", normalizedLines);
131-
132-
// Remove leading and trailing empty lines
133-
result = result.Trim('\n');
134-
135-
// Normalize multiple consecutive newlines to double newlines maximum
136-
result = Regex.Replace(result, @"\n{3,}", "\n\n");
137-
138-
return result;
139-
}
140-
141141
/// <summary>
142142
/// Processes a cpplint test failure or error element and creates an issue.
143143
/// </summary>
144144
/// <param name="failureElement">The failure or error XML element.</param>
145-
/// <param name="className">The test class name.</param>
146145
/// <param name="testName">The test name.</param>
147146
/// <param name="priority">The issue priority.</param>
148147
/// <param name="repositorySettings">Repository settings.</param>
149148
/// <returns>The created issue or null if the failure should be ignored.</returns>
150-
private IIssue ProcessCppLintFailure(XElement failureElement, string className, string testName, IssuePriority priority, IRepositorySettings repositorySettings)
149+
private IIssue ProcessCppLintFailure(XElement failureElement, string testName, IssuePriority priority, IRepositorySettings repositorySettings)
151150
{
152151
var message = failureElement.Attribute("message")?.Value ?? string.Empty;
153152
var type = failureElement.Attribute("type")?.Value ?? string.Empty;
@@ -188,12 +187,13 @@ private IIssue ProcessCppLintFailure(XElement failureElement, string className,
188187
RegexOptions.Multiline);
189188
if (lineMatch.Success && int.TryParse(lineMatch.Groups[1].Value, out var lineNum))
190189
{
191-
var pathValidation = ValidateFilePath(testName, repositorySettings);
192-
if (pathValidation.Valid)
190+
var (valid, filePath) = ValidateFilePath(testName, repositorySettings);
191+
if (valid)
193192
{
194-
issueBuilder = issueBuilder.InFile(pathValidation.FilePath, lineNum, null);
193+
issueBuilder = issueBuilder.InFile(filePath, lineNum, null);
195194
}
196195
}
196+
197197
// Also check for simple line number pattern without the category/subcategory format
198198
else
199199
{
@@ -207,10 +207,10 @@ private IIssue ProcessCppLintFailure(XElement failureElement, string className,
207207
// Only treat as file if the test name doesn't contain hyphens (which are common in rule names)
208208
if (!testName.Contains('-') && !testName.Contains('_'))
209209
{
210-
var pathValidation = ValidateFilePath(testName, repositorySettings);
211-
if (pathValidation.Valid)
210+
var (valid, filePath) = ValidateFilePath(testName, repositorySettings);
211+
if (valid)
212212
{
213-
issueBuilder = issueBuilder.InFile(pathValidation.FilePath, simpleLineNum, null);
213+
issueBuilder = issueBuilder.InFile(filePath, simpleLineNum, null);
214214
}
215215
}
216216
}

src/Cake.Issues.JUnit/LogFileFormat/GenericJUnitLogFileFormat.cs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,53 +56,6 @@ public override IEnumerable<IIssue> ReadIssues(
5656
return result;
5757
}
5858

59-
/// <summary>
60-
/// Recursively processes a testsuite element and its nested testsuites and testcases.
61-
/// </summary>
62-
/// <param name="testSuite">The testsuite element to process.</param>
63-
/// <param name="result">The list to add found issues to.</param>
64-
/// <param name="repositorySettings">Repository settings.</param>
65-
private void ProcessTestSuite(XElement testSuite, List<IIssue> result, IRepositorySettings repositorySettings)
66-
{
67-
if (testSuite == null)
68-
{
69-
return;
70-
}
71-
72-
// Process direct testcase children
73-
foreach (var testCase in testSuite.Elements("testcase"))
74-
{
75-
var className = testCase.Attribute("classname")?.Value ?? string.Empty;
76-
var testName = testCase.Attribute("name")?.Value ?? string.Empty;
77-
78-
// Process failures
79-
foreach (var failure in testCase.Elements("failure"))
80-
{
81-
var issue = this.ProcessTestFailure(failure, className, testName, IssuePriority.Error, repositorySettings);
82-
if (issue != null)
83-
{
84-
result.Add(issue);
85-
}
86-
}
87-
88-
// Process errors
89-
foreach (var error in testCase.Elements("error"))
90-
{
91-
var issue = this.ProcessTestFailure(error, className, testName, IssuePriority.Error, repositorySettings);
92-
if (issue != null)
93-
{
94-
result.Add(issue);
95-
}
96-
}
97-
}
98-
99-
// Recursively process nested testsuite elements
100-
foreach (var nestedTestSuite in testSuite.Elements("testsuite"))
101-
{
102-
this.ProcessTestSuite(nestedTestSuite, result, repositorySettings);
103-
}
104-
}
105-
10659
/// <summary>
10760
/// Normalizes XML content by removing XML formatting indentation while preserving intentional structure.
10861
/// </summary>
@@ -116,7 +69,7 @@ private static string NormalizeXmlContent(string content)
11669
}
11770

11871
// Split by lines, trim each line to remove XML indentation, then rejoin
119-
var lines = content.Split(new[] { '\r', '\n' }, StringSplitOptions.None);
72+
var lines = content.Split(['\r', '\n'], StringSplitOptions.None);
12073
var normalizedLines = new List<string>();
12174

12275
foreach (var line in lines)
@@ -128,13 +81,13 @@ private static string NormalizeXmlContent(string content)
12881

12982
// Join lines back together and clean up multiple consecutive empty lines
13083
var result = string.Join("\n", normalizedLines);
131-
84+
13285
// Remove leading and trailing empty lines
13386
result = result.Trim('\n');
134-
87+
13588
// Normalize multiple consecutive newlines to double newlines maximum
13689
result = Regex.Replace(result, @"\n{3,}", "\n\n");
137-
90+
13891
return result;
13992
}
14093

@@ -189,15 +142,15 @@ private static (string FilePath, int? Line, int? Column)? ExtractFileInfoFromOut
189142
// file.txt line 123: message
190143
// /path/to/file.txt:123: message
191144
// file.txt:123 message
192-
var patterns = new[]
193-
{
145+
string[] patterns =
146+
[
194147
@"([^\s:]+):(\d+):(\d+)", // file:line:column
195148
@"([^\s:]+):(\d+)", // file:line
196149
@"([^\s\(\)]+)\((\d+),(\d+)\)", // file(line,column)
197150
@"([^\s\(\)]+)\((\d+)\)", // file(line)
198151
@"^([^\s]+)\s+line\s+(\d+)", // file line 123 (must start at beginning of line)
199152
@"File:\s*([^\s]+)", // File: path
200-
};
153+
];
201154

202155
foreach (var pattern in patterns)
203156
{
@@ -232,6 +185,53 @@ private static (string FilePath, int? Line, int? Column)? ExtractFileInfoFromOut
232185
return null;
233186
}
234187

188+
/// <summary>
189+
/// Recursively processes a testsuite element and its nested testsuites and testcases.
190+
/// </summary>
191+
/// <param name="testSuite">The testsuite element to process.</param>
192+
/// <param name="result">The list to add found issues to.</param>
193+
/// <param name="repositorySettings">Repository settings.</param>
194+
private void ProcessTestSuite(XElement testSuite, List<IIssue> result, IRepositorySettings repositorySettings)
195+
{
196+
if (testSuite == null)
197+
{
198+
return;
199+
}
200+
201+
// Process direct testcase children
202+
foreach (var testCase in testSuite.Elements("testcase"))
203+
{
204+
var className = testCase.Attribute("classname")?.Value ?? string.Empty;
205+
var testName = testCase.Attribute("name")?.Value ?? string.Empty;
206+
207+
// Process failures
208+
foreach (var failure in testCase.Elements("failure"))
209+
{
210+
var issue = this.ProcessTestFailure(failure, className, testName, IssuePriority.Error, repositorySettings);
211+
if (issue != null)
212+
{
213+
result.Add(issue);
214+
}
215+
}
216+
217+
// Process errors
218+
foreach (var error in testCase.Elements("error"))
219+
{
220+
var issue = this.ProcessTestFailure(error, className, testName, IssuePriority.Error, repositorySettings);
221+
if (issue != null)
222+
{
223+
result.Add(issue);
224+
}
225+
}
226+
}
227+
228+
// Recursively process nested testsuite elements
229+
foreach (var nestedTestSuite in testSuite.Elements("testsuite"))
230+
{
231+
this.ProcessTestSuite(nestedTestSuite, result, repositorySettings);
232+
}
233+
}
234+
235235
/// <summary>
236236
/// Processes a test failure or error element and creates an issue.
237237
/// </summary>
@@ -276,10 +276,10 @@ private IIssue ProcessTestFailure(XElement failureElement, string className, str
276276
if (fileInfo.HasValue)
277277
{
278278
var (filePath, line, column) = fileInfo.Value;
279-
var pathValidation = ValidateFilePath(filePath, repositorySettings);
280-
if (pathValidation.Valid)
279+
var (valid, validatedPath) = ValidateFilePath(filePath, repositorySettings);
280+
if (valid)
281281
{
282-
issueBuilder = issueBuilder.InFile(pathValidation.FilePath, line, column);
282+
issueBuilder = issueBuilder.InFile(validatedPath, line, column);
283283
}
284284
}
285285

0 commit comments

Comments
 (0)