2019-10-08 19:42:54 +07:00
|
|
|
import * as utils from './utils';
|
|
|
|
import * as extensions from './extensions';
|
|
|
|
import * as config from './config';
|
|
|
|
|
2019-10-12 00:39:05 +07:00
|
|
|
/**
|
2019-11-24 03:34:12 +07:00
|
|
|
* Function to setup Xdebug
|
2019-10-12 00:39:05 +07:00
|
|
|
*
|
2020-06-20 07:55:19 +07:00
|
|
|
* @param extension
|
2019-10-12 00:39:05 +07:00
|
|
|
* @param version
|
|
|
|
* @param os_version
|
2019-12-26 20:01:18 +07:00
|
|
|
* @param pipe
|
2019-10-12 00:39:05 +07:00
|
|
|
*/
|
2019-11-24 03:34:12 +07:00
|
|
|
export async function addCoverageXdebug(
|
2020-06-20 07:55:19 +07:00
|
|
|
extension: string,
|
2019-10-08 19:42:54 +07:00
|
|
|
version: string,
|
2019-12-26 20:01:18 +07:00
|
|
|
os_version: string,
|
|
|
|
pipe: string
|
2019-10-08 19:42:54 +07:00
|
|
|
): Promise<string> {
|
2020-06-20 07:55:19 +07:00
|
|
|
const xdebug =
|
|
|
|
(await extensions.addExtension(extension, version, os_version, true)) +
|
|
|
|
pipe;
|
2020-07-08 09:31:26 +07:00
|
|
|
const ini = await config.addINIValues(
|
|
|
|
'xdebug.mode=coverage',
|
|
|
|
os_version,
|
|
|
|
true
|
|
|
|
);
|
2020-06-20 07:55:19 +07:00
|
|
|
const log = await utils.addLog(
|
|
|
|
'$tick',
|
|
|
|
extension,
|
|
|
|
'Xdebug enabled as coverage driver',
|
|
|
|
os_version
|
|
|
|
);
|
|
|
|
switch (true) {
|
|
|
|
case /^xdebug3$/.test(extension):
|
2020-10-17 01:39:15 +07:00
|
|
|
case /^8\.\d$/.test(version):
|
2020-06-20 07:55:19 +07:00
|
|
|
return '\n' + xdebug + '\n' + ini + '\n' + log;
|
|
|
|
case /^xdebug$/.test(extension):
|
2019-12-09 16:24:14 +07:00
|
|
|
default:
|
2020-06-19 16:17:34 +07:00
|
|
|
return xdebug + '\n' + log;
|
2019-12-09 16:24:14 +07:00
|
|
|
}
|
2019-10-08 19:42:54 +07:00
|
|
|
}
|
|
|
|
|
2019-10-12 00:39:05 +07:00
|
|
|
/**
|
|
|
|
* Function to setup PCOV
|
|
|
|
*
|
|
|
|
* @param version
|
|
|
|
* @param os_version
|
2019-12-26 20:01:18 +07:00
|
|
|
* @param pipe
|
2019-10-12 00:39:05 +07:00
|
|
|
*/
|
2019-11-24 03:34:12 +07:00
|
|
|
export async function addCoveragePCOV(
|
|
|
|
version: string,
|
2019-12-26 20:01:18 +07:00
|
|
|
os_version: string,
|
|
|
|
pipe: string
|
2019-11-24 03:34:12 +07:00
|
|
|
): Promise<string> {
|
|
|
|
let script = '\n';
|
2020-02-09 05:38:48 +07:00
|
|
|
switch (true) {
|
2019-10-08 19:42:54 +07:00
|
|
|
default:
|
2019-10-17 03:11:13 +07:00
|
|
|
script +=
|
|
|
|
(await extensions.addExtension('pcov', version, os_version, true)) +
|
2019-12-26 20:01:18 +07:00
|
|
|
pipe +
|
2019-10-17 03:11:13 +07:00
|
|
|
'\n';
|
|
|
|
script +=
|
|
|
|
(await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n';
|
2019-10-08 19:42:54 +07:00
|
|
|
|
|
|
|
// add command to disable xdebug and enable pcov
|
|
|
|
switch (os_version) {
|
|
|
|
case 'linux':
|
|
|
|
case 'darwin':
|
2019-12-26 20:01:18 +07:00
|
|
|
script += 'remove_extension xdebug' + pipe + '\n';
|
2019-10-08 19:42:54 +07:00
|
|
|
break;
|
|
|
|
case 'win32':
|
2019-12-26 20:01:18 +07:00
|
|
|
script += 'Remove-Extension xdebug' + pipe + '\n';
|
2019-10-08 19:42:54 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// success
|
2019-10-17 03:11:13 +07:00
|
|
|
script += await utils.addLog(
|
|
|
|
'$tick',
|
|
|
|
'coverage: pcov',
|
2019-10-08 19:42:54 +07:00
|
|
|
'PCOV enabled as coverage driver',
|
2019-10-17 03:11:13 +07:00
|
|
|
os_version
|
2019-10-08 19:42:54 +07:00
|
|
|
);
|
|
|
|
// version is not supported
|
|
|
|
break;
|
2020-02-09 05:38:48 +07:00
|
|
|
|
|
|
|
case /5\.[3-6]|7\.0/.test(version):
|
2019-10-17 03:11:13 +07:00
|
|
|
script += await utils.addLog(
|
|
|
|
'$cross',
|
|
|
|
'pcov',
|
|
|
|
'PHP 7.1 or newer is required',
|
|
|
|
os_version
|
2019-10-08 19:42:54 +07:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|
|
|
|
|
2019-10-12 00:39:05 +07:00
|
|
|
/**
|
|
|
|
* Function to disable Xdebug and PCOV
|
|
|
|
*
|
|
|
|
* @param version
|
|
|
|
* @param os_version
|
2019-12-26 20:01:18 +07:00
|
|
|
* @param pipe
|
2019-10-12 00:39:05 +07:00
|
|
|
*/
|
2019-11-24 03:34:12 +07:00
|
|
|
export async function disableCoverage(
|
|
|
|
version: string,
|
2019-12-26 20:01:18 +07:00
|
|
|
os_version: string,
|
|
|
|
pipe: string
|
2019-11-24 03:34:12 +07:00
|
|
|
): Promise<string> {
|
|
|
|
let script = '\n';
|
2019-10-08 19:42:54 +07:00
|
|
|
switch (os_version) {
|
|
|
|
case 'linux':
|
|
|
|
case 'darwin':
|
2019-12-26 20:01:18 +07:00
|
|
|
script += 'remove_extension xdebug' + pipe + '\n';
|
|
|
|
script += 'remove_extension pcov' + pipe + '\n';
|
2019-10-08 19:42:54 +07:00
|
|
|
break;
|
|
|
|
case 'win32':
|
2019-12-26 20:01:18 +07:00
|
|
|
script += 'Remove-Extension xdebug' + pipe + '\n';
|
|
|
|
script += 'Remove-Extension pcov' + pipe + '\n';
|
2019-10-08 19:42:54 +07:00
|
|
|
break;
|
|
|
|
}
|
2019-10-17 03:11:13 +07:00
|
|
|
script += await utils.addLog(
|
|
|
|
'$tick',
|
|
|
|
'none',
|
2019-10-08 19:42:54 +07:00
|
|
|
'Disabled Xdebug and PCOV',
|
2019-10-17 03:11:13 +07:00
|
|
|
os_version
|
2019-10-08 19:42:54 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|
2019-11-24 03:34:12 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to set coverage driver
|
|
|
|
*
|
|
|
|
* @param coverage_driver
|
|
|
|
* @param version
|
|
|
|
* @param os_version
|
|
|
|
*/
|
|
|
|
export async function addCoverage(
|
|
|
|
coverage_driver: string,
|
|
|
|
version: string,
|
|
|
|
os_version: string
|
|
|
|
): Promise<string> {
|
2020-01-26 17:45:39 +07:00
|
|
|
coverage_driver = coverage_driver.toLowerCase();
|
2019-11-24 03:34:12 +07:00
|
|
|
const script: string =
|
|
|
|
'\n' + (await utils.stepLog('Setup Coverage', os_version));
|
2019-12-26 20:01:18 +07:00
|
|
|
const pipe: string = await utils.suppressOutput(os_version);
|
2019-11-24 03:34:12 +07:00
|
|
|
switch (coverage_driver) {
|
|
|
|
case 'pcov':
|
2019-12-26 20:01:18 +07:00
|
|
|
return script + (await addCoveragePCOV(version, os_version, pipe));
|
2019-11-24 03:34:12 +07:00
|
|
|
case 'xdebug':
|
2020-06-20 07:55:19 +07:00
|
|
|
case 'xdebug3':
|
|
|
|
return (
|
|
|
|
script +
|
|
|
|
(await addCoverageXdebug(coverage_driver, version, os_version, pipe))
|
|
|
|
);
|
2019-11-24 03:34:12 +07:00
|
|
|
case 'none':
|
2019-12-26 20:01:18 +07:00
|
|
|
return script + (await disableCoverage(version, os_version, pipe));
|
2019-11-24 03:34:12 +07:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|