Reputation: 8855
Is there a code coverage tool for Hack language (on hhvm)?
This question is not about code coverage on PHP source code running on hhvm (which is possible using PHPUnit for example), but to generate code coverage of source code written in hack language.
Upvotes: 3
Views: 890
Reputation: 1220
The current version of PHPUnit(4.4,4.5,4.6) doesn't generate coverage and it fails with this error.
$php phpunit-alpha.phar -coverage-html=cover t/
PHPUnit alpha-2015-01-09 by Sebastian Bergmann and contributors.
PHPUnit alpha-2015-01-09 by Sebastian Bergmann and contributors.
Fatal error: Class undefined: PHP_Token_TYPELIST_LT in phar://phpunit-alpha-2015-01-09.phar/php-token-stream/Token/Stream.php on line 185
I do agree that with Ira that code coverage is using XDEBUG. However for some reason PHPUnit has not decided to have HackLang code coverage.
First Update:
It is because Hacklang has more registered commands(like shape, type) and more structures(lambda), which php-token-stream is not able to recognize them.
The fix is quite simple though, you can create the class that is not defined and extend it from PHP_Token. For instance for my project I had to create these classes:
class PHP_Token_TYPELIST_LT extends PHP_Token {}
class PHP_Token_TYPELIST_GT extends PHP_Token {}
class PHP_Token_TYPE extends PHP_Token {}
class PHP_Token_SHAPE extends PHP_Token {}
class PHP_Token_LAMBDA_OP extends PHP_Token {}
class PHP_Token_LAMBDA_CP extends PHP_Token {}
class PHP_Token_LAMBDA_ARROW extends PHP_Token {}
Second Update:
PHPUnit is using CodeCoverage to detect the executed line and in that project, on HHVM it's using fb_get_code_coverage
Upvotes: 4
Reputation: 95306
While it may be useful for OP to write testing code in PHPUnit, most of the PHP test coverage tools (including PHPUnit as I understand it) use XDEBUG to collect their test coverage data. I'm not familiar with the Hack implementation but I understand it has nothing to do with Zend... so the likelyhood it contains XDEBUG seems kind of remote. (Maybe Hack copied XDEBUG exactly?) If XDEBUG is not available under Hack, those XDEBUG-based coverage tools literally cannot collect the data they need.
To the extent that Hack is a identical to PHP, our PHP Test Coverage Tool will probably work directly. It instruments source code, and so is not dependent in any way on the existence of XDEBUG. I suspect PHPUnit could easily be adapted.
(If Hack is not exactly the same, the test coverage tool could be revised to handle the changed syntax pretty easily, since it is based on a general purpose program transformation system).
Upvotes: 1
Reputation: 7260
The internal representation of Hack code is very similar to that of PHP. Depending on how exactly existing code coverage libraries do their checking, it's possible that they'll just work. Have you tried using PHPUnit to write test cases over Hack code? Their coverage, for example, might just work!
Upvotes: 1