Skip to content

Commit 050cb80

Browse files
committed
Add coverage driver version in logs
1 parent 3fda17f commit 050cb80

5 files changed

Lines changed: 64 additions & 6 deletions

File tree

__tests__/coverage.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ describe('Config tests', () => {
44
it.each`
55
driver | php | os | output
66
${'PCOV'} | ${'7.4'} | ${'win32'} | ${'Add-Extension pcov,Disable-Extension xdebug false'}
7+
${'pcov'} | ${'7.4'} | ${'win32'} | ${'$pcov_version = php -r "echo phpversion(\'pcov\');"'}
8+
${'pcov'} | ${'7.4'} | ${'win32'} | ${'PCOV $pcov_version enabled as coverage driver'}
79
${'pcov'} | ${'7.0'} | ${'win32'} | ${'PHP 7.1 or newer is required'}
810
${'pcov'} | ${'5.6'} | ${'win32'} | ${'PHP 7.1 or newer is required'}
911
${'pcov'} | ${'7.4'} | ${'win32'} | ${'Add-Extension pcov,Disable-Extension xdebug false'}
@@ -15,6 +17,8 @@ describe('Config tests', () => {
1517
${'xdebug'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
1618
${'xdebug3'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
1719
${'xdebug2'} | ${'7.4'} | ${'linux'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'}
20+
${'xdebug'} | ${'7.4'} | ${'linux'} | ${'xdebug_version="$(php -r "echo phpversion(\'xdebug\');")"'}
21+
${'xdebug'} | ${'7.4'} | ${'linux'} | ${'Xdebug $xdebug_version enabled as coverage driver'}
1822
${'xdebug'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'}
1923
${'xdebug3'} | ${'7.1'} | ${'darwin'} | ${'xdebug3 is not supported on PHP 7.1'}
2024
${'xdebug2'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug2'}

__tests__/utils.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,13 @@ describe('Utils tests', () => {
256256
'\nadd_extension_from_source ext https://sub.domain.XN--tld org repo release extension'
257257
);
258258
});
259+
260+
it('checking setVariable', async () => {
261+
let script: string = await utils.setVariable('var', 'command', 'linux');
262+
expect(script).toEqual('\nvar="$(command)"\n');
263+
script = await utils.setVariable('var', 'command', 'darwin');
264+
expect(script).toEqual('\nvar="$(command)"\n');
265+
script = await utils.setVariable('var', 'command', 'win32');
266+
expect(script).toEqual('\n$var = command\n');
267+
});
259268
});

dist/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ async function addCoverageXdebug(extension, version, os, pipe) {
135135
extension = extension == 'xdebug3' ? 'xdebug' : extension;
136136
script +=
137137
(await extensions.addExtension(extension, version, os, true)) + pipe;
138-
message = 'Xdebug enabled as coverage driver';
138+
script += await utils.setVariable('xdebug_version', 'php -r "echo phpversion(\'xdebug\');"', os);
139+
message = 'Xdebug $xdebug_version enabled as coverage driver';
139140
status = '$tick';
140141
}
141142
script += await utils.addLog(status, extension, message, os);
@@ -152,7 +153,8 @@ async function addCoveragePCOV(version, os, pipe) {
152153
script +=
153154
(await extensions.addExtension('pcov', version, os, true)) + pipe;
154155
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';
155-
script += await utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os);
156+
script += await utils.setVariable('pcov_version', 'php -r "echo phpversion(\'pcov\');"', os);
157+
script += await utils.addLog('$tick', 'coverage: pcov', 'PCOV $pcov_version enabled as coverage driver', os);
156158
break;
157159
case /5\.[3-6]|7\.0/.test(version):
158160
script += await utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os);
@@ -1013,7 +1015,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
10131015
return result;
10141016
};
10151017
Object.defineProperty(exports, "__esModule", ({ value: true }));
1016-
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;
1018+
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;
10171019
const path = __importStar(__nccwpck_require__(17));
10181020
const core = __importStar(__nccwpck_require__(186));
10191021
const fetch = __importStar(__nccwpck_require__(387));
@@ -1253,6 +1255,17 @@ async function parseExtensionSource(extension, prefix) {
12531255
return await joins('\nadd_extension_from_source', ...matches.splice(1, matches.length), prefix);
12541256
}
12551257
exports.parseExtensionSource = parseExtensionSource;
1258+
async function setVariable(variable, command, os) {
1259+
switch (os) {
1260+
case 'win32':
1261+
return '\n$' + variable + ' = ' + command + '\n';
1262+
case 'linux':
1263+
case 'darwin':
1264+
default:
1265+
return '\n' + variable + '="$(' + command + ')"\n';
1266+
}
1267+
}
1268+
exports.setVariable = setVariable;
12561269
//# sourceMappingURL=utils.js.map
12571270

12581271
/***/ }),

src/coverage.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ export async function addCoverageXdebug(
3838
extension = extension == 'xdebug3' ? 'xdebug' : extension;
3939
script +=
4040
(await extensions.addExtension(extension, version, os, true)) + pipe;
41-
message = 'Xdebug enabled as coverage driver';
41+
script += await utils.setVariable(
42+
'xdebug_version',
43+
'php -r "echo phpversion(\'xdebug\');"',
44+
os
45+
);
46+
message = 'Xdebug $xdebug_version enabled as coverage driver';
4247
status = '$tick';
4348
}
4449
script += await utils.addLog(status, extension, message, os);
@@ -66,12 +71,16 @@ export async function addCoveragePCOV(
6671
script +=
6772
(await extensions.addExtension('pcov', version, os, true)) + pipe;
6873
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';
69-
74+
script += await utils.setVariable(
75+
'pcov_version',
76+
'php -r "echo phpversion(\'pcov\');"',
77+
os
78+
);
7079
// success
7180
script += await utils.addLog(
7281
'$tick',
7382
'coverage: pcov',
74-
'PCOV enabled as coverage driver',
83+
'PCOV $pcov_version enabled as coverage driver',
7584
os
7685
);
7786
// version is not supported

src/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,26 @@ export async function parseExtensionSource(
413413
prefix
414414
);
415415
}
416+
417+
/**
418+
* Log to console
419+
*
420+
* @param variable
421+
* @param command
422+
* @param os
423+
*/
424+
export async function setVariable(
425+
variable: string,
426+
command: string,
427+
os: string
428+
): Promise<string> {
429+
switch (os) {
430+
case 'win32':
431+
return '\n$' + variable + ' = ' + command + '\n';
432+
433+
case 'linux':
434+
case 'darwin':
435+
default:
436+
return '\n' + variable + '="$(' + command + ')"\n';
437+
}
438+
}

0 commit comments

Comments
 (0)