mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-01-18 22:31:44 +07:00
test: move csc.json unit test into problem-matchers tests
This commit is contained in:
parent
e8284b346f
commit
90a52e1c23
@ -1,45 +0,0 @@
|
|||||||
import cscFile from '../.github/csc.json';
|
|
||||||
describe('csc tests', () => {
|
|
||||||
test('regular expression in csc.json is valid', async () => {
|
|
||||||
const regexPattern = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
|
|
||||||
const regexResultsMap = cscFile['problemMatcher'][0]['pattern'][0];
|
|
||||||
|
|
||||||
const regex = new RegExp(regexPattern);
|
|
||||||
|
|
||||||
const stringsToMatch = [
|
|
||||||
'Program.cs(10,79): error CS1002: ; expected [/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]"
|
|
||||||
];
|
|
||||||
// Expected results are calculated according to the csc matcher located in csc.json file
|
|
||||||
const expectedResults = [
|
|
||||||
{
|
|
||||||
file: 'Program.cs',
|
|
||||||
line: '10',
|
|
||||||
severity: 'error',
|
|
||||||
code: 'CS1002',
|
|
||||||
message: '; expected',
|
|
||||||
fromPath:
|
|
||||||
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
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'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
stringsToMatch.map((string, index) => {
|
|
||||||
const matchedResultsArray = string.match(regex);
|
|
||||||
for (const propName in expectedResults[index]) {
|
|
||||||
const propertyIndex = regexResultsMap[propName];
|
|
||||||
const expectedPropValue = expectedResults[index][propName];
|
|
||||||
const matchedPropValue = matchedResultsArray![propertyIndex];
|
|
||||||
expect(matchedPropValue).toEqual(expectedPropValue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 10000);
|
|
||||||
});
|
|
@ -1,32 +1,70 @@
|
|||||||
|
import csc from '../.github/csc.json';
|
||||||
import dotnetFormat from '../.github/dotnet-format.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', () => {
|
describe('/.github/dotnet-format.json tests', () => {
|
||||||
const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0];
|
const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0];
|
||||||
|
|
||||||
it.each([
|
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]",
|
||||||
'/home/runner/work/repo/Test.cs',
|
{
|
||||||
'18',
|
file: '/home/runner/work/repo/Test.cs',
|
||||||
'6',
|
line: '18',
|
||||||
'error',
|
column: '6',
|
||||||
'WHITESPACE',
|
severity: 'error',
|
||||||
"Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.",
|
code: 'WHITESPACE',
|
||||||
'/home/runner/work/repo/Test.csproj'
|
message:
|
||||||
|
"Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.",
|
||||||
|
fromPath: '/home/runner/work/repo/Test.csproj'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
])(
|
])('log "%s" matches %o', (logOutput, expected) => {
|
||||||
'"%s" returns {file: "%s", line: "%s", column: "%s", severity: "%s", code: "%s", message: "%s", fromPath: "%s"}',
|
const regexp = new RegExp(problemMatcher.regexp);
|
||||||
(logOutput, file, line, column, severity, code, message, fromPath) => {
|
const res = logOutput.match(regexp);
|
||||||
const regexp = new RegExp(problemMatcher.regexp);
|
|
||||||
const res = logOutput.match(regexp);
|
|
||||||
|
|
||||||
expect(res?.[problemMatcher.file]).toBe(file);
|
for (const key in expected) {
|
||||||
expect(res?.[problemMatcher.line]).toBe(line);
|
expect(res?.[problemMatcher[key]]).toBe(expected[key]);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user