From e5b90e33c67b2d34f453211a2dfc74abb3c4013c Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 24 Dec 2020 18:20:42 +0530 Subject: [PATCH] Add support for coverage: xdebug2 --- __tests__/coverage.test.ts | 49 +++++++++++++++++++++++------------- __tests__/extensions.test.ts | 13 +++++----- dist/index.js | 38 +++++++++------------------- src/coverage.ts | 7 ++++-- src/extensions.ts | 22 ++++++---------- src/scripts/darwin.sh | 7 +++--- src/utils.ts | 13 +++------- 7 files changed, 69 insertions(+), 80 deletions(-) diff --git a/__tests__/coverage.test.ts b/__tests__/coverage.test.ts index b159209a..9b8d6b84 100644 --- a/__tests__/coverage.test.ts +++ b/__tests__/coverage.test.ts @@ -30,34 +30,29 @@ describe('Config tests', () => { expect(win32).toContain('Add-Extension xdebug'); }); + it('checking addCoverage with Xdebug3 on windows', async () => { + const win32: string = await coverage.addCoverage('xdebug3', '7.4', 'win32'); + expect(win32).toContain('Add-Extension xdebug'); + }); + + it('checking addCoverage with Xdebug2 on windows', async () => { + const win32: string = await coverage.addCoverage('xdebug2', '7.4', 'win32'); + expect(win32).toContain('Add-Extension xdebug stable 2.9.8'); + }); + it('checking addCoverage with Xdebug on linux', async () => { const linux: string = await coverage.addCoverage('xdebug', '8.0', 'linux'); expect(linux).toContain('add_extension xdebug'); }); - it('checking addCoverage with Xdebug3 on linux', async () => { - const linux: string = await coverage.addCoverage('xdebug3', '7.4', 'linux'); - expect(linux).toContain('add_extension_from_source xdebug'); - }); - it('checking addCoverage with Xdebug3 on linux', async () => { const linux: string = await coverage.addCoverage('xdebug3', '8.0', 'linux'); expect(linux).toContain('add_extension xdebug'); }); - it('checking addCoverage with Xdebug on linux', async () => { - const linux: string = await coverage.addCoverage('xdebug', '8.0', 'linux'); - expect(linux).toContain('add_extension xdebug'); - }); - - it('checking addCoverage with Xdebug3 on linux', async () => { - const linux: string = await coverage.addCoverage('xdebug3', '8.1', 'linux'); - expect(linux).toContain('add_extension xdebug'); - }); - - it('checking addCoverage with Xdebug on linux', async () => { - const linux: string = await coverage.addCoverage('xdebug', '8.1', 'linux'); - expect(linux).toContain('add_extension xdebug'); + it('checking addCoverage with Xdebug2 on linux', async () => { + const linux: string = await coverage.addCoverage('xdebug2', '7.4', 'linux'); + expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension'); }); it('checking addCoverage with Xdebug on darwin', async () => { @@ -69,6 +64,24 @@ describe('Config tests', () => { expect(darwin).toContain('add_brew_extension xdebug'); }); + it('checking addCoverage with Xdebug3 on darwin', async () => { + const darwin: string = await coverage.addCoverage( + 'xdebug3', + '7.4', + 'darwin' + ); + expect(darwin).toContain('add_brew_extension xdebug'); + }); + + it('checking addCoverage with Xdebug2 on darwin', async () => { + const darwin: string = await coverage.addCoverage( + 'xdebug2', + '7.4', + 'darwin' + ); + expect(darwin).toContain('add_brew_extension xdebug2'); + }); + it('checking disableCoverage windows', async () => { const win32 = await coverage.addCoverage('none', '7.4', 'win32'); expect(win32).toContain('Remove-Extension xdebug'); diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 13aac874..bca5600f 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -25,7 +25,7 @@ describe('Extension tests', () => { 'Add-Log "$cross" "pcov" "pcov is not supported on PHP 5.6"' ); - win32 = await extensions.addExtension('xdebug', '7.2', 'win32'); + win32 = await extensions.addExtension('xdebug2', '7.2', 'win32'); expect(win32).toContain('Add-Extension xdebug stable 2.9.8'); win32 = await extensions.addExtension('mysql', '7.4', 'win32'); @@ -62,13 +62,11 @@ describe('Extension tests', () => { it('checking addExtensionOnLinux', async () => { let linux: string = await extensions.addExtension( - 'Xdebug, xdebug3, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3', + 'Xdebug, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3', '7.4', 'linux' ); - expect(linux).toContain( - 'add_extension_from_source xdebug xdebug/xdebug master --enable-xdebug zend_extension' - ); + expect(linux).toContain('add_extension xdebug'); expect(linux).toContain('add_extension sqlite3'); expect(linux).toContain('remove_extension intl'); expect(linux).toContain('add_unstable_extension ast beta extension'); @@ -99,7 +97,7 @@ describe('Extension tests', () => { linux = await extensions.addExtension('cubrid', '7.4', 'linux'); expect(linux).toContain('add_cubrid cubrid'); - linux = await extensions.addExtension('xdebug', '7.2', 'linux'); + linux = await extensions.addExtension('xdebug2', '7.2', 'linux'); expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension'); linux = await extensions.addExtension('xdebug', '7.2', 'openbsd'); @@ -194,6 +192,9 @@ describe('Extension tests', () => { darwin = await extensions.addExtension('xdebug', '7.2', 'darwin'); expect(darwin).toContain('add_brew_extension xdebug'); + darwin = await extensions.addExtension('xdebug2', '7.2', 'darwin'); + expect(darwin).toContain('add_brew_extension xdebug2'); + darwin = await extensions.addExtension('redis', '5.6', 'darwin'); expect(darwin).toContain('add_extension redis-2.2.8'); diff --git a/dist/index.js b/dist/index.js index f918bbb0..c3db6a48 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1275,18 +1275,11 @@ exports.CSVArray = CSVArray; * @param extension */ async function getExtensionPrefix(extension) { - const zend = [ - 'xdebug', - 'xdebug3', - 'opcache', - 'ioncube', - 'eaccelerator' - ]; - switch (zend.indexOf(extension)) { + switch (true) { default: - return 'zend_extension'; - case -1: return 'extension'; + case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension): + return 'zend_extension'; } } exports.getExtensionPrefix = getExtensionPrefix; @@ -2419,8 +2412,9 @@ async function addCoverage(coverage_driver, version, os_version) { return script + (await addCoveragePCOV(version, os_version, pipe)); case 'xdebug': case 'xdebug3': - return (script + - (await addCoverageXdebug(coverage_driver, version, os_version, pipe))); + return (script + (await addCoverageXdebug('xdebug', version, os_version, pipe))); + case 'xdebug2': + return (script + (await addCoverageXdebug('xdebug2', version, os_version, pipe))); case 'none': return script + (await disableCoverage(version, os_version, pipe)); default: @@ -2968,10 +2962,11 @@ async function addExtensionWindows(extension_csv, version) { matches = /.*-(\d+\.\d+\.\d)([a-zA-Z+]+)\d*/.exec(version_extension); add_script += await utils.joins('\nAdd-Extension', ext_name, matches[2].replace('preview', 'devel'), matches[1]); break; - // match 5.3pcov to 7.0pcov - case /7\.2xdebug/.test(version_extension): + // match 7.2xdebug2 to 7.4xdebug2 + case /7\.[2-4]xdebug2/.test(version_extension): add_script += '\nAdd-Extension xdebug stable 2.9.8'; break; + // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): add_script += await utils.getUnsupportedLog('pcov', version, 'win32'); break; @@ -3048,19 +3043,10 @@ async function addExtensionLinux(extension_csv, version) { case /(5\.[3-6]|7\.0)pcov/.test(version_extension): add_script += await utils.getUnsupportedLog('pcov', version, 'linux'); return; - // match 7.2xdebug3..7.4xdebug3 - case /^7\.[2-4]xdebug3$/.test(version_extension): - add_script += - '\nadd_extension_from_source xdebug xdebug/xdebug master --enable-xdebug zend_extension'; + // match 7.2xdebug2...7.4xdebug2 + case /^7\.[2-4]xdebug2$/.test(version_extension): + add_script += await utils.joins('\nadd_pecl_extension', 'xdebug', '2.9.8', ext_prefix); return; - // match 7.2xdebug - case /^7\.2xdebug$/.test(version_extension): - add_script += await utils.joins('\nadd_pecl_extension', ext_name, '2.9.8', ext_prefix); - break; - // match 8.0xdebug3...8.9xdebug3 - case /^8\.[0-9]xdebug3$/.test(version_extension): - extension = 'xdebug'; - break; // match pdo extensions case /.*pdo[_-].*/.test(version_extension): extension = extension.replace(/pdo[_-]|3/, ''); diff --git a/src/coverage.ts b/src/coverage.ts index 01216d91..bbc36f75 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -140,8 +140,11 @@ export async function addCoverage( case 'xdebug': case 'xdebug3': return ( - script + - (await addCoverageXdebug(coverage_driver, version, os_version, pipe)) + script + (await addCoverageXdebug('xdebug', version, os_version, pipe)) + ); + case 'xdebug2': + return ( + script + (await addCoverageXdebug('xdebug2', version, os_version, pipe)) ); case 'none': return script + (await disableCoverage(version, os_version, pipe)); diff --git a/src/extensions.ts b/src/extensions.ts index a4ca8494..904c30a0 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -163,10 +163,11 @@ export async function addExtensionWindows( matches[1] ); break; - // match 5.3pcov to 7.0pcov - case /7\.2xdebug/.test(version_extension): + // match 7.2xdebug2 to 7.4xdebug2 + case /7\.[2-4]xdebug2/.test(version_extension): add_script += '\nAdd-Extension xdebug stable 2.9.8'; break; + // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): add_script += await utils.getUnsupportedLog('pcov', version, 'win32'); break; @@ -267,24 +268,15 @@ export async function addExtensionLinux( case /(5\.[3-6]|7\.0)pcov/.test(version_extension): add_script += await utils.getUnsupportedLog('pcov', version, 'linux'); return; - // match 7.2xdebug3..7.4xdebug3 - case /^7\.[2-4]xdebug3$/.test(version_extension): - add_script += - '\nadd_extension_from_source xdebug xdebug/xdebug master --enable-xdebug zend_extension'; - return; - // match 7.2xdebug - case /^7\.2xdebug$/.test(version_extension): + // match 7.2xdebug2...7.4xdebug2 + case /^7\.[2-4]xdebug2$/.test(version_extension): add_script += await utils.joins( '\nadd_pecl_extension', - ext_name, + 'xdebug', '2.9.8', ext_prefix ); - break; - // match 8.0xdebug3...8.9xdebug3 - case /^8\.[0-9]xdebug3$/.test(version_extension): - extension = 'xdebug'; - break; + return; // match pdo extensions case /.*pdo[_-].*/.test(version_extension): extension = extension.replace(/pdo[_-]|3/, ''); diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index ff7fa637..3b9c82fe 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -68,8 +68,9 @@ add_brew_tap() { # Function to install a php extension from shivammathur/extensions tap. add_brew_extension() { - extension=$1 + formula=$1 prefix=$2 + extension=${formula//[0-9]/} enable_extension "$extension" "$prefix" if check_extension "$extension"; then add_log "${tick:?}" "$extension" "Enabled" @@ -77,8 +78,8 @@ add_brew_extension() { add_brew_tap shivammathur/homebrew-php add_brew_tap shivammathur/homebrew-extensions sudo mv "$tap_dir"/shivammathur/homebrew-extensions/.github/deps/"$extension"/* "$tap_dir/homebrew/homebrew-core/Formula/" 2>/dev/null || true - brew install "$extension@$version" >/dev/null 2>&1 - sudo cp "$brew_prefix/opt/$extension@$version/$extension.so" "$ext_dir" + brew install "$formula@$version" >/dev/null 2>&1 + sudo cp "$brew_prefix/opt/$formula@$version/$extension.so" "$ext_dir" add_extension_log "$extension" "Installed and enabled" fi } diff --git a/src/utils.ts b/src/utils.ts index 4ec89620..71192881 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -262,18 +262,11 @@ export async function CSVArray(values_csv: string): Promise> { * @param extension */ export async function getExtensionPrefix(extension: string): Promise { - const zend: Array = [ - 'xdebug', - 'xdebug3', - 'opcache', - 'ioncube', - 'eaccelerator' - ]; - switch (zend.indexOf(extension)) { + switch (true) { default: - return 'zend_extension'; - case -1: return 'extension'; + case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension): + return 'zend_extension'; } }