-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathut_coverage_helper_block.pkb
More file actions
110 lines (98 loc) · 4.02 KB
/
ut_coverage_helper_block.pkb
File metadata and controls
110 lines (98 loc) · 4.02 KB
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
create or replace package body ut_coverage_helper_block is
/*
utPLSQL - Version 3
Copyright 2016 - 2021 utPLSQL Project
Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
type t_block_row is record(
line binary_integer
,blocks binary_integer
,covered_blocks binary_integer);
type t_block_rows is table of t_block_row;
function coverage_start(a_run_comment varchar2) return integer is
begin
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
return dbms_plsql_code_coverage.start_coverage(run_comment => a_run_comment);
$else
return null;
$end
end;
procedure coverage_stop is
begin
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
dbms_plsql_code_coverage.stop_coverage();
$else
null;
$end
exception
when others then
if sqlcode = -08402 then
dbms_output.put_line('Unable to finish gathering coverage with DBMS_PLSQL_CODE_COVERAGE. ');
dbms_output.put_line('Encountered exception `ORA-08402` when calling procedure `DBMS_PLSQL_CODE_COVERAGE.STOP_COVERAGE()`.');
dbms_output.put_line('Coverage report will only include line-level code-coverage (without branches).');
dbms_output.put_line('Please reference following issue for details on possible causes: https://github.com/utPLSQL/utPLSQL/issues/1097 ');
end if;
end;
function block_results(a_object ut_coverage_helper.t_tmp_table_object, a_coverage_run_id raw) return t_block_rows is
l_coverage_rows t_block_rows;
l_ut_owner varchar2(250) := ut_utils.ut_owner;
begin
execute immediate q'[
select /*+ no_parallel */
line as line,
count(block) as blocks,
sum(covered) as covered_blocks
from (select line,
block,
max(covered) as covered
from dbmspcc_units ccu
join ]'||l_ut_owner||q'[.ut_coverage_runs r
on r.block_coverage_id = ccu.run_id
left join dbmspcc_blocks ccb
on ccu.run_id = ccb.run_id
and ccu.object_id = ccb.object_id
where r.coverage_run_id = :a_coverage_run_id
and ccu.owner = :a_object_owner
and ccu.name = :a_object_name
and ccu.type = :a_object_type
group by ccb.line, ccb.block
)
group by line
having count(block) > 1
order by line]'
bulk collect into l_coverage_rows
using
a_coverage_run_id, a_object.owner,
a_object.name, a_object.type;
return l_coverage_rows;
end;
function get_raw_coverage_data(a_object ut_coverage_helper.t_tmp_table_object, a_coverage_run_id raw) return ut_coverage_helper.t_unit_line_calls is
l_tmp_data t_block_rows;
l_results ut_coverage_helper.t_unit_line_calls;
begin
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
l_tmp_data := block_results(a_object, a_coverage_run_id);
for i in 1 .. l_tmp_data.count loop
l_results(l_tmp_data(i).line).blocks := l_tmp_data(i).blocks;
l_results(l_tmp_data(i).line).covered_blocks := l_tmp_data(i).covered_blocks;
l_results(l_tmp_data(i).line).partcovered :=
case
when (l_tmp_data(i).covered_blocks > 0)
and (l_tmp_data(i).blocks > l_tmp_data(i).covered_blocks)
then 1
else 0
end;
end loop;
$end
return l_results;
end;
end;
/