Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3ce10c

Browse files
authored
Merge pull request #626 from lwasylow/feature/12cblockcoverage
Feature/12cblockcoverage
2 parents faab0fe + 1289e99 commit d3ce10c

2 files changed

Lines changed: 163 additions & 0 deletions

File tree

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
create or replace package body test_coverage is
2+
3+
g_run_id integer;
4+
5+
function get_mock_run_id return integer is
6+
v_result integer;
7+
begin
8+
select nvl(min(runid),0) - 1 into v_result
9+
from ut3.plsql_profiler_runs;
10+
return v_result;
11+
end;
12+
13+
procedure create_dummy_coverage_package is
14+
pragma autonomous_transaction;
15+
begin
16+
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE is
17+
procedure do_stuff;
18+
end;]';
19+
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE is
20+
procedure do_stuff is
21+
begin
22+
if 1 = 2 then
23+
dbms_output.put_line('should not get here');
24+
else
25+
dbms_output.put_line('should get here');
26+
end if;
27+
end;
28+
end;]';
29+
end;
30+
31+
procedure create_dummy_coverage_test is
32+
pragma autonomous_transaction;
33+
begin
34+
execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE is
35+
--%suite(dummy coverage test)
36+
--%suitepath(coverage_testing)
37+
38+
--%test
39+
procedure test_do_stuff;
40+
end;]';
41+
execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE is
42+
procedure test_do_stuff is
43+
begin
44+
dummy_coverage.do_stuff;
45+
end;
46+
end;]';
47+
end;
48+
49+
procedure create_dummy_coverage_test_1 is
50+
pragma autonomous_transaction;
51+
begin
52+
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE_1 is
53+
procedure do_stuff;
54+
end;]';
55+
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE_1 is
56+
procedure do_stuff is
57+
begin
58+
if 1 = 2 then
59+
dbms_output.put_line('should not get here');
60+
else
61+
dbms_output.put_line('should get here');
62+
end if;
63+
end;
64+
end;]';
65+
execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE_1 is
66+
--%suite(dummy coverage test 1)
67+
--%suitepath(coverage_testing)
68+
69+
--%test
70+
procedure test_do_stuff;
71+
end;]';
72+
execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE_1 is
73+
procedure test_do_stuff is
74+
begin
75+
dummy_coverage_1.do_stuff;
76+
end;
77+
end;]';
78+
end;
79+
80+
procedure drop_dummy_coverage_test_1 is
81+
pragma autonomous_transaction;
82+
begin
83+
execute immediate q'[drop package UT3.DUMMY_COVERAGE_1]';
84+
execute immediate q'[drop package UT3.TEST_DUMMY_COVERAGE_1]';
85+
end;
86+
87+
88+
procedure mock_coverage_data(a_run_id integer) is
89+
c_unit_id constant integer := 1;
90+
begin
91+
insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment)
92+
values(a_run_id, user, sysdate, 'unit testing utPLSQL');
93+
94+
insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name)
95+
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE');
96+
97+
insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time)
98+
select a_run_id, c_unit_id, 4, 1, 1 from dual union all
99+
select a_run_id, c_unit_id, 5, 0, 0 from dual union all
100+
select a_run_id, c_unit_id, 7, 1, 1 from dual;
101+
end;
102+
103+
procedure setup_dummy_coverage is
104+
pragma autonomous_transaction;
105+
begin
106+
create_dummy_coverage_package();
107+
create_dummy_coverage_test();
108+
g_run_id := get_mock_run_id();
109+
ut3.ut_coverage_helper.mock_coverage_id(g_run_id);
110+
mock_coverage_data(g_run_id);
111+
commit;
112+
end;
113+
114+
procedure cleanup_dummy_coverage is
115+
pragma autonomous_transaction;
116+
begin
117+
begin execute immediate q'[drop package ut3.test_dummy_coverage]'; exception when others then null; end;
118+
begin execute immediate q'[drop package ut3.dummy_coverage]'; exception when others then null; end;
119+
delete from ut3.plsql_profiler_data where runid = g_run_id;
120+
delete from ut3.plsql_profiler_units where runid = g_run_id;
121+
delete from ut3.plsql_profiler_runs where runid = g_run_id;
122+
commit;
123+
end;
124+
125+
procedure invalid_coverage_type is
126+
l_expected clob;
127+
l_actual clob;
128+
l_results ut3.ut_varchar2_list;
129+
begin
130+
--Arrange
131+
l_expected := '%<file path="ut3.dummy_coverage">%';
132+
--Act
133+
select *
134+
bulk collect into l_results
135+
from table(
136+
ut3.ut.run(
137+
a_path => 'ut3.test_dummy_coverage',
138+
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
139+
a_include_objects => ut3.ut_varchar2_list( 'ut3.dummy_coverage' )
140+
)
141+
);
142+
end;
143+
144+
end;
145+
/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
create or replace package test_coverage is
2+
3+
--%suite
4+
--%suitepath(utplsql.core.reporters)
5+
6+
--%beforeall
7+
procedure setup_dummy_coverage;
8+
9+
--%afterall
10+
procedure cleanup_dummy_coverage;
11+
12+
13+
--%test(Coverage is requested for invalid type of coverage)
14+
--%throws(-20215)
15+
procedure invalid_coverage_type;
16+
17+
end;
18+
/

0 commit comments

Comments
 (0)