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

Skip to content

Commit 8a26845

Browse files
committed
Fixes after merging from develop.
Added additional tests for suite_builder. Adjusted variable names to match convention. Fixed setting of nls_params for XMLTYPE conversion using DBMS_XMLGEN.
1 parent 4bc7ced commit 8a26845

7 files changed

Lines changed: 165 additions & 50 deletions

File tree

source/core/events/ut_event_manager.pkb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ create or replace package body ut_event_manager as
2121
type t_listener_numbers is table of boolean index by t_listener_number;
2222
type t_events_listeners is table of t_listener_numbers index by t_event_name;
2323

24-
gc_event_listeners_index t_events_listeners;
25-
gc_listeners t_listeners;
24+
g_event_listeners_index t_events_listeners;
25+
g_listeners t_listeners;
2626

2727
procedure initialize is
2828
begin
29-
gc_event_listeners_index.delete;
30-
gc_listeners := t_listeners();
29+
g_event_listeners_index.delete;
30+
g_listeners := t_listeners();
3131
end;
3232

3333
procedure trigger_event( a_event_name t_event_name, a_event_object ut_event_item ) is
3434
begin
35-
if a_event_name is not null and gc_event_listeners_index.exists(a_event_name)
36-
and gc_event_listeners_index(a_event_name) is not null
35+
if a_event_name is not null and g_event_listeners_index.exists(a_event_name)
36+
and g_event_listeners_index(a_event_name) is not null
3737
then
38-
for listener_number in 1 .. gc_event_listeners_index(a_event_name).count loop
39-
gc_listeners(listener_number).on_event(a_event_name, a_event_object);
38+
for listener_number in 1 .. g_event_listeners_index(a_event_name).count loop
39+
g_listeners(listener_number).on_event(a_event_name, a_event_object);
4040
end loop;
4141
end if;
4242
end;
4343

4444
procedure add_event( a_event_name t_event_name, a_listener_pos binary_integer ) is
4545
begin
46-
gc_event_listeners_index(a_event_name)(a_listener_pos) := true;
46+
g_event_listeners_index(a_event_name)(a_listener_pos) := true;
4747
end;
4848

4949
procedure add_events( a_event_names ut_varchar2_list, a_listener_pos binary_integer ) is
@@ -55,12 +55,12 @@ create or replace package body ut_event_manager as
5555

5656
function add_listener( a_listener ut_event_listener ) return t_listener_number is
5757
begin
58-
if gc_listeners is null then
59-
gc_listeners := t_listeners();
58+
if g_listeners is null then
59+
g_listeners := t_listeners();
6060
end if;
61-
gc_listeners.extend;
62-
gc_listeners(gc_listeners.last) := a_listener;
63-
return gc_listeners.last;
61+
g_listeners.extend;
62+
g_listeners(g_listeners.last) := a_listener;
63+
return g_listeners.last;
6464
end;
6565

6666
procedure add_listener( a_listener ut_event_listener ) is

source/core/ut_suite_builder.pkb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ create or replace package body ut_suite_builder is
6767

6868
function get_procedure_annotations(a_annotations ut_annotations, a_index binary_integer) return tt_procedure_annotations is
6969
l_result tt_procedure_annotations;
70-
i binary_integer := a_index;
70+
l_index binary_integer := a_index;
7171
begin
7272
loop
73-
l_result(a_annotations(i).name)(i) := a_annotations(i).text;
74-
exit when is_last_annotation_for_proc(a_annotations, i);
75-
i := a_annotations.next(i);
73+
l_result(a_annotations(l_index).name)(l_index) := a_annotations(l_index).text;
74+
exit when is_last_annotation_for_proc(a_annotations, l_index);
75+
l_index := a_annotations.next(l_index);
7676
end loop;
7777
return l_result;
7878
end;
@@ -102,14 +102,14 @@ create or replace package body ut_suite_builder is
102102

103103
function build_annotation_index(a_annotations tt_package_annotations ) return tt_annotations_index is
104104
l_result tt_annotations_index;
105-
i binary_integer;
105+
l_idx binary_integer;
106106
begin
107-
i := a_annotations.first;
108-
while i is not null loop
109-
if a_annotations(i).name is not null then
110-
l_result(a_annotations(i).name)(i) := true;
107+
l_idx := a_annotations.first;
108+
while l_idx is not null loop
109+
if a_annotations(l_idx).name is not null then
110+
l_result(a_annotations(l_idx).name)(l_idx) := true;
111111
end if;
112-
i := a_annotations.next(i);
112+
l_idx := a_annotations.next(l_idx);
113113
end loop;
114114
return l_result;
115115
end;
@@ -119,15 +119,15 @@ create or replace package body ut_suite_builder is
119119
a_start_pos t_annotation_position,
120120
a_end_pos t_annotation_position
121121
) is
122-
i t_annotation_name;
122+
l_idx t_annotation_name;
123123
begin
124-
i := a_index.first;
125-
while i is not null loop
126-
a_index(i).delete(a_start_pos, a_end_pos);
127-
if a_index(i).count = 0 then
128-
a_index.delete(i);
124+
l_idx := a_index.first;
125+
while l_idx is not null loop
126+
a_index( l_idx ).delete( a_start_pos, a_end_pos);
127+
if a_index( l_idx ).count = 0 then
128+
a_index.delete( l_idx );
129129
end if;
130-
i := a_index.next(i);
130+
l_idx := a_index.next( l_idx );
131131
end loop;
132132
end;
133133

source/expectations/data_values/ut_data_value_anydata.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ create or replace type body ut_data_value_anydata as
3737
self.is_data_null := 1;
3838
end if;
3939
if not self.is_null() then
40-
open l_query for select a_value val from dual;
4140
ut_expectation_processor.set_xml_nls_params();
41+
open l_query for select a_value val from dual;
4242
l_ctx := sys.dbms_xmlgen.newcontext( l_query );
4343
dbms_xmlgen.setrowtag(l_ctx, '');
4444
dbms_xmlgen.setrowsettag(l_ctx, '');

source/reporters/ut_tfs_junit_reporter.tpb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ create or replace type body ut_tfs_junit_reporter is
9595
l_tests_count integer := a_suite.results_count.disabled_count + a_suite.results_count.success_count +
9696
a_suite.results_count.failure_count + a_suite.results_count.errored_count;
9797
l_suite ut_suite;
98+
l_outputs clob;
99+
l_errors ut_varchar2_list;
98100
begin
99101

100102
for i in 1 .. a_suite.items.count loop
@@ -114,20 +116,22 @@ create or replace type body ut_tfs_junit_reporter is
114116
end if;
115117
end loop;
116118
l_suite := treat(a_suite as ut_suite);
117-
if l_suite.before_all.serveroutput is not null or l_suite.after_all.serveroutput is not null then
119+
l_outputs := l_suite.get_serveroutputs();
120+
if l_outputs is not null and l_outputs != empty_clob() then
118121
self.print_text('<system-out>');
119122
self.print_text('<![CDATA[');
120-
self.print_clob(l_suite.get_serveroutputs());
123+
self.print_clob(l_outputs);
121124
self.print_text(']]>');
122125
self.print_text('</system-out>');
123126
else
124127
self.print_text('<system-out/>');
125128
end if;
126129

127-
if l_suite.before_all.error_stack is not null or l_suite.after_all.error_stack is not null then
130+
l_errors := l_suite.get_error_stack_traces();
131+
if l_errors is not empty then
128132
self.print_text('<system-err>');
129133
self.print_text('<![CDATA[');
130-
self.print_text(trim(l_suite.before_all.error_stack) || trim(chr(10) || chr(10) || l_suite.after_all.error_stack));
134+
self.print_clob(ut_utils.table_to_clob(l_errors));
131135
self.print_text(']]>');
132136
self.print_text('</system-err>');
133137
else

test/core/reporters/test_tfs_junit_reporter.pkb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ create or replace package body test_tfs_junit_reporter as
117117
ut.expect(l_actual).to_be_like('<testsuites>
118118
<testsuite tests="0" id="1" package="core.check_junit_rep_suitepath.check_junit_flat_suitepath" errors="0" failures="0" name="flatsuitepath" time="%" timestamp="%" hostname="%" >
119119
<properties/>
120-
<system-out>
121-
<![CDATA[
122-
]]>
123-
</system-out>
120+
<system-out/>
124121
<system-err/>
125122
</testsuite>%');
126123
end;

test/core/test_suite_builder.pkb

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@ create or replace package body test_suite_builder is
55
a_package_name varchar2 := 'TEST_SUITE_BUILDER_PACKAGE'
66
) return clob is
77
l_suites ut3.ut_suite_builder.tt_schema_suites;
8+
l_suite ut3.ut_logical_suite;
89
l_cursor sys_refcursor;
10+
l_xml xmltype;
911
begin
1012
open l_cursor for select value(x) from table(
1113
ut3.ut_annotated_objects(
1214
ut3.ut_annotated_object('UT3_TESTER', a_package_name, 'PACKAGE', a_annotations)
1315
) ) x;
1416
l_suites := ut3.ut_suite_builder.build_suites(l_cursor).schema_suites;
15-
return xmltype(l_suites(l_suites.first)).getClobVal();
17+
l_suite := l_suites(l_suites.first);
18+
19+
select deletexml(
20+
xmltype(l_suite),
21+
'//RESULTS_COUNT|//START_TIME|//END_TIME|//RESULT|//ASSOCIATED_EVENT_NAME' ||
22+
'|//TRANSACTION_INVALIDATORS|//ERROR_BACKTRACE|//ERROR_STACK|//SERVEROUTPUT'
23+
)
24+
into l_xml
25+
from dual;
26+
27+
return l_xml.getClobVal();
1628
end;
1729

1830
procedure no_suite_description is
@@ -363,19 +375,19 @@ create or replace package body test_suite_builder is
363375
--Act
364376
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
365377
--Assert
366-
ut.expect(l_actual).match(
378+
ut.expect(l_actual).to_be_like(
367379
'<UT_LOGICAL_SUITE><SELF_TYPE>UT_SUITE</SELF_TYPE><OBJECT_OWNER>UT3_TESTER</OBJECT_OWNER>' ||
368380
'<OBJECT_NAME>some_package</OBJECT_NAME><NAME>some_package</NAME><DESCRIPTION>Cool</DESCRIPTION>' ||
369-
'.*<WARNINGS><VARCHAR2>Annotations: &quot;--%afterall&quot;, &quot;--%aftereach&quot;, &quot;--%beforeall&quot;, &quot;--%beforeeach&quot;' ||
381+
'%<WARNINGS><VARCHAR2>Annotations: &quot;--\%afterall&quot;, &quot;--\%aftereach&quot;, &quot;--\%beforeall&quot;, &quot;--\%beforeeach&quot;' ||
370382
' were ignored for procedure &quot;DO_STUFF&quot;.' ||
371-
' Those annotations cannot be used with annotation: &quot;--%test&quot;</VARCHAR2></WARNINGS>'||
372-
'.*<UT_SUITE_ITEM>.*<OBJECT_NAME>some_package</OBJECT_NAME>.*<NAME>do_stuff</NAME>' ||
373-
'(.*<BEFORE_EACH_LIST/>)?' ||
374-
'(.*<AFTER_EACH_LIST/>)?' ||
375-
'(.*<BEFORE_ALL_LIST/>)?' ||
376-
'(.*<AFTER_ALL_LIST/>)?'
383+
' Those annotations cannot be used with annotation: &quot;--\%test&quot;</VARCHAR2></WARNINGS>'||
384+
'%<UT_SUITE_ITEM>%<OBJECT_NAME>some_package</OBJECT_NAME>%<NAME>do_stuff</NAME>%</UT_LOGICAL_SUITE>'
377385
,'\'
378386
);
387+
ut.expect(l_actual).not_to_be_like('%<BEFORE_EACH_LIST>%');
388+
ut.expect(l_actual).not_to_be_like('%<AFTER_EACH_LIST>%');
389+
ut.expect(l_actual).not_to_be_like('%<BEFORE_ALL_LIST>%');
390+
ut.expect(l_actual).not_to_be_like('%<AFTER_ALL_LIST>%');
379391
end;
380392

381393
procedure suite_from_context is
@@ -423,6 +435,102 @@ create or replace package body test_suite_builder is
423435
);
424436
end;
425437

438+
procedure before_after_in_context is
439+
l_actual clob;
440+
l_annotations ut3.ut_annotations;
441+
begin
442+
--Arrange
443+
l_annotations := ut3.ut_annotations(
444+
ut3.ut_annotation(1, 'suite','Cool', null),
445+
ut3.ut_annotation(2, 'test','In suite', 'suite_level_test'),
446+
ut3.ut_annotation(3, 'context','A context', null),
447+
ut3.ut_annotation(4, 'beforeall',null, 'context_beforeall'),
448+
ut3.ut_annotation(5, 'beforeeach',null, 'context_beforeeach'),
449+
ut3.ut_annotation(6, 'test', 'In context', 'test_in_a_context'),
450+
ut3.ut_annotation(7, 'aftereach',null, 'context_aftereach'),
451+
ut3.ut_annotation(8, 'afterall',null, 'context_afterall'),
452+
ut3.ut_annotation(9, 'endcontext',null, null)
453+
);
454+
--Act
455+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
456+
--Assert
457+
ut.expect(l_actual).to_be_like(
458+
'<UT_LOGICAL_SUITE>' ||
459+
'%<ITEMS>' ||
460+
'%<UT_SUITE_ITEM>' ||
461+
'%<NAME>context_1</NAME>' ||
462+
'%<ITEMS>' ||
463+
'%<UT_SUITE_ITEM>' ||
464+
'%<NAME>test_in_a_context</NAME>' ||
465+
'%<BEFORE_EACH_LIST>%<PROCEDURE_NAME>context_beforeeach</PROCEDURE_NAME>%</BEFORE_EACH_LIST>' ||
466+
'%<ITEM>%<PROCEDURE_NAME>test_in_a_context</PROCEDURE_NAME>%</ITEM>' ||
467+
'%<AFTER_EACH_LIST>%<PROCEDURE_NAME>context_aftereach</PROCEDURE_NAME>%</AFTER_EACH_LIST>' ||
468+
'%</UT_SUITE_ITEM>' ||
469+
'%</ITEMS>' ||
470+
'%<BEFORE_ALL_LIST>%<PROCEDURE_NAME>context_beforeall</PROCEDURE_NAME>%</BEFORE_ALL_LIST>' ||
471+
'%<AFTER_ALL_LIST>%<PROCEDURE_NAME>context_afterall</PROCEDURE_NAME>%</AFTER_ALL_LIST>' ||
472+
'%</UT_SUITE_ITEM>' ||
473+
'%<UT_SUITE_ITEM>' ||
474+
'%<NAME>suite_level_test</NAME>' ||
475+
'%<ITEM>%<PROCEDURE_NAME>suite_level_test</PROCEDURE_NAME>%</ITEM>' ||
476+
'%</UT_SUITE_ITEM>' ||
477+
'%</ITEMS>' ||
478+
'%</UT_LOGICAL_SUITE>'
479+
);
480+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%</ITEMS>%<BEFORE_EACH_LIST>%</ITEMS>%');
481+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%</ITEMS>%<AFTER_EACH_LIST>%</ITEMS>%');
482+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%</ITEMS>%</ITEMS>%<BEFORE_ALL_LIST>%');
483+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%</ITEMS>%</ITEMS>%<AFTER_ALL_LIST>%');
484+
end;
485+
486+
procedure before_after_out_of_context is
487+
l_actual clob;
488+
l_annotations ut3.ut_annotations;
489+
begin
490+
--Arrange
491+
l_annotations := ut3.ut_annotations(
492+
ut3.ut_annotation(1, 'suite','Cool', null),
493+
ut3.ut_annotation(2, 'beforeall',null, 'suite_level_beforeall'),
494+
ut3.ut_annotation(3, 'beforeeach',null, 'suite_level_beforeeach'),
495+
ut3.ut_annotation(4, 'test','In suite', 'suite_level_test'),
496+
ut3.ut_annotation(5, 'context','A context', null),
497+
ut3.ut_annotation(6, 'test', 'In context', 'test_in_a_context'),
498+
ut3.ut_annotation(7, 'endcontext',null, null),
499+
ut3.ut_annotation(8, 'aftereach',null, 'suite_level_aftereach'),
500+
ut3.ut_annotation(9, 'afterall',null, 'suite_level_afterall')
501+
);
502+
--Act
503+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
504+
--Assert
505+
ut.expect(l_actual).to_be_like(
506+
'<UT_LOGICAL_SUITE>' ||
507+
'%<ITEMS>' ||
508+
'%<UT_SUITE_ITEM>' ||
509+
'%<NAME>context_1</NAME>' ||
510+
'%<ITEMS>' ||
511+
'%<UT_SUITE_ITEM>' ||
512+
'%<NAME>test_in_a_context</NAME>' ||
513+
'%<ITEM>%<PROCEDURE_NAME>test_in_a_context</PROCEDURE_NAME>%</ITEM>' ||
514+
'%</UT_SUITE_ITEM>' ||
515+
'%</ITEMS>' ||
516+
'%</UT_SUITE_ITEM>' ||
517+
'%<UT_SUITE_ITEM>' ||
518+
'%<NAME>suite_level_test</NAME>' ||
519+
'%<BEFORE_EACH_LIST>%<PROCEDURE_NAME>suite_level_beforeeach</PROCEDURE_NAME>%</BEFORE_EACH_LIST>' ||
520+
'%<ITEM>%<PROCEDURE_NAME>suite_level_test</PROCEDURE_NAME>%</ITEM>' ||
521+
'%<AFTER_EACH_LIST>%<PROCEDURE_NAME>suite_level_aftereach</PROCEDURE_NAME>%</AFTER_EACH_LIST>' ||
522+
'%</UT_SUITE_ITEM>' ||
523+
'%</ITEMS>' ||
524+
'%<BEFORE_ALL_LIST>%<PROCEDURE_NAME>suite_level_beforeall</PROCEDURE_NAME>%</BEFORE_ALL_LIST>' ||
525+
'%<AFTER_ALL_LIST>%<PROCEDURE_NAME>suite_level_afterall</PROCEDURE_NAME>%</AFTER_ALL_LIST>' ||
526+
'%</UT_LOGICAL_SUITE>'
527+
);
528+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%<BEFORE_EACH_LIST>%</ITEMS>%</ITEMS>%');
529+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%<AFTER_EACH_LIST>%</ITEMS>%</ITEMS>%');
530+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%</ITEMS>%<BEFORE_ALL_LIST>%</ITEMS>%');
531+
ut.expect(l_actual).not_to_be_like('%<ITEMS>%<ITEMS>%</ITEMS>%<AFTER_ALL_LIST>%</ITEMS>%');
532+
end;
533+
426534
procedure context_without_endcontext is
427535
l_actual clob;
428536
l_annotations ut3.ut_annotations;

test/core/test_suite_builder.pks

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ create or replace package test_suite_builder is
5656
--%test(Creates nested suite for content between context/endcontext annotations)
5757
procedure suite_from_context;
5858

59+
--%test(Associates before/after all/each to tests in context only)
60+
procedure before_after_in_context;
61+
62+
--%test(Does not propagate before/after each to context)
63+
procedure before_after_out_of_context;
64+
5965
--%test(Does not create context and gives warning when endcontext is missing)
6066
procedure context_without_endcontext;
6167

62-
--%test(Gives warning when endcontext is missing a preceding context)
68+
--%test(Gives warning if --%endcontext is missing a preceding --%context)
6369
procedure endcontext_without_context;
6470

6571
end;

0 commit comments

Comments
 (0)