From e0561697dca304c1449578b8ecdbd5144421a153 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 23 Jul 2020 06:47:57 +0530 Subject: [PATCH] Fail fast PCOV on unsupported PHP versions --- __tests__/extensions.test.ts | 20 +++++++++++++++++++- dist/index.js | 20 +++++++++++++++++++- src/extensions.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 369c3170..92f04c00 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -9,6 +9,12 @@ describe('Extension tests', () => { expect(await extensions.getXdebugVersion('7.0')).toContain('2.7.2'); expect(await extensions.getXdebugVersion('7.2')).toContain('2.9.6'); }); + it('checking getUnsupportedLog', async () => { + expect(await extensions.getUnsupportedLog('ext', '5.6', 'linux')).toContain( + 'add_log "$cross" "ext" "ext is not supported on PHP 5.6"' + ); + }); + it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( 'Xdebug, pcov, sqlite, :intl, phalcon4, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2', @@ -27,6 +33,11 @@ describe('Extension tests', () => { expect(win32).toContain('Add-Extension grpc stable 1.2.3'); expect(win32).toContain('Add-Extension inotify alpha 1.2.3'); + win32 = await extensions.addExtension('pcov', '5.6', 'win32'); + expect(win32).toContain( + 'Add-Log "$cross" "pcov" "pcov is not supported on PHP 5.6"' + ); + win32 = await extensions.addExtension('mysql', '7.4', 'win32'); expect(win32).toContain('Add-Extension mysqli'); expect(win32).toContain('Add-Extension mysqlnd'); @@ -88,6 +99,11 @@ describe('Extension tests', () => { 'sudo $debconf_fix apt-get install -y php8.0-xdebug' ); + linux = await extensions.addExtension('pcov', '5.6', 'linux'); + expect(linux).toContain( + 'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6"' + ); + linux = await extensions.addExtension('gearman', '7.0', 'linux'); expect(linux).toContain('gearman.sh 7.0'); linux = await extensions.addExtension('gearman', '7.1', 'linux'); @@ -153,7 +169,9 @@ describe('Extension tests', () => { expect(darwin).toContain('oci.sh pdo_oci 7.3'); darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); - expect(darwin).toContain('sudo pecl install -f pcov'); + expect(darwin).toContain( + 'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6"' + ); darwin = await extensions.addExtension('pcov', '7.2', 'darwin'); expect(darwin).toContain('add_brew_extension pcov'); diff --git a/dist/index.js b/dist/index.js index 65491e2e..0c70b88e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3568,7 +3568,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.addExtension = exports.addExtensionLinux = exports.addExtensionWindows = exports.addExtensionDarwin = exports.getXdebugVersion = void 0; +exports.addExtension = exports.addExtensionLinux = exports.addExtensionWindows = exports.addExtensionDarwin = exports.getUnsupportedLog = exports.getXdebugVersion = void 0; const path = __importStar(__webpack_require__(622)); const utils = __importStar(__webpack_require__(163)); /** @@ -3592,6 +3592,12 @@ async function getXdebugVersion(version) { } } exports.getXdebugVersion = getXdebugVersion; +async function getUnsupportedLog(extension, version, os_version) { + return ('\n' + + (await utils.addLog('$cross', extension, extension + ' is not supported on PHP ' + version, os_version)) + + '\n'); +} +exports.getUnsupportedLog = getUnsupportedLog; /** * Install and enable extensions for darwin * @@ -3650,6 +3656,10 @@ async function addExtensionDarwin(extension_csv, version, pipe) { command = command_prefix + 'xdebug-' + (await getXdebugVersion(version)); break; + // match 5.3pcov to 7.0pcov + case /(5\.[3-6]|7\.0)pcov/.test(version_extension): + add_script += await getUnsupportedLog('pcov', version, 'darwin'); + return; // match 5.6xdebug to 8.0xdebug, 5.6swoole to 8.0swoole // match 5.6grpc to 7.4grpc, 5.6protobuf to 7.4protobuf // match 7.1pcov to 8.0pcov @@ -3759,6 +3769,10 @@ async function addExtensionWindows(extension_csv, version) { add_script += '\nAdd-Extension ' + ext_name + ' ' + matches[2] + ' ' + matches[1]; return; + // match 5.3pcov to 7.0pcov + case /(5\.[3-6]|7\.0)pcov/.test(version_extension): + add_script += await getUnsupportedLog('pcov', version, 'win32'); + break; // match 5.3mysql..5.6mysql // match 5.3mysqli..5.6mysqli // match 5.3mysqlnd..5.6mysqlnd @@ -3869,6 +3883,10 @@ async function addExtensionLinux(extension_csv, version, pipe) { ' ' + ext_prefix; return; + // match 5.3pcov to 7.0pcov + case /(5\.[3-6]|7\.0)pcov/.test(version_extension): + add_script += await getUnsupportedLog('pcov', version, 'linux'); + return; // match 5.6gearman..7.4gearman case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): command = diff --git a/src/extensions.ts b/src/extensions.ts index 37ad4bcf..eb4a7507 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -22,6 +22,23 @@ export async function getXdebugVersion(version: string): Promise { } } +export async function getUnsupportedLog( + extension: string, + version: string, + os_version: string +): Promise { + return ( + '\n' + + (await utils.addLog( + '$cross', + extension, + extension + ' is not supported on PHP ' + version, + os_version + )) + + '\n' + ); +} + /** * Install and enable extensions for darwin * @@ -86,6 +103,10 @@ export async function addExtensionDarwin( command = command_prefix + 'xdebug-' + (await getXdebugVersion(version)); break; + // match 5.3pcov to 7.0pcov + case /(5\.[3-6]|7\.0)pcov/.test(version_extension): + add_script += await getUnsupportedLog('pcov', version, 'darwin'); + return; // match 5.6xdebug to 8.0xdebug, 5.6swoole to 8.0swoole // match 5.6grpc to 7.4grpc, 5.6protobuf to 7.4protobuf // match 7.1pcov to 8.0pcov @@ -204,6 +225,10 @@ export async function addExtensionWindows( add_script += '\nAdd-Extension ' + ext_name + ' ' + matches[2] + ' ' + matches[1]; return; + // match 5.3pcov to 7.0pcov + case /(5\.[3-6]|7\.0)pcov/.test(version_extension): + add_script += await getUnsupportedLog('pcov', version, 'win32'); + break; // match 5.3mysql..5.6mysql // match 5.3mysqli..5.6mysqli // match 5.3mysqlnd..5.6mysqlnd @@ -320,6 +345,10 @@ export async function addExtensionLinux( ' ' + ext_prefix; return; + // match 5.3pcov to 7.0pcov + case /(5\.[3-6]|7\.0)pcov/.test(version_extension): + add_script += await getUnsupportedLog('pcov', version, 'linux'); + return; // match 5.6gearman..7.4gearman case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): command =