8000 Merge pull request #1240 from utPLSQL/bugfix/coverage_html_report_on_… · utPLSQL/utPLSQL@65db189 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65db189

Browse files
authored
Merge pull request #1240 from utPLSQL/bugfix/coverage_html_report_on_long_lines
Ability to report coverage on long lines.
2 parents c94472e + 8270715 commit 65db189

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

source/reporters/ut_coverage_report_html_helper.pkb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ create or replace package body ut_coverage_report_html_helper is
134134
l_file_part varchar2(32767);
135135
l_result ut_varchar2_rows := ut_varchar2_rows();
136136
l_coverage_pct number(5, 2);
137-
l_coverage_block_pct number(5, 2);
138137
l_hits varchar2(30);
139138
l_blocks varchar2(30);
139+
l_line_text varchar2(32767);
140+
e_buffer_too_small exception;
141+
pragma exception_init ( e_buffer_too_small, -19011 );
140142
begin
141143

142144
l_coverage_pct := coverage_pct(a_coverage_unit.covered_lines, a_coverage_unit.uncovered_lines);
@@ -148,10 +150,16 @@ create or replace package body ut_coverage_report_html_helper is
148150
ut_utils.append_to_list(l_result, l_file_part);
149151

150152
for line_no in 1 .. a_source_code.count loop
153+
begin
154+
l_line_text := dbms_xmlgen.convert(a_source_code(line_no));
155+
exception
156+
when e_buffer_too_small then
157+
l_line_text := dbms_xmlgen.convert(to_clob(a_source_code(line_no)));
158+
end;
151159
if not a_coverage_unit.lines.exists(line_no) then
152160
l_file_part := '
153161
<li class="' || line_status(null) || '" data-hits="" data-linenumber="' || line_no || '">
154-
<code class="sql">' || (dbms_xmlgen.convert(a_source_code(line_no))) ||
162+
<code class="sql">' || l_line_text ||
155163
'</code></li>';
156164
else
157165
l_hits := to_char(a_coverage_unit.lines(line_no).executions);
@@ -188,7 +196,7 @@ create or replace package body ut_coverage_report_html_helper is
188196
'</span>';
189197
end if;
190198
l_file_part := l_file_part || '
191-
<code class="sql">' || (dbms_xmlgen.convert(a_source_code(line_no))) ||
199+
<code class="sql">' || l_line_text ||
192200
'</code></li>';
193201
end if;
194202
ut_utils.append_to_list(l_result, l_file_part);
@@ -222,7 +230,6 @@ create or replace package body ut_coverage_report_html_helper is
222230
l_file_part varchar2(32767);
223231
l_title varchar2(100) := 'All files';
224232
l_coverage_pct number(5, 2);
225-
l_coverage_block_pct number(5, 2);
226233
l_result ut_varchar2_rows;
227234
l_id varchar2(50) := object_id(a_title);
228235
l_unit_coverage ut_coverage.t_unit_coverage;

test/ut3_user/reporters/test_coverage/test_html_coverage_reporter.pkb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,70 @@ create or replace package body test_html_coverage_reporter is
3232
ut.expect(l_actual).to_be_like(l_expected);
3333
end;
3434

35+
procedure setup_long_lines is
36+
pragma autonomous_transaction;
37+
begin
38+
39+
execute immediate q'[create or replace type string_array is table of varchar2(5 char);]';
40+
execute immediate q'[
41+
create or replace function f return integer is
42+
l_string_array string_array;
43+
l_count integer;
44+
begin
45+
-- line is 1912 chars long, 1911 characters seem to be the max. line length that works (@formatter:off)
46+
l_string_array := string_array('aahed', 'aalii', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abele', 'abers', 'abets', 'abies', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abohm', 'aboil', 'aboma', 'aboon', 'abord', 'abore', 'abram', 'abray', 'abrim', 'abrin', 'abris', 'absey', 'absit', 'abuna', 'abune', 'abuts', 'abuzz', 'abyes', 'abysm', 'acais', 'acari', 'accas', 'accoy', 'acerb', 'acers', 'aceta', 'achar', 'ached', 'aches', 'achoo', 'acids', 'acidy', 'acing', 'acini', 'ackee', 'acker', 'acmes', 'acmic', 'acned', 'acnes', 'acock', 'acold', 'acred', 'acres', 'acros', 'acted', 'actin', 'acton', 'acyls', 'adaws', 'adays', 'adbot', 'addax', 'added', 'adder', 'addio', 'addle', 'adeem', 'adhan', 'adieu', 'adios', 'adits', 'adman', 'admen', 'admix', 'adobo', 'adown', 'adoze', 'adrad', 'adred', 'adsum', 'aduki', 'adunc', 'adust', 'advew', 'adyta', 'adzed', 'adzes', 'aecia', 'aedes', 'aegis', 'aeons', 'aerie', 'aeros', 'aesir', 'afald', 'afara', 'afars', 'afear', 'aflaj', 'afore', 'afrit', 'afros', 'agama', 'agami', 'agars', 'agast', 'agave', 'agaze', 'agene', 'agers', 'agger', 'aggie', 'aggri', 'aggro', 'aggry', 'aghas', 'agila', 'agios', 'agism', 'agist', 'agita', 'aglee', 'aglet', 'agley', 'agloo', 'aglus', 'agmas', 'agoge', 'agone', 'agons', 'agood', 'agora', 'agria', 'agrin', 'agros', 'agued', 'agues', 'aguna', 'aguti', 'aheap', 'ahent', 'ahigh', 'ahind', 'ahing', 'ahint', 'ahold', 'ahull', 'ahuru', 'aidas', 'aided', 'aides', 'aidoi', 'aidos', 'aiery', 'aigas', 'aight', 'ailed', 'aimed', 'aimer', 'ainee', 'ainga', 'aioli', 'aired', 'airer', 'airns', 'airth', 'airts', 'aitch', 'aitus', 'aiver', 'aiyee', 'aizle', 'ajies', 'ajiva', 'ajuga', 'ajwan', 'akees', 'akela', 'akene', 'aking', 'akita', 'akkas', 'alaap', 'alack', 'alamo', 'aland', 'alane', 'alang', 'a');
47+
select count(*) into l_count from table(l_string_array);
48+
return l_count;
49+
end;]';
50+
51+
execute immediate q'[
52+
create or replace package test_f is
53+
--%suite
54+
55+
--%test
56+
procedure fail_ut_coverage_html_reporter;
57+
end;]';
58+
59+
execute immediate q'[
60+
create or replace package body test_f is
61+
procedure fail_ut_coverage_html_reporter is
62+
begin
63+
ut3_develop.ut.expect(f()).to_be_greater_or_equal(1);
64+
end;
65+
end;
66+
]';
67+
end;
68+
69+
procedure cleanup_long_lines is
70+
pragma autonomous_transaction;
71+
begin
72+
execute immediate 'drop package test_f';
73+
execute immediate 'drop function f';
74+
execute immediate 'drop type string_array force';
75+
end;
76+
77+
procedure report_long_lines is
78+
l_expected varchar2(32767);
79+
l_actual clob;
80+
l_name varchar2(250);
81+
begin
82+
--Arrange
83+
l_expected := '%l_string_array := string_array%';
84+
85+
l_actual :=
86+
ut3_tester_helper.coverage_helper.run_tests_as_job(
87+
q'[
88+
ut3_develop.ut.run(
89+
a_path => 'ut3_user.test_f',
90+
a_reporter=> ut3_develop.ut_coverage_html_reporter(),
91+
a_include_objects => ut3_develop.ut_varchar2_list( 'UT3_USER.F' )
92+
)
93+
]'
94+
);
95+
--Assert
96+
ut.expect(l_actual).to_be_like(l_expected);
97+
end;
98+
99+
35100
end test_html_coverage_reporter;
36101
/

test/ut3_user/reporters/test_coverage/test_html_coverage_reporter.pks

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@ create or replace package test_html_coverage_reporter is
66
--%test(reports on a project file mapped to database object in extended profiler coverage)
77
procedure report_on_file;
88

9+
procedure setup_long_lines;
10+
procedure cleanup_long_lines;
11+
12+
--%test(reports on lines exceeding 4000 chars after conversion to XML)
13+
--%beforetest(setup_long_lines)
14+
--%aftertest(cleanup_long_lines)
15+
procedure report_long_lines;
16+
917
end test_html_coverage_reporter;
1018
/

0 commit comments

Comments
 (0)
0