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

Skip to content

Commit d1dc6e1

Browse files
committed
Fixes issue when in failure message appears a special characters or a tag like CDDATA.
1 parent b30ce47 commit d1dc6e1

7 files changed

Lines changed: 82 additions & 6 deletions

File tree

source/reporters/ut_junit_reporter.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ create or replace type body ut_junit_reporter is
5959
l_lines := a_test.failed_expectations(i).get_result_lines();
6060

6161
for j in 1 .. l_lines.count loop
62-
self.print_text(l_lines(j));
62+
self.print_text(dbms_xmlgen.convert(l_lines(j)));
6363
end loop;
6464
self.print_text(a_test.failed_expectations(i).caller_info);
6565
end loop;

source/reporters/ut_sonar_test_reporter.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ create or replace type body ut_sonar_test_reporter is
6060
for i in 1 .. a_test.failed_expectations.count loop
6161
l_lines := a_test.failed_expectations(i).get_result_lines();
6262
for i in 1 .. l_lines.count loop
63-
self.print_text(l_lines(i));
63+
self.print_text(dbms_xmlgen.convert(l_lines(i)));
6464
end loop;
6565
end loop;
6666
self.print_text(']]>');

source/reporters/ut_tfs_junit_reporter.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ create or replace type body ut_tfs_junit_reporter is
8080
for i in 1 .. a_test.failed_expectations.count loop
8181
l_lines := a_test.failed_expectations(i).get_result_lines();
8282
for j in 1 .. l_lines.count loop
83-
self.print_text(l_lines(j));
83+
self.print_text(dbms_xmlgen.convert(l_lines(j)));
8484
end loop;
8585
self.print_text(a_test.failed_expectations(i).caller_info);
8686
end loop;

test/core/reporters/test_junit_reporter.pkb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ create or replace package body test_junit_reporter as
6262
procedure test1 is begin ut.expect(1).to_equal(1); end;
6363
end;]';
6464

65+
execute immediate q'[create or replace package check_fail_escape is
66+
--%suitepath(core)
67+
--%suite(checkfailedescape)
68+
--%displayname(Check JUNIT XML failure is escaped)
69+
70+
--%test(Fail Miserably)
71+
procedure fail_miserably;
72+
73+
end;]';
74+
75+
execute immediate q'[create or replace package body check_fail_escape is
76+
procedure fail_miserably is
77+
begin
78+
ut3.ut.expect('test').to_equal('<![CDATA[some stuff]]>');
79+
end;
80+
end;]';
81+
6582
reporters.reporters_setup;
6683

6784
end;
@@ -267,13 +284,30 @@ create or replace package body test_junit_reporter as
267284
ut.expect(l_actual).to_be_like(l_expected);
268285
end;
269286

287+
288+
procedure check_failure_escaped is
289+
l_results ut3.ut_varchar2_list;
290+
l_actual clob;
291+
begin
292+
--Act
293+
select *
294+
bulk collect into l_results
295+
from table(ut3.ut.run('check_fail_escape',ut3.ut_junit_reporter()));
296+
l_actual := ut3.ut_utils.table_to_clob(l_results);
297+
--Assert
298+
ut.expect(l_actual).to_be_like('%<![CDATA[%
299+
Actual: &apos;test&apos; (varchar2) was expected to equal: &apos;&lt;![CDATA[some stuff]]&gt;&apos; (varchar2)%
300+
]]>%');
301+
end;
302+
270303
procedure remove_test_package is
271304
pragma autonomous_transaction;
272305
begin
273306
execute immediate 'drop package check_junit_reporting';
274307
execute immediate 'drop package check_junit_rep_suitepath';
275308
execute immediate 'drop package tst_package_junit_nodesc';
276309
execute immediate 'drop package tst_package_junit_nosuite';
310+
execute immediate 'drop package check_fail_escape';
277311
reporters.reporters_cleanup;
278312
end;
279313
end;

test/core/reporters/test_junit_reporter.pks

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ create or replace package test_junit_reporter as
2727
--%test(Reports duration according to XML specification for numbers)
2828
procedure check_nls_number_formatting;
2929

30-
--%test(Report on test without description)
30+
--%test(Report on test without description)
3131
procedure report_test_without_desc;
3232

33-
--%test(Report on suite without description)
33+
--%test(Report on suite without description)
3434
procedure report_suite_without_desc;
3535

36-
--%test(Report produces expected output)
36+
--%test(Report produces expected output)
3737
procedure reporort_produces_expected_out;
3838

39+
--%test( Validate that fail with special char are escaped )
40+
procedure check_failure_escaped;
41+
3942
--%afterall
4043
procedure remove_test_package;
4144
end;

test/core/reporters/test_tfs_junit_reporter.pkb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,28 @@ create or replace package body test_tfs_junit_reporter as
4848
null;
4949
end;
5050
end;]';
51+
52+
53+
execute immediate q'[create or replace package check_fail_escape is
54+
--%suitepath(core)
55+
--%suite(checkfailedescape)
56+
--%displayname(Check JUNIT XML failure is escaped)
57+
58+
--%test(Fail Miserably)
59+
procedure fail_miserably;
60+
61+
end;]';
62+
63+
execute immediate q'[create or replace package body check_fail_escape is
64+
procedure fail_miserably is
65+
begin
66+
ut3.ut.expect('test').to_equal('<![CDATA[some stuff]]>');
67+
end;
68+
end;]';
69+
5170
end;
5271

72+
5373
procedure escapes_special_chars is
5474
l_results ut3.ut_varchar2_list;
5575
l_actual clob;
@@ -143,6 +163,21 @@ create or replace package body test_tfs_junit_reporter as
143163
execute immediate 'alter session set NLS_NUMERIC_CHARACTERS='''||l_nls_numeric_characters||'''';
144164
end;
145165

166+
procedure check_failure_escaped is
167+
l_results ut3.ut_varchar2_list;
168+
l_actual clob;
169+
begin
170+
--Act
171+
select *
172+
bulk collect into l_results
173+
from table(ut3.ut.run('check_fail_escape',ut3.ut_tfs_junit_reporter()));
174+
l_actual := ut3.ut_utils.table_to_clob(l_results);
175+
--Assert
176+
ut.expect(l_actual).to_be_like('%<![CDATA[%
177+
Actual: &apos;test&apos; (varchar2) was expected to equal: &apos;&lt;![CDATA[some stuff]]&gt;&apos; (varchar2)%
178+
]]>%');
179+
end;
180+
146181
procedure check_classname_suitepath is
147182
l_results ut3.ut_varchar2_list;
148183
l_actual clob;
@@ -161,6 +196,7 @@ create or replace package body test_tfs_junit_reporter as
161196
execute immediate 'drop package check_junit_reporting';
162197
execute immediate 'drop package check_junit_rep_suitepath';
163198
execute immediate 'drop package check_junit_flat_suitepath';
199+
execute immediate 'drop package check_fail_escape';
164200
end;
165201
end;
166202
/

test/core/reporters/test_tfs_junit_reporter.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ create or replace package test_tfs_junit_reporter as
2727
--%test(Reports duration according to XML specification for numbers)
2828
procedure check_nls_number_formatting;
2929

30+
--%test( Validate that failures with special char are escaped )
31+
procedure check_failure_escaped;
32+
3033
--%afterall
3134
procedure remove_test_package;
3235
end;

0 commit comments

Comments
 (0)