Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Problem Matcher for dotnet-format #583

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: move csc.json unit test into problem-matchers tests
nogic1008 committed Jan 14, 2025
commit 90a52e1c23eeb84fe7d387857edbcb14808071d5
45 changes: 0 additions & 45 deletions __tests__/csc.test.ts

This file was deleted.

78 changes: 58 additions & 20 deletions __tests__/problem-matchers.json.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,70 @@
import csc from '../.github/csc.json';
import dotnetFormat from '../.github/dotnet-format.json';

// Unit tests for problem matchers
// https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md

describe('/.github/csc.json tests', () => {
const problemMatcher = csc.problemMatcher[0].pattern[0];

it.each([
[
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
{
file: 'Program.cs',
line: '10',
severity: 'error',
code: 'CS1002',
message: '; expected',
fromPath:
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
}
],
[
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]",
{
file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs',
line: '33',
severity: 'error',
code: 'CS1003',
message: "Syntax error, ',' expected",
fromPath:
'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop'
}
]
])('log "%s" matches %o', (logOutput, expected) => {
const regexp = new RegExp(problemMatcher.regexp);
const res = logOutput.match(regexp);

for (const key in expected) {
expect(res?.[problemMatcher[key]]).toBe(expected[key]);
}
});
});

describe('/.github/dotnet-format.json tests', () => {
const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0];

it.each([
[
"/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]",
'/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'
{
file: '/home/runner/work/repo/Test.cs',
line: '18',
column: '6',
severity: 'error',
code: 'WHITESPACE',
message:
"Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.",
fromPath: '/home/runner/work/repo/Test.csproj'
}
]
])(
'"%s" returns {file: "%s", line: "%s", column: "%s", severity: "%s", code: "%s", message: "%s", fromPath: "%s"}',
(logOutput, file, line, column, severity, code, message, fromPath) => {
const regexp = new RegExp(problemMatcher.regexp);
const res = logOutput.match(regexp);
])('log "%s" matches %o', (logOutput, expected) => {
const regexp = new RegExp(problemMatcher.regexp);
const res = logOutput.match(regexp);

expect(res?.[problemMatcher.file]).toBe(file);
expect(res?.[problemMatcher.line]).toBe(line);
expect(res?.[problemMatcher.column]).toBe(column);
expect(res?.[problemMatcher.severity]).toBe(severity);
expect(res?.[problemMatcher.code]).toBe(code);
expect(res?.[problemMatcher.message]).toBe(message);
expect(res?.[problemMatcher.fromPath]).toBe(fromPath);
for (const key in expected) {
expect(res?.[problemMatcher[key]]).toBe(expected[key]);
}
);
});
});