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

Skip to content

Commit e8f4532

Browse files
committed
Skip as many %endcontext as nested %context annotations
We need to make sure to calculate the corrent %endcontext annotation, not just the first that is greater than the next nested %context. To operate correctly during recursion we also need information about the parent %endcontext position Fixes #1034
1 parent 090b74c commit e8f4532

3 files changed

Lines changed: 119 additions & 10 deletions

File tree

source/core/ut_suite_builder.pkb

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -708,15 +708,49 @@ create or replace package body ut_suite_builder is
708708
a_context_ann_pos t_annotation_position,
709709
a_package_annotations in out nocopy tt_annotations_by_name
710710
) return t_annotation_position is
711-
l_result t_annotation_position;
711+
l_next_endcontext_pos t_annotation_position;
712+
l_next_context_pos t_annotation_position;
713+
l_open_count integer := 0;
712714
begin
713715
if a_package_annotations.exists(gc_endcontext) then
714-
l_result := a_package_annotations(gc_endcontext).first;
715-
while l_result <= a_context_ann_pos loop
716-
l_result := a_package_annotations(gc_endcontext).next(l_result);
716+
l_next_endcontext_pos := a_package_annotations(gc_endcontext).first;
717+
while l_next_endcontext_pos <= a_context_ann_pos loop
718+
l_next_endcontext_pos := a_package_annotations(gc_endcontext).next(l_next_endcontext_pos);
717719
end loop;
720+
721+
l_next_context_pos := a_package_annotations(gc_context).next(a_context_ann_pos);
722+
loop
723+
-- Get all the %context annotations between start and first %endcontext
724+
while l_next_context_pos is not null and l_next_context_pos < l_next_endcontext_pos loop
725+
l_open_count := l_open_count+1;
726+
l_next_context_pos := a_package_annotations(gc_context).next(l_next_context_pos);
727+
end loop;
728+
-- Skip as many %endcontexts as we had additional contexts open
729+
while l_open_count > 0 loop
730+
l_open_count := l_open_count-1;
731+
l_next_endcontext_pos := a_package_annotations(gc_endcontext).next(l_next_endcontext_pos);
732+
end loop;
733+
-- Repeat until the next %context is later than next %endcontext
734+
exit when l_next_context_pos is null or l_next_context_pos > l_next_endcontext_pos;
735+
end loop;
718736
end if;
719-
return l_result;
737+
return l_next_endcontext_pos;
738+
end;
739+
740+
function has_nested_context(
741+
a_context_ann_pos t_annotation_position,
742+
a_package_annotations in out nocopy tt_annotations_by_name
743+
) return boolean is
744+
l_next_endcontext_pos t_annotation_position;
745+
begin
746+
if ( a_package_annotations.exists(gc_endcontext) and a_package_annotations.exists(gc_context)) then
747+
l_next_endcontext_pos := a_package_annotations(gc_endcontext).first;
748+
while l_next_endcontext_pos <= a_context_ann_pos loop
749+
l_next_endcontext_pos := a_package_annotations(gc_endcontext).next(l_next_endcontext_pos);
750+
end loop;
751+
return l_next_endcontext_pos > a_package_annotations(gc_context).next(a_context_ann_pos);
752+
end if;
753+
return false;
720754
end;
721755

722756
function get_annotations_in_context(
@@ -753,7 +787,8 @@ create or replace package body ut_suite_builder is
753787
a_parent in out nocopy ut_suite,
754788
a_annotations in out nocopy t_annotations_info,
755789
a_suite_items out nocopy ut_suite_items,
756-
a_parent_context_pos in integer := 0
790+
a_parent_context_pos in integer := 0,
791+
a_parent_end_context_pos in integer default null
757792
) is
758793
l_context_pos t_annotation_position;
759794
l_next_context_pos t_annotation_position;
@@ -802,7 +837,6 @@ create or replace package body ut_suite_builder is
802837
l_default_context_name := 'nested_context_#'||l_context_no;
803838
l_context_name := null;
804839
l_end_context_pos := get_endcontext_position(l_context_pos, a_annotations.by_name );
805-
806840
l_next_context_pos := a_annotations.by_name(gc_context).next(l_context_pos);
807841
if a_annotations.by_name.exists(gc_name) then
808842
l_context_name :=
@@ -841,9 +875,8 @@ create or replace package body ut_suite_builder is
841875
l_context.parse_time := a_annotations.parse_time;
842876

843877
--if nested context found
844-
if l_next_context_pos < l_end_context_pos or l_end_context_pos is null then
845-
get_context_items( l_context, a_annotations, l_context_items, l_context_pos );
846-
l_end_context_pos := get_endcontext_position(l_context_pos, a_annotations.by_name );
878+
if has_nested_context(l_context_pos, a_annotations.by_name) then
879+
get_context_items( l_context, a_annotations, l_context_items, l_context_pos, l_end_context_pos );
847880
else
848881
l_context_items := ut_suite_items();
849882
end if;
@@ -870,6 +903,9 @@ create or replace package body ut_suite_builder is
870903
exit when not a_annotations.by_name.exists( gc_context);
871904

872905
l_context_pos := a_annotations.by_name( gc_context).next( l_context_pos);
906+
if ( a_parent_end_context_pos is not null and a_parent_end_context_pos <= l_context_pos ) then
907+
l_context_pos := null;
908+
end if;
873909
l_context_no := l_context_no + 1;
874910
end loop;
875911
end;

test/ut3_tester/core/test_suite_builder.pkb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,74 @@ create or replace package body test_suite_builder is
767767
);
768768
end;
769769

770+
procedure nested_contexts_2 is
771+
l_actual clob;
772+
l_annotations ut3.ut_annotations;
773+
begin
774+
--Arrange
775+
l_annotations := ut3.ut_annotations(
776+
ut3.ut_annotation( 1, 'suite','Cool', null),
777+
ut3.ut_annotation( 2, 'suitepath','path', null),
778+
ut3.ut_annotation( 3, 'context','Level 1', null),
779+
ut3.ut_annotation( 4, 'name','context_1', null),
780+
ut3.ut_annotation( 5, 'context','Level 1.1', null),
781+
ut3.ut_annotation( 6, 'name','context_1_1', null),
782+
ut3.ut_annotation( 7, 'test', 'Test 1.1.1', 'test_1_1_1'),
783+
ut3.ut_annotation( 8, 'test', 'Test 1.1.2', 'test_1_1_2'),
784+
ut3.ut_annotation( 9, 'endcontext', null, null),
785+
ut3.ut_annotation(10, 'endcontext', null, null),
786+
ut3.ut_annotation(11, 'context','Level 2', null),
787+
ut3.ut_annotation(12, 'name','context_2', null),
788+
ut3.ut_annotation(13, 'test', 'Test 2.1', 'test_2_1'),
789+
ut3.ut_annotation(14, 'endcontext',null, null)
790+
);
791+
--Act
792+
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
793+
--Assert
794+
ut.expect(l_actual).to_be_like(
795+
'<ROWSET><ROW>'||
796+
'<UT_LOGICAL_SUITE>' ||
797+
'%<ITEMS>%' ||
798+
'<UT_SUITE_ITEM>' ||
799+
'%<NAME>context_1</NAME><DESCRIPTION>Level 1</DESCRIPTION><PATH>path.some_package.context_1</PATH>' ||
800+
'%<ITEMS>' ||
801+
'<UT_SUITE_ITEM>' ||
802+
'%<NAME>context_1_1</NAME><DESCRIPTION>Level 1.1</DESCRIPTION><PATH>path.some_package.context_1.context_1_1</PATH>' ||
803+
'%<ITEMS>' ||
804+
'<UT_SUITE_ITEM>' ||
805+
'%<NAME>test_1_1_1</NAME><DESCRIPTION>Test 1.1.1</DESCRIPTION><PATH>path.some_package.context_1.context_1_1.test_1_1_1</PATH>' ||
806+
'%</UT_SUITE_ITEM>' ||
807+
'<UT_SUITE_ITEM>' ||
808+
'%<NAME>test_1_1_2</NAME><DESCRIPTION>Test 1.1.2</DESCRIPTION><PATH>path.some_package.context_1.context_1_1.test_1_1_2</PATH>' ||
809+
'%</UT_SUITE_ITEM>' ||
810+
'</ITEMS>' ||
811+
'%<BEFORE_ALL_LIST/>' ||
812+
'%</UT_SUITE_ITEM>' ||
813+
'</ITEMS>' ||
814+
'%</UT_SUITE_ITEM>' ||
815+
'%</ITEMS>' ||
816+
'%</UT_LOGICAL_SUITE>'||
817+
'</ROW></ROWSET>'
818+
);
819+
-- Test both contexts separately due to ordering
820+
ut.expect(l_actual).to_be_like(
821+
'<ROWSET><ROW>'||
822+
'<UT_LOGICAL_SUITE>' ||
823+
'%<ITEMS>%' ||
824+
'<UT_SUITE_ITEM>' ||
825+
'%<NAME>context_2</NAME><DESCRIPTION>Level 2</DESCRIPTION><PATH>path.some_package.context_2</PATH>' ||
826+
'%<ITEMS>' ||
827+
'<UT_SUITE_ITEM>' ||
828+
'%<NAME>test_2_1</NAME><DESCRIPTION>Test 2.1</DESCRIPTION><PATH>path.some_package.context_2.test_2_1</PATH>' ||
829+
'%</UT_SUITE_ITEM>' ||
830+
'%</ITEMS>' ||
831+
'%</UT_SUITE_ITEM>' ||
832+
'%</ITEMS>' ||
833+
'%</UT_LOGICAL_SUITE>'||
834+
'</ROW></ROWSET>'
835+
);
836+
end;
837+
770838

771839
procedure before_after_in_context is
772840
l_actual clob;

test/ut3_tester/core/test_suite_builder.pks

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ create or replace package test_suite_builder is
33
--%suitepath(utplsql.ut3_tester.core)
44

55
--%context(--%suite annotation)
6+
--%name(suite)
67

78
--%test(Sets suite name from package name and leaves description empty)
89
procedure no_suite_description;
@@ -105,13 +106,17 @@ create or replace package test_suite_builder is
105106
--%endcontext
106107

107108
--%context(--%context annotation)
109+
--%name(context)
108110

109111
--%test(Creates nested suite for content between context/endcontext annotations)
110112
procedure suite_from_context;
111113

112114
--%test(Creates nested contexts inside a context)
113115
procedure nested_contexts;
114116

117+
--%test(Creates multiple nested contexts inside a context)
118+
procedure nested_contexts_2;
119+
115120
--%test(Associates before/after all/each to tests in context only)
116121
procedure before_after_in_context;
117122

0 commit comments

Comments
 (0)