|
1 | 1 | import cscFile from '../.github/csc.json'; |
2 | 2 | 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); |
6 | 6 |
|
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: { |
16 | 12 | file: 'Program.cs', |
17 | 13 | line: '10', |
| 14 | + column: '79', |
18 | 15 | severity: 'error', |
19 | 16 | code: 'CS1002', |
20 | 17 | message: '; expected', |
21 | 18 | fromPath: |
22 | 19 | '/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: { |
25 | 26 | file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs', |
26 | 27 | line: '33', |
| 28 | + column: '7', |
27 | 29 | severity: 'error', |
28 | 30 | code: 'CS1003', |
29 | 31 | message: "Syntax error, ',' expected", |
30 | 32 | fromPath: |
31 | 33 | 'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop' |
32 | 34 | } |
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(); |
34 | 86 |
|
35 | | - stringsToMatch.map((string, index) => { |
36 | | - const matchedResultsArray = string.match(regex); |
37 | | - for (const propName in expectedResults[index]) { |
| 87 | + for (const propName in results) { |
38 | 88 | const propertyIndex = regexResultsMap[propName]; |
39 | | - const expectedPropValue = expectedResults[index][propName]; |
| 89 | + const expectedPropValue = results[propName]; |
40 | 90 | const matchedPropValue = matchedResultsArray![propertyIndex]; |
41 | 91 | expect(matchedPropValue).toEqual(expectedPropValue); |
42 | 92 | } |
43 | | - }); |
44 | | - }, 10000); |
| 93 | + }, |
| 94 | + 10000 |
| 95 | + ); |
45 | 96 | }); |
0 commit comments