Skip to content

Commit 90a52e1

Browse files
committed
test: move csc.json unit test into problem-matchers tests
1 parent e8284b3 commit 90a52e1

File tree

2 files changed

+58
-65
lines changed

2 files changed

+58
-65
lines changed

__tests__/csc.test.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,70 @@
1+
import csc from '../.github/csc.json';
12
import dotnetFormat from '../.github/dotnet-format.json';
23

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+
345
describe('/.github/dotnet-format.json tests', () => {
446
const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0];
547

648
it.each([
749
[
850
"/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+
}
1661
]
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);
2265

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]);
3068
}
31-
);
69+
});
3270
});

0 commit comments

Comments
 (0)