forked from facebookarchive/pfff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_coverage.ml
130 lines (117 loc) · 4.25 KB
/
layer_coverage.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
(* 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.
*)
open Common
(*****************************************************************************)
(* 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 *)
(*****************************************************************************)
let gen_red_green_layer lines_coverage ~output =
let layer = { Layer_code.
title = "Test coverage (red/green)";
description = "Use information from xdebug";
files = lines_coverage +> List.map (fun (file, lines_cover) ->
let covered = lines_cover.Coverage_code.covered_sites in
let all = lines_cover.Coverage_code.all_sites in
let not_covered = Common2.minus_set all covered in
let percent =
try
Common2.pourcent_good_bad
(List.length covered) (List.length not_covered)
with Division_by_zero -> 0
in
file,
{ Layer_code.
micro_level =
(covered +> List.map (fun line -> line, "ok")) ++
(not_covered +> List.map (fun line -> line, "bad"))
;
macro_level = [
(match percent with
| 0 -> "no_info"
| n when n < 50 -> "bad"
| _ -> "ok"
),
1.
];
}
);
kinds = Layer_code.red_green_properties;
}
in
Layer_code.save_layer layer output
(* mostly a copy paste of gen_red_green_layer *)
let gen_heatmap_layer lines_coverage ~output =
let layer = { Layer_code.
title = "Test coverage (heatmap)";
description = "Use information from xdebug";
files = lines_coverage +> List.map (fun (file, lines_cover) ->
let covered = lines_cover.Coverage_code.covered_sites in
let all = lines_cover.Coverage_code.all_sites in
let not_covered = Common2.minus_set all covered in
let percent =
try
Common2.pourcent_good_bad
(List.length covered) (List.length not_covered)
with Division_by_zero -> 0
in
file,
{ Layer_code.
micro_level =
(covered +> List.map (fun line -> line, "ok")) ++
(not_covered +> List.map (fun line -> line, "bad"))
;
macro_level = [
(let percent_round = (percent / 10) * 10 in
spf "cover %d%%" percent_round
),
1.
];
}
);
kinds = Layer_code.heat_map_properties;
}
in
Layer_code.save_layer layer output
(*****************************************************************************)
(* Actions *)
(*****************************************************************************)
let actions () = [
"-gen_red_green_coverage_layer", " <json> <output>",
Common.mk_action_2_arg (fun jsonfile output ->
let cover = Coverage_code.load_lines_coverage jsonfile in
gen_red_green_layer cover ~output
);
"-gen_heatmap_coverage_layer", " <json> <output>",
Common.mk_action_2_arg (fun jsonfile output ->
let cover = Coverage_code.load_lines_coverage jsonfile in
gen_heatmap_layer cover ~output
);
]