Log error when wrong Xdebug version is requested

This commit is contained in:
Shivam Mathur 2021-11-26 00:07:28 +05:30
parent 92b4784fb6
commit b33066473d
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 62 additions and 30 deletions

View File

@ -10,14 +10,15 @@ describe('Config tests', () => {
${'pcov'} | ${'7.4'} | ${'linux'} | ${'add_extension pcov,disable_extension xdebug false'} ${'pcov'} | ${'7.4'} | ${'linux'} | ${'add_extension pcov,disable_extension xdebug false'}
${'pcov'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension pcov,disable_extension xdebug false'} ${'pcov'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension pcov,disable_extension xdebug false'}
${'xdebug'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug'} ${'xdebug'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug'}
${'xdebug3'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug'} ${'xdebug3'} | ${'7.1'} | ${'win32'} | ${'xdebug3 is not supported on PHP 7.1'}
${'xdebug2'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug stable 2.9.8'} ${'xdebug2'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug stable 2.9.8'}
${'xdebug'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'} ${'xdebug'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
${'xdebug3'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'} ${'xdebug3'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
${'xdebug2'} | ${'7.4'} | ${'linux'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'} ${'xdebug2'} | ${'7.4'} | ${'linux'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'}
${'xdebug'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'} ${'xdebug'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'}
${'xdebug3'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'} ${'xdebug3'} | ${'7.1'} | ${'darwin'} | ${'xdebug3 is not supported on PHP 7.1'}
${'xdebug2'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug2'} ${'xdebug2'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug2'}
${'xdebug2'} | ${'8.0'} | ${'darwin'} | ${'xdebug2 is not supported on PHP 8.0'}
${'none'} | ${'7.4'} | ${'win32'} | ${'Disable-Extension xdebug false,Disable-Extension pcov false'} ${'none'} | ${'7.4'} | ${'win32'} | ${'Disable-Extension xdebug false,Disable-Extension pcov false'}
${'none'} | ${'7.4'} | ${'linux'} | ${'disable_extension xdebug false,disable_extension pcov false'} ${'none'} | ${'7.4'} | ${'linux'} | ${'disable_extension xdebug false,disable_extension pcov false'}
${'none'} | ${'7.4'} | ${'darwin'} | ${'disable_extension xdebug false,disable_extension pcov false'} ${'none'} | ${'7.4'} | ${'darwin'} | ${'disable_extension xdebug false,disable_extension pcov false'}

36
dist/index.js vendored
View File

@ -104,19 +104,33 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addCoverage = exports.disableCoverage = exports.addCoveragePCOV = exports.addCoverageXdebug = void 0; exports.addCoverage = exports.disableCoverage = exports.addCoveragePCOV = exports.addCoverageXdebug = exports.checkXdebugError = void 0;
const utils = __importStar(__nccwpck_require__(918)); const utils = __importStar(__nccwpck_require__(918));
const extensions = __importStar(__nccwpck_require__(390)); const extensions = __importStar(__nccwpck_require__(390));
const config = __importStar(__nccwpck_require__(88)); const config = __importStar(__nccwpck_require__(88));
async function checkXdebugError(extension, version) {
if ((/^5\.[3-6]$|^7\.[0-1]$/.test(version) && extension == 'xdebug3') ||
(/^8\.[0-9]$/.test(version) && extension == 'xdebug2')) {
return extension + ' is not supported on PHP ' + version;
}
return '';
}
exports.checkXdebugError = checkXdebugError;
async function addCoverageXdebug(extension, version, os_version, pipe) { async function addCoverageXdebug(extension, version, os_version, pipe) {
let script = '\n'; let script = '\n';
script += let message = await checkXdebugError(extension, version);
(await extensions.addExtension(':pcov:false', version, os_version, true)) + let status = '$cross';
pipe; if (!message) {
script += script +=
(await extensions.addExtension(extension, version, os_version, true)) + (await extensions.addExtension(':pcov:false', version, os_version, true)) + pipe;
pipe; extension = extension == 'xdebug3' ? 'xdebug' : extension;
script += await utils.addLog('$tick', extension, 'Xdebug enabled as coverage driver', os_version); script +=
(await extensions.addExtension(extension, version, os_version, true)) +
pipe;
message = 'Xdebug enabled as coverage driver';
status = '$tick';
}
script += await utils.addLog(status, extension, message, os_version);
return script; return script;
} }
exports.addCoverageXdebug = addCoverageXdebug; exports.addCoverageXdebug = addCoverageXdebug;
@ -159,10 +173,10 @@ async function addCoverage(coverage_driver, version, os_version) {
case 'pcov': case 'pcov':
return script + (await addCoveragePCOV(version, os_version, pipe)); return script + (await addCoveragePCOV(version, os_version, pipe));
case 'xdebug': case 'xdebug':
case 'xdebug3':
return (script + (await addCoverageXdebug('xdebug', version, os_version, pipe)));
case 'xdebug2': case 'xdebug2':
return (script + (await addCoverageXdebug('xdebug2', version, os_version, pipe))); case 'xdebug3':
return (script +
(await addCoverageXdebug(coverage_driver, version, os_version, pipe)));
case 'none': case 'none':
return script + (await disableCoverage(version, os_version, pipe)); return script + (await disableCoverage(version, os_version, pipe));
default: default:

View File

@ -2,6 +2,19 @@ import * as utils from './utils';
import * as extensions from './extensions'; import * as extensions from './extensions';
import * as config from './config'; import * as config from './config';
export async function checkXdebugError(
extension: string,
version: string
): Promise<string> {
if (
(/^5\.[3-6]$|^7\.[0-1]$/.test(version) && extension == 'xdebug3') ||
(/^8\.[0-9]$/.test(version) && extension == 'xdebug2')
) {
return extension + ' is not supported on PHP ' + version;
}
return '';
}
/** /**
* Function to setup Xdebug * Function to setup Xdebug
* *
@ -17,18 +30,24 @@ export async function addCoverageXdebug(
pipe: string pipe: string
): Promise<string> { ): Promise<string> {
let script = '\n'; let script = '\n';
script += let message: string = await checkXdebugError(extension, version);
(await extensions.addExtension(':pcov:false', version, os_version, true)) + let status = '$cross';
pipe; if (!message) {
script += script +=
(await extensions.addExtension(extension, version, os_version, true)) + (await extensions.addExtension(
pipe; ':pcov:false',
script += await utils.addLog( version,
'$tick', os_version,
extension, true
'Xdebug enabled as coverage driver', )) + pipe;
os_version extension = extension == 'xdebug3' ? 'xdebug' : extension;
); script +=
(await extensions.addExtension(extension, version, os_version, true)) +
pipe;
message = 'Xdebug enabled as coverage driver';
status = '$tick';
}
script += await utils.addLog(status, extension, message, os_version);
return script; return script;
} }
@ -136,13 +155,11 @@ export async function addCoverage(
case 'pcov': case 'pcov':
return script + (await addCoveragePCOV(version, os_version, pipe)); return script + (await addCoveragePCOV(version, os_version, pipe));
case 'xdebug': case 'xdebug':
case 'xdebug2':
case 'xdebug3': case 'xdebug3':
return ( return (
script + (await addCoverageXdebug('xdebug', version, os_version, pipe)) script +
); (await addCoverageXdebug(coverage_driver, version, os_version, pipe))
case 'xdebug2':
return (
script + (await addCoverageXdebug('xdebug2', version, os_version, pipe))
); );
case 'none': case 'none':
return script + (await disableCoverage(version, os_version, pipe)); return script + (await disableCoverage(version, os_version, pipe));