Search code examples
code-coveragehacklang

Code coverage tool for hack language


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.


Solution

  • 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