@@ -625,7 +625,7 @@ create or replace package body ut_suite_builder is
625625 a_suite.path := lower(coalesce(a_suite.path, a_suite.object_name));
626626 end;
627627
628- procedure add_suite_tests (
628+ procedure add_tests_to_items (
629629 a_suite in out nocopy ut_suite,
630630 a_annotations t_annotations_info,
631631 a_suite_items in out nocopy ut_suite_items
@@ -738,7 +738,8 @@ create or replace package body ut_suite_builder is
738738 procedure get_suite_contexts_items(
739739 a_suite in out nocopy ut_suite,
740740 a_annotations in out nocopy t_annotations_info,
741- a_suite_items out nocopy ut_suite_items
741+ a_suite_items out nocopy ut_suite_items,
742+ a_parent_context_pos in integer := 0
742743 ) is
743744 l_context_pos t_annotation_position;
744745 l_end_context_pos t_annotation_position;
@@ -755,35 +756,43 @@ create or replace package body ut_suite_builder is
755756 return;
756757 end if;
757758
758- l_context_pos := a_annotations.by_name( gc_context).first ;
759+ l_context_pos := a_annotations.by_name( gc_context).next(a_parent_context_pos) ;
759760
760761 while l_context_pos is not null loop
761762 l_end_context_pos := get_endcontext_position(l_context_pos, a_annotations.by_name );
763+
764+ l_context_name := coalesce( a_annotations.by_line( l_context_pos ).text, gc_context||'_'||l_context_no );
765+ l_context := ut_suite_context(a_suite.object_owner, a_suite.object_name, l_context_name, l_context_pos );
766+ l_context.path := a_suite.path||'.'||l_context_name;
767+ l_context.description := a_annotations.by_line( l_context_pos ).text;
768+ l_context.parse_time := a_annotations.parse_time;
769+
770+ --if nested context found
771+ if a_annotations.by_name(gc_context).next(l_context_pos) < l_end_context_pos or l_end_context_pos is null then
772+ get_suite_contexts_items( l_context, a_annotations, l_context_items, l_context_pos );
773+ l_end_context_pos := get_endcontext_position(l_context_pos, a_annotations.by_name );
774+ else
775+ l_context_items := ut_suite_items();
776+ end if;
762777
763- exit when l_end_context_pos is null;
778+ if l_end_context_pos is null then
779+ a_suite.put_warning(
780+ 'Missing "--%endcontext" annotation for a "--%context" annotation. The end of package specification is effective end of context.'|| get_object_reference( a_suite, null, l_context_pos )
781+ );
782+ l_end_context_pos := a_annotations.by_line.last;
783+ end if;
764784
765- l_context_items := ut_suite_items();
766785 --create a sub-set of annotations to process as sub-suite (context)
767- l_ctx_annotations := get_annotations_in_context( a_annotations, l_context_pos, l_end_context_pos);
786+ l_ctx_annotations := get_annotations_in_context( a_annotations, l_context_pos, l_end_context_pos);
768787
769- l_context_name := coalesce(
770- l_ctx_annotations.by_line( l_context_pos ).text
771- , gc_context||'_'||l_context_no
772- );
773788 if l_context_names.exists(l_context_name) then
774789 add_annotation_ignored_warning( a_suite, 'context', 'Context name must be unique in a suite. Context and all of it''s content ignored.', l_context_pos );
775790 else
776791 l_context_names(l_context_name) := true;
777792
778- l_context := ut_suite_context(a_suite.object_owner, a_suite.object_name, l_context_name, l_context_pos );
779-
780- l_context.path := a_suite.path||'.'||l_context_name;
781- l_context.description := l_ctx_annotations.by_line( l_context_pos ).text;
782- l_context.parse_time := a_annotations.parse_time;
783-
784793 warning_on_duplicate_annot( l_context, l_ctx_annotations.by_name, gc_context );
785794
786- add_suite_tests ( l_context, l_ctx_annotations, l_context_items );
795+ add_tests_to_items ( l_context, l_ctx_annotations, l_context_items );
787796 add_items_to_list(a_suite_items, l_context_items);
788797 a_suite_items.extend;
789798 a_suite_items(a_suite_items.last) := l_context;
@@ -798,27 +807,17 @@ create or replace package body ut_suite_builder is
798807 end loop;
799808 end;
800809
801- procedure warning_on_incomplete_context (
810+ procedure warning_on_floating_endcontext (
802811 a_suite in out nocopy ut_suite,
803812 a_package_ann_index tt_annotations_by_name
804813 ) is
805814 l_annotation_pos t_annotation_position;
806815 begin
807- if a_package_ann_index.exists(gc_context) then
808- l_annotation_pos := a_package_ann_index(gc_context).first;
809- while l_annotation_pos is not null loop
810- add_annotation_ignored_warning(
811- a_suite, gc_context, 'Invalid annotation %%%. Cannot find following "--%endcontext".',
812- l_annotation_pos
813- );
814- l_annotation_pos := a_package_ann_index(gc_context).next(l_annotation_pos);
815- end loop;
816- end if;
817816 if a_package_ann_index.exists(gc_endcontext) then
818817 l_annotation_pos := a_package_ann_index(gc_endcontext).first;
819818 while l_annotation_pos is not null loop
820819 add_annotation_ignored_warning(
821- a_suite, gc_endcontext, 'Invalid annotation %%%. Cannot find preceding "--%context".',
820+ a_suite, gc_endcontext, 'Extra %%% annotation found . Cannot find corresponding "--%context".',
822821 l_annotation_pos
823822 );
824823 l_annotation_pos := a_package_ann_index(gc_endcontext).next(l_annotation_pos);
@@ -891,10 +890,10 @@ create or replace package body ut_suite_builder is
891890 build_suitepath( l_suite, l_annotations );
892891 get_suite_contexts_items( l_suite, l_annotations, a_suite_items );
893892 --create suite tests and add
894- add_suite_tests ( l_suite, l_annotations, a_suite_items );
893+ add_tests_to_items ( l_suite, l_annotations, a_suite_items );
895894
896895 --by this time all contexts were consumed and l_annotations should not have any context/endcontext annotation in it.
897- warning_on_incomplete_context ( l_suite, l_annotations.by_name );
896+ warning_on_floating_endcontext ( l_suite, l_annotations.by_name );
898897
899898 a_suite_items.extend;
900899 a_suite_items( a_suite_items.last) := l_suite;
0 commit comments