Visitar URL original
Expand the CSC problem matcher to light up more errors on GitHub. (#717) · actions/setup-dotnet@26b0ec1 · GitHub
Skip to content

Commit 26b0ec1

Browse files
Expand the CSC problem matcher to light up more errors on GitHub. (#717)
Expand csc problem matcher with more real-world scenarios. Co-authored-by: Stephen Cleary <900597+StephenCleary@users.noreply.github.com>
1 parent da5e548 commit 26b0ec1

2 files changed

Lines changed: 78 additions & 26 deletions

File tree

‎.github/csc.json‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"owner": "csc",
55
"pattern": [
66
{
7-
"regexp": "^([^\\s].*)\\((\\d+)(?:,\\d+|,\\d+,\\d+)?\\):\\s+(error|warning)\\s+([a-zA-Z]+(?<!MSB)\\d+):\\s*(.*?)\\s+\\[(.*?)\\]$",
7+
"regexp": "^\\s*(?:\\d+>\\s*)?([^\\s].*)\\((\\d+)(?:,(\\d+))?(?:,\\d+)*\\):\\s+(error|warning)\\s+([a-zA-Z]+(?<!MSB)\\d*):\\s*(.*?)\\s+\\[(.*?)\\]$",
88
"file": 1,
99
"line": 2,
10-
"severity": 3,
11-
"code": 4,
12-
"message": 5,
13-
"fromPath": 6
10+
"column": 3,
11+
"severity": 4,
12+
"code": 5,
13+
"message": 6,
14+
"fromPath": 7
1415
}
1516
]
1617
}

‎__tests__/csc.test.ts‎

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,96 @@
11
import cscFile from '../.github/csc.json';
22
describe('csc tests', () => {
3-
test('regular expression in csc.json is valid', async () => {
4-
const regexPattern = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
5-
const regexResultsMap = cscFile['problemMatcher'][0]['pattern'][0];
3+
const regexPattern = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
4+
const regexResultsMap = cscFile['problemMatcher'][0]['pattern'][0];
5+
const regex = new RegExp(regexPattern);
66

7-
const regex = new RegExp(regexPattern);
8-
9-
const stringsToMatch = [
10-
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
11-
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]"
12-
];
13-
// Expected results are calculated according to the csc matcher located in csc.json file
14-
const expectedResults = [
15-
{
7+
const testCases: Array<{input: string; results: Record<string, string>}> = [
8+
{
9+
input:
10+
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
11+
results: {
1612
file: 'Program.cs',
1713
line: '10',
14+
column: '79',
1815
severity: 'error',
1916
code: 'CS1002',
2017
message: '; expected',
2118
fromPath:
2219
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
23-
},
24-
{
20+
}
21+
},
22+
{
23+
input:
24+
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]",
25+
results: {
2526
file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs',
2627
line: '33',
28+
column: '7',
2729
severity: 'error',
2830
code: 'CS1003',
2931
message: "Syntax error, ',' expected",
3032
fromPath:
3133
'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop'
3234
}
33-
];
35+
},
36+
{
37+
// `dotnet format` style error
38+
input:
39+
'C:\\actions-runner\\_work\\Some\\Folder\\SomeFile.cs(222,8): error WHITESPACE: Fix whitespace formatting. Delete 1 characters. [C:\\actions-runner\\_work\\Some\\Folder\\SomeProject.csproj]',
40+
results: {
41+
file: 'C:\\actions-runner\\_work\\Some\\Folder\\SomeFile.cs',
42+
line: '222',
43+
column: '8',
44+
severity: 'error',
45+
code: 'WHITESPACE',
46+
message: 'Fix whitespace formatting. Delete 1 characters.',
47+
fromPath: 'C:\\actions-runner\\_work\\Some\\Folder\\SomeProject.csproj'
48+
}
49+
},
50+
{
51+
// CSC error with whitespace prefix
52+
input:
53+
' /Volumes/Code/ghe_actions-2.301.1/Some/Folder/SomeFile.cs(10,8): error CS1014: A get or set accessor expected [/Volumes/Code/ghe_actions-2.301.1/Some/Folder/SomeProject.csproj]',
54+
results: {
55+
file: '/Volumes/Code/ghe_actions-2.301.1/Some/Folder/SomeFile.cs',
56+
line: '10',
57+
column: '8',
58+
severity: 'error',
59+
code: 'CS1014',
60+
message: 'A get or set accessor expected',
61+
fromPath:
62+
'/Volumes/Code/ghe_actions-2.301.1/Some/Folder/SomeProject.csproj'
63+
}
64+
},
65+
{
66+
// CSC error with MSBuild prefix
67+
input:
68+
' 20>C:\\actions-runner\\_work\\Some\\Folder\\SomeFile.cs(8,2): error CS1014: A get or set accessor expected [C:\\actions-runner\\_work\\Some\\Folder\\SomeProject.csproj]',
69+
results: {
70+
file: 'C:\\actions-runner\\_work\\Some\\Folder\\SomeFile.cs',
71+
line: '8',
72+
column: '2',
73+
severity: 'error',
74+
code: 'CS1014',
75+
message: 'A get or set accessor expected',
76+
fromPath: 'C:\\actions-runner\\_work\\Some\\Folder\\SomeProject.csproj'
77+
}
78+
}
79+
];
80+
81+
test.each(testCases)(
82+
'regex matches and parses: $input',
83+
({input, results}: {input: string; results: Record<string, string>}) => {
84+
const matchedResultsArray = input.match(regex);
85+
expect(matchedResultsArray).not.toBeNull();
3486

35-
stringsToMatch.map((string, index) => {
36-
const matchedResultsArray = string.match(regex);
37-
for (const propName in expectedResults[index]) {
87+
for (const propName in results) {
3888
const propertyIndex = regexResultsMap[propName];
39-
const expectedPropValue = expectedResults[index][propName];
89+
const expectedPropValue = results[propName];
4090
const matchedPropValue = matchedResultsArray![propertyIndex];
4191
expect(matchedPropValue).toEqual(expectedPropValue);
4292
}
43-
});
44-
}, 10000);
93+
},
94+
10000
95+
);
4596
});

0 commit comments

Comments
 (0)