123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127(* Yoann Padioleau
*
* Copyright (C) 2010 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)openCommon(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* Thin layer generator wrapper around the Coverage_tests_php.lines_coverage
* data, which itself is generated by running many unit tests with a
* tracer, xdebug or hphpi-tracer, on.
*
* We generate either a layer with red/green colors or one with
* heat-based colors for finer-grained visualization.
*)(*****************************************************************************)(* Types *)(*****************************************************************************)(*****************************************************************************)(* Helper *)(*****************************************************************************)(*****************************************************************************)(* Main entry point *)(*****************************************************************************)letgen_red_green_layerlines_coverage={Layer_code.title="Test coverage (red/green)";description="Use information from xdebug";files=lines_coverage|>List.map(fun(file,lines_cover)->letcovered=lines_cover.Coverage_code.covered_sitesinletall=lines_cover.Coverage_code.all_sitesinletnot_covered=Common2.minus_setallcoveredinletpercent=tryCommon2.pourcent_good_bad(List.lengthcovered)(List.lengthnot_covered)withDivision_by_zero->0infile,{Layer_code.micro_level=(covered|>List.map(funline->line,"ok"))@(not_covered|>List.map(funline->line,"bad"));macro_level=[(matchpercentwith|0->"no_info"|nwhenn<50->"bad"|_->"ok"),1.];});kinds=Layer_code.red_green_properties;}(* mostly a copy paste of gen_red_green_layer *)letgen_heatmap_layerlines_coverage={Layer_code.title="Test coverage (heatmap)";description="Use information from xdebug";files=lines_coverage|>List.map(fun(file,lines_cover)->letcovered=lines_cover.Coverage_code.covered_sitesinletall=lines_cover.Coverage_code.all_sitesinletnot_covered=Common2.minus_setallcoveredinletpercent=tryCommon2.pourcent_good_bad(List.lengthcovered)(List.lengthnot_covered)withDivision_by_zero->0infile,{Layer_code.micro_level=(covered|>List.map(funline->line,"ok"))@(not_covered|>List.map(funline->line,"bad"));macro_level=[(letpercent_round=(percent/10)*10inspf"cover %d%%"percent_round),1.];});kinds=Layer_code.heat_map_properties;}(*****************************************************************************)(* Actions *)(*****************************************************************************)letactions()=["-gen_red_green_coverage_layer"," <json> <output>",Common.mk_action_2_arg(funjsonfileoutput->letcover=Coverage_code.load_lines_coveragejsonfileinletlayer=gen_red_green_layercoverinLayer_code.save_layerlayeroutput);"-gen_heatmap_coverage_layer"," <json> <output>",Common.mk_action_2_arg(funjsonfileoutput->letcover=Coverage_code.load_lines_coveragejsonfileinletlayer=gen_heatmap_layercoverinLayer_code.save_layerlayeroutput);]