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> {
|
2021-03-23 08:20:05 +07:00
|
|
|
let script = '\n';
|
|
|
|
script +=
|
|
|
|
(await extensions.addExtension(':pcov', version, os_version, true)) + pipe;
|
|
|
|
script +=
|
2020-06-20 07:55:19 +07:00
|
|
|
(await extensions.addExtension(extension, version, os_version, true)) +
|
|
|
|
pipe;
|
2021-03-23 08:20:05 +07:00
|
|
|
script += await utils.addLog(
|
2020-06-20 07:55:19 +07:00
|
|
|
'$tick',
|
|
|
|
extension,
|
|
|
|
'Xdebug enabled as coverage driver',
|
|
|
|
os_version
|
|
|
|
);
|
2021-03-23 08:20:05 +07:00
|
|
|
return script;
|
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:
|
2021-03-23 08:20:05 +07:00
|
|
|
script +=
|
|
|
|
(await extensions.addExtension(':xdebug', version, os_version, true)) +
|
|
|
|
pipe;
|
2019-10-17 03:11:13 +07:00
|
|
|
script +=
|
|
|
|
(await extensions.addExtension('pcov', version, os_version, true)) +
|
2021-03-23 08:20:05 +07:00
|
|
|
pipe;
|
2019-10-17 03:11:13 +07:00
|
|
|
script +=
|
|
|
|
(await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n';
|
2019-10-08 19:42:54 +07:00
|
|
|
|
|
|
|
// 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';
|
2021-03-23 08:20:05 +07:00
|
|
|
script +=
|
|
|
|
(await extensions.addExtension(':pcov', version, os_version, true)) + pipe;
|
|
|
|
script +=
|
|
|
|
(await extensions.addExtension(':xdebug', version, os_version, true)) +
|
|
|
|
pipe;
|
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));
|
2021-03-23 08:20:05 +07:00
|
|
|
const pipe: string = (await utils.suppressOutput(os_version)) + '\n';
|
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 (
|
2020-12-24 19:50:42 +07:00
|
|
|
script + (await addCoverageXdebug('xdebug', version, os_version, pipe))
|
|
|
|
);
|
|
|
|
case 'xdebug2':
|
|
|
|
return (
|
|
|
|
script + (await addCoverageXdebug('xdebug2', version, os_version, pipe))
|
2020-06-20 07:55:19 +07:00
|
|
|
);
|
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 '';
|
|
|
|
}
|
|
|
|
}
|