Skip to content

Commit

Permalink
Add coverage driver version in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Jun 30, 2022
1 parent 3fda17f commit 050cb80
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
4 changes: 4 additions & 0 deletions __tests__/coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ describe('Config tests', () => {
it.each`
driver | php | os | output
${'PCOV'} | ${'7.4'} | ${'win32'} | ${'Add-Extension pcov,Disable-Extension xdebug false'}
${'pcov'} | ${'7.4'} | ${'win32'} | ${'$pcov_version = php -r "echo phpversion(\'pcov\');"'}
${'pcov'} | ${'7.4'} | ${'win32'} | ${'PCOV $pcov_version enabled as coverage driver'}
${'pcov'} | ${'7.0'} | ${'win32'} | ${'PHP 7.1 or newer is required'}
${'pcov'} | ${'5.6'} | ${'win32'} | ${'PHP 7.1 or newer is required'}
${'pcov'} | ${'7.4'} | ${'win32'} | ${'Add-Extension pcov,Disable-Extension xdebug false'}
Expand All @@ -15,6 +17,8 @@ describe('Config tests', () => {
${'xdebug'} | ${'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'}
${'xdebug'} | ${'7.4'} | ${'linux'} | ${'xdebug_version="$(php -r "echo phpversion(\'xdebug\');")"'}
${'xdebug'} | ${'7.4'} | ${'linux'} | ${'Xdebug $xdebug_version enabled as coverage driver'}
${'xdebug'} | ${'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'}
Expand Down
9 changes: 9 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,13 @@ describe('Utils tests', () => {
'\nadd_extension_from_source ext https://sub.domain.XN--tld org repo release extension'
);
});

it('checking setVariable', async () => {
let script: string = await utils.setVariable('var', 'command', 'linux');
expect(script).toEqual('\nvar="$(command)"\n');
script = await utils.setVariable('var', 'command', 'darwin');
expect(script).toEqual('\nvar="$(command)"\n');
script = await utils.setVariable('var', 'command', 'win32');
expect(script).toEqual('\n$var = command\n');
});
});
19 changes: 16 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ async function addCoverageXdebug(extension, version, os, pipe) {
extension = extension == 'xdebug3' ? 'xdebug' : extension;
script +=
(await extensions.addExtension(extension, version, os, true)) + pipe;
message = 'Xdebug enabled as coverage driver';
script += await utils.setVariable('xdebug_version', 'php -r "echo phpversion(\'xdebug\');"', os);
message = 'Xdebug $xdebug_version enabled as coverage driver';
status = '$tick';
}
script += await utils.addLog(status, extension, message, os);
Expand All @@ -152,7 +153,8 @@ async function addCoveragePCOV(version, os, pipe) {
script +=
(await extensions.addExtension('pcov', version, os, true)) + pipe;
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';
script += await utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os);
script += await utils.setVariable('pcov_version', 'php -r "echo phpversion(\'pcov\');"', os);
script += await utils.addLog('$tick', 'coverage: pcov', 'PCOV $pcov_version enabled as coverage driver', os);
break;
case /5\.[3-6]|7\.0/.test(version):
script += await utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os);
Expand Down Expand Up @@ -1013,7 +1015,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseExtensionSource = exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseIniFile = exports.parseVersion = exports.getManifestURL = exports.getInput = exports.readEnv = void 0;
exports.setVariable = exports.parseExtensionSource = exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseIniFile = exports.parseVersion = exports.getManifestURL = exports.getInput = exports.readEnv = void 0;
const path = __importStar(__nccwpck_require__(17));
const core = __importStar(__nccwpck_require__(186));
const fetch = __importStar(__nccwpck_require__(387));
Expand Down Expand Up @@ -1253,6 +1255,17 @@ async function parseExtensionSource(extension, prefix) {
return await joins('\nadd_extension_from_source', ...matches.splice(1, matches.length), prefix);
}
exports.parseExtensionSource = parseExtensionSource;
async function setVariable(variable, command, os) {
switch (os) {
case 'win32':
return '\n$' + variable + ' = ' + command + '\n';
case 'linux':
case 'darwin':
default:
return '\n' + variable + '="$(' + command + ')"\n';
}
}
exports.setVariable = setVariable;
//# sourceMappingURL=utils.js.map

/***/ }),
Expand Down
15 changes: 12 additions & 3 deletions src/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export async function addCoverageXdebug(
extension = extension == 'xdebug3' ? 'xdebug' : extension;
script +=
(await extensions.addExtension(extension, version, os, true)) + pipe;
message = 'Xdebug enabled as coverage driver';
script += await utils.setVariable(
'xdebug_version',
'php -r "echo phpversion(\'xdebug\');"',
os
);
message = 'Xdebug $xdebug_version enabled as coverage driver';
status = '$tick';
}
script += await utils.addLog(status, extension, message, os);
Expand Down Expand Up @@ -66,12 +71,16 @@ export async function addCoveragePCOV(
script +=
(await extensions.addExtension('pcov', version, os, true)) + pipe;
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';

script += await utils.setVariable(
'pcov_version',
'php -r "echo phpversion(\'pcov\');"',
os
);
// success
script += await utils.addLog(
'$tick',
'coverage: pcov',
'PCOV enabled as coverage driver',
'PCOV $pcov_version enabled as coverage driver',
os
);
// version is not supported
Expand Down
23 changes: 23 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,26 @@ export async function parseExtensionSource(
prefix
);
}

/**
* Log to console
*
* @param variable
* @param command
* @param os
*/
export async function setVariable(
variable: string,
command: string,
os: string
): Promise<string> {
switch (os) {
case 'win32':
return '\n$' + variable + ' = ' + command + '\n';

case 'linux':
case 'darwin':
default:
return '\n' + variable + '="$(' + command + ')"\n';
}
}

0 comments on commit 050cb80

Please sign in to comment.