Code Coverage Tool for Hacked Language

Is there a code coverage tool for the Hack language (on hhvm)?

This question is not about code coverage of PHP source code running on hhvm (which is possible, for example using PHPUnit), but for generating source code code written in the hacking language.

+3


source to share


3 answers


The current version of PHPUnit (4.4.4.5.4.6) does not 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 agree with Ira that the code coverage is using XDEBUG. However, for some reason PHPUnit didn't decide to cover HackLang in code.

First update:

This is because Hacklang has more registered commands (such as form, type) and more structures (lambdas) that php-token-stream cannot recognize them.



The fix is ​​pretty simple, but you can create a class that is not defined and extend it from PHP_Token. For example, 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 uses CodeCoverage to detect the executed line and in this project, on HHVM using fb_get_code_coverage

+4


source


The internal representation of the Hack code is very similar to the internal representation of PHP. Depending on how the existing code coverage libraries do their validation, it is possible that they will work. Have you tried using PHPUnit to write Hack code test cases? Their coverage, for example, might just work!



+1


source


While it can be useful for PHP to write test code in PHPUnit, most PHP 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 that this has nothing to do with Zend ... so the chances of it containing XDEBUG seem to be deleted. (Maybe Hack copied XDEBUG exactly?) If XDEBUG isn't available in Hack, these XDEBUG-based coverage tools literally can't collect the data they need.

To the extent that Hack is identical to PHP, our PHP Test Checker will likely work directly. It controls the source code and therefore does not depend in any way on the existence of XDEBUG. I suspect PHPUnit can be easily adapted.

(If the Hack is not exactly the same, the test coverage tool can be revised to handle the modified syntax quite easily, since it is based on a general goal transformation system).

+1


source







All Articles