From 3a2ca44a8ade5e640420385eb11c2e1e38cc6489 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 14 Feb 2020 01:26:09 +0530 Subject: [PATCH] Add problem matcher for PHP native errors --- __tests__/matchers.test.ts | 21 +++++++++++++++++++-- dist/index.js | 5 +++-- src/configs/php.json | 29 +++++++++++++++++++++++++++++ src/matchers.ts | 11 +++-------- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/configs/php.json diff --git a/__tests__/matchers.test.ts b/__tests__/matchers.test.ts index 1d55d6f0..25534c36 100644 --- a/__tests__/matchers.test.ts +++ b/__tests__/matchers.test.ts @@ -18,10 +18,10 @@ describe('Matchers', () => { process.env['RUNNER_TOOL_CACHE'] = __dirname; await matchers.addMatchers(); const spy = jest.spyOn(io, 'cp'); - expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(2); }); - it('Test Regex', async () => { + it('Test PHPUnit Regex', async () => { const regex1 = /^\d+\)\s.*$/; const regex2 = /^(.*Failed\sasserting\sthat.*)$/; const regex3 = /^\s*$/; @@ -31,4 +31,21 @@ describe('Matchers', () => { expect(regex3.test('\n')).toBe(true); expect(regex4.test('/path/to/file.php:42')).toBe(true); }); + + it('Test PHP Regex', async () => { + const regex1 = /^(.*error):\s+\s+(.+) in (.+) on line (\d+)$/; + const regex2 = /^(.*Warning|.*Deprecated|.*Notice):\s+\s+(.+) in (.+) on line (\d+)$/; + expect( + regex1.test('PHP Parse error: error_message in file.php on line 10') + ).toBe(true); + expect( + regex2.test('PHP Notice: info_message in file.php on line 10') + ).toBe(true); + expect( + regex2.test('PHP Warning: warning_message in file.php on line 10') + ).toBe(true); + expect( + regex2.test('PHP Deprecated: deprecated_message in file.php on line 10') + ).toBe(true); + }); }); diff --git a/dist/index.js b/dist/index.js index af279b3c..16ccc9d5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -964,9 +964,10 @@ const io = __importStar(__webpack_require__(1)); */ function addMatchers() { return __awaiter(this, void 0, void 0, function* () { - const config_path = path.join(__dirname, '..', 'src', 'configs', 'phpunit.json'); + const config_path = path.join(__dirname, '..', 'src', 'configs'); const runner_dir = yield utils.getInput('RUNNER_TOOL_CACHE', false); - yield io.cp(config_path, runner_dir); + yield io.cp(path.join(config_path, 'phpunit.json'), runner_dir); + yield io.cp(path.join(config_path, 'php.json'), runner_dir); }); } exports.addMatchers = addMatchers; diff --git a/src/configs/php.json b/src/configs/php.json new file mode 100644 index 00000000..1f0ee8b2 --- /dev/null +++ b/src/configs/php.json @@ -0,0 +1,29 @@ +{ + "problemMatcher": [ + { + "owner": "php_native_error", + "severity": "error", + "pattern": [ + { + "regexp": "^(.*error):\\s+\\s+(.+) in (.+) on line (\\d+)$", + "code": 1, + "message": 2, + "file": 3, + "line": 4 + } + ] + }, { + "owner": "php_native_warning", + "severity": "warning", + "pattern": [ + { + "regexp": "^(.*Warning|.*Deprecated|.*Notice):\\s+\\s+(.+) in (.+) on line (\\d+)$", + "code": 1, + "message": 2, + "file": 3, + "line": 4 + } + ] + } + ] +} diff --git a/src/matchers.ts b/src/matchers.ts index 500f2101..03b1bfd8 100644 --- a/src/matchers.ts +++ b/src/matchers.ts @@ -6,13 +6,8 @@ import * as io from '@actions/io'; * Cache json files for problem matchers */ export async function addMatchers(): Promise { - const config_path = path.join( - __dirname, - '..', - 'src', - 'configs', - 'phpunit.json' - ); + const config_path = path.join(__dirname, '..', 'src', 'configs'); const runner_dir: string = await utils.getInput('RUNNER_TOOL_CACHE', false); - await io.cp(config_path, runner_dir); + await io.cp(path.join(config_path, 'phpunit.json'), runner_dir); + await io.cp(path.join(config_path, 'php.json'), runner_dir); }