|
| 1 | +import csc from '../.github/csc.json'; |
1 | 2 | import dotnetFormat from '../.github/dotnet-format.json'; |
2 | 3 |
|
| 4 | +// Unit tests for problem matchers |
| 5 | +// https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md |
| 6 | + |
| 7 | +describe('/.github/csc.json tests', () => { |
| 8 | + const problemMatcher = csc.problemMatcher[0].pattern[0]; |
| 9 | + |
| 10 | + it.each([ |
| 11 | + [ |
| 12 | + 'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]', |
| 13 | + { |
| 14 | + file: 'Program.cs', |
| 15 | + line: '10', |
| 16 | + severity: 'error', |
| 17 | + code: 'CS1002', |
| 18 | + message: '; expected', |
| 19 | + fromPath: |
| 20 | + '/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj' |
| 21 | + } |
| 22 | + ], |
| 23 | + [ |
| 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 | + { |
| 26 | + file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs', |
| 27 | + line: '33', |
| 28 | + severity: 'error', |
| 29 | + code: 'CS1003', |
| 30 | + message: "Syntax error, ',' expected", |
| 31 | + fromPath: |
| 32 | + 'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop' |
| 33 | + } |
| 34 | + ] |
| 35 | + ])('log "%s" matches %o', (logOutput, expected) => { |
| 36 | + const regexp = new RegExp(problemMatcher.regexp); |
| 37 | + const res = logOutput.match(regexp); |
| 38 | + |
| 39 | + for (const key in expected) { |
| 40 | + expect(res?.[problemMatcher[key]]).toBe(expected[key]); |
| 41 | + } |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
3 | 45 | describe('/.github/dotnet-format.json tests', () => { |
4 | 46 | const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0]; |
5 | 47 |
|
6 | 48 | it.each([ |
7 | 49 | [ |
8 | 50 | "/home/runner/work/repo/Test.cs(18,6): error WHITESPACE: Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'. [/home/runner/work/repo/Test.csproj]", |
9 | | - '/home/runner/work/repo/Test.cs', |
10 | | - '18', |
11 | | - '6', |
12 | | - 'error', |
13 | | - 'WHITESPACE', |
14 | | - "Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.", |
15 | | - '/home/runner/work/repo/Test.csproj' |
| 51 | + { |
| 52 | + file: '/home/runner/work/repo/Test.cs', |
| 53 | + line: '18', |
| 54 | + column: '6', |
| 55 | + severity: 'error', |
| 56 | + code: 'WHITESPACE', |
| 57 | + message: |
| 58 | + "Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.", |
| 59 | + fromPath: '/home/runner/work/repo/Test.csproj' |
| 60 | + } |
16 | 61 | ] |
17 | | - ])( |
18 | | - '"%s" returns {file: "%s", line: "%s", column: "%s", severity: "%s", code: "%s", message: "%s", fromPath: "%s"}', |
19 | | - (logOutput, file, line, column, severity, code, message, fromPath) => { |
20 | | - const regexp = new RegExp(problemMatcher.regexp); |
21 | | - const res = logOutput.match(regexp); |
| 62 | + ])('log "%s" matches %o', (logOutput, expected) => { |
| 63 | + const regexp = new RegExp(problemMatcher.regexp); |
| 64 | + const res = logOutput.match(regexp); |
22 | 65 |
|
23 | | - expect(res?.[problemMatcher.file]).toBe(file); |
24 | | - expect(res?.[problemMatcher.line]).toBe(line); |
25 | | - expect(res?.[problemMatcher.column]).toBe(column); |
26 | | - expect(res?.[problemMatcher.severity]).toBe(severity); |
27 | | - expect(res?.[problemMatcher.code]).toBe(code); |
28 | | - expect(res?.[problemMatcher.message]).toBe(message); |
29 | | - expect(res?.[problemMatcher.fromPath]).toBe(fromPath); |
| 66 | + for (const key in expected) { |
| 67 | + expect(res?.[problemMatcher[key]]).toBe(expected[key]); |
30 | 68 | } |
31 | | - ); |
| 69 | + }); |
32 | 70 | }); |
0 commit comments