Skip to content

Creating a list of annotations allowed to treat package as annotated #1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/core/annotations/ut_annotation_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ create or replace package body ut_annotation_manager as
l_result sys_refcursor;
l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
l_card natural;
l_allowed_annotations varchar2(32767) := ut_utils.get_annotations_list_regex;
begin

l_card := ut_utils.scale_cardinality(cardinality(a_objects_to_refresh));
open l_result for
q'[select /*+ no_parallel */ x.name, x.text
from (select /*+ cardinality( r ]'||l_card||q'[ )*/
s.name, s.text, s.line,
max(case when s.text like '%--%\%%' escape '\'
and regexp_like(s.text,'^\s*--\s*%')
and regexp_like(s.text,'^\s*--\s*%(]'||l_allowed_annotations||q'[)')
then 'Y' else 'N' end
)
over(partition by s.name) is_annotated
Expand All @@ -125,7 +127,6 @@ create or replace package body ut_annotation_manager as
where x.is_annotated = 'Y'
order by x.name, x.line]'
using a_objects_to_refresh;

return l_result;
end;

Expand Down
47 changes: 14 additions & 33 deletions source/core/ut_suite_builder.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,27 @@ create or replace package body ut_suite_builder is
subtype t_object_name is varchar2(500);
subtype t_annotation_position is binary_integer;

gc_suite constant t_annotation_name := 'suite';
gc_suitepath constant t_annotation_name := 'suitepath';
gc_tags constant t_annotation_name := 'tags';
gc_suite constant t_annotation_name := ut_utils.gc_suite;
gc_suitepath constant t_annotation_name := ut_utils.gc_suitepath;
gc_tags constant t_annotation_name := ut_utils.gc_tags;
gc_test constant t_annotation_name := ut_utils.gc_test_execute;
gc_disabled constant t_annotation_name := 'disabled';
gc_displayname constant t_annotation_name := 'displayname';
gc_disabled constant t_annotation_name := ut_utils.gc_disabled_ann;
gc_displayname constant t_annotation_name := ut_utils.gc_displayname;
gc_beforeall constant t_annotation_name := ut_utils.gc_before_all;
gc_beforeeach constant t_annotation_name := ut_utils.gc_before_each;
gc_beforetest constant t_annotation_name := ut_utils.gc_before_test;
gc_afterall constant t_annotation_name := ut_utils.gc_after_all;
gc_aftereach constant t_annotation_name := ut_utils.gc_after_each;
gc_aftertest constant t_annotation_name := ut_utils.gc_after_test;
gc_throws constant t_annotation_name := 'throws';
gc_rollback constant t_annotation_name := 'rollback';
gc_context constant t_annotation_name := 'context';
gc_name constant t_annotation_name := 'name';
gc_endcontext constant t_annotation_name := 'endcontext';

type tt_annotations is table of t_annotation_name;

gc_supported_annotations constant tt_annotations
:= tt_annotations(
gc_suite,
gc_suitepath,
gc_tags,
gc_test,
gc_disabled,
gc_displayname,
gc_beforeall,
gc_beforeeach,
gc_beforetest,
gc_afterall,
gc_aftereach,
gc_aftertest,
gc_throws,
gc_rollback,
gc_context,
gc_name,
gc_endcontext
);
gc_throws constant t_annotation_name := ut_utils.gc_throws;
gc_rollback constant t_annotation_name := ut_utils.gc_rollback;
gc_context constant t_annotation_name := ut_utils.gc_context;
gc_name constant t_annotation_name := ut_utils.gc_name;
gc_endcontext constant t_annotation_name := ut_utils.gc_endcontext;


gc_supported_annotations constant ut_utils.tt_annotations
:= ut_utils.gc_supported_annotations;

type tt_executables is table of ut_executables index by t_annotation_position;

Expand Down
12 changes: 12 additions & 0 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -1024,5 +1024,17 @@ create or replace package body ut_utils is
return l_result;
end;

function get_annotations_list_regex return varchar2 is
cursor c_get_annotation_regex is
select listagg(column_value,'|') within group (order by column_value)
from table(gc_supported_annotations);
l_result varchar2(4000);
begin
open c_get_annotation_regex;
fetch c_get_annotation_regex into l_result;
close c_get_annotation_regex;
return l_result;
end get_annotations_list_regex;

end ut_utils;
/
36 changes: 36 additions & 0 deletions source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,48 @@ create or replace package ut_utils authid definer is
gc_version constant varchar2(50) := 'v3.1.14.4206-develop';

subtype t_executable_type is varchar2(30);
subtype t_annotation_name is varchar2(4000);
gc_suite constant t_annotation_name := 'suite';
gc_suitepath constant t_annotation_name := 'suitepath';
gc_tags constant t_annotation_name := 'tags';
gc_before_all constant t_executable_type := 'beforeall';
gc_before_each constant t_executable_type := 'beforeeach';
gc_before_test constant t_executable_type := 'beforetest';
gc_test_execute constant t_executable_type := 'test';
gc_after_test constant t_executable_type := 'aftertest';
gc_after_each constant t_executable_type := 'aftereach';
gc_after_all constant t_executable_type := 'afterall';
gc_disabled_ann constant t_annotation_name := 'disabled';
gc_displayname constant t_annotation_name := 'displayname';
gc_throws constant t_annotation_name := 'throws';
gc_rollback constant t_annotation_name := 'rollback';
gc_context constant t_annotation_name := 'context';
gc_name constant t_annotation_name := 'name';
gc_endcontext constant t_annotation_name := 'endcontext';

type tt_annotations is table of t_annotation_name;


gc_supported_annotations constant tt_annotations
:= tt_annotations(
gc_suite,
gc_suitepath,
gc_tags,
gc_before_all,
gc_before_each,
gc_before_test,
gc_test_execute,
gc_after_test,
gc_after_each,
gc_after_all,
gc_disabled_ann,
gc_displayname,
gc_throws,
gc_rollback,
gc_context,
gc_name ,
gc_endcontext
);

/* Constants: Test Results */
subtype t_test_result is binary_integer range 0 .. 3;
Expand Down Expand Up @@ -482,5 +517,6 @@ create or replace package ut_utils authid definer is
*/
function lengthb_clob( a_clob clob) return integer;

function get_annotations_list_regex return varchar2;
end ut_utils;
/
37 changes: 37 additions & 0 deletions test/ut3_tester/core/annotations/test_annotation_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ create or replace package body test_annotation_manager is
end;]');
end;

procedure add_badly_annotated_pck is
begin
exec_autonomous(q'[
create or replace package badly_annot_pkg as
--%sparameter(no parameter)
--%returns(no return)
--%usage(no usage)
procedure some_dummy_test_procedure;
end;]');
end;

procedure drop_dummy_test_package is
begin
exec_autonomous(q'[drop package dummy_test_package]');
Expand All @@ -66,6 +77,14 @@ create or replace package body test_annotation_manager is
null;
end;

procedure drop_badly_ann_pkg is
begin
exec_autonomous(q'[drop package badly_annot_pkg]');
exception
when others then
null;
end;

procedure recompile_dummy_test_package is
begin
exec_autonomous(q'[alter package dummy_test_package compile]');
Expand Down Expand Up @@ -462,5 +481,23 @@ create or replace package body test_annotation_manager is
assert_dummy_test_package(l_start_date);
end;

procedure issue_1278_correct_annotation is
l_actual sys_refcursor;
begin
--Arrange
add_badly_annotated_pck();
--Act
ut3_develop.ut_annotation_manager.rebuild_annotation_cache(sys_context('USERENV', 'CURRENT_USER'),'PACKAGE');
--Assert
open l_actual for
select *
from ut3_develop.ut_suite_cache_package
where object_owner = sys_context('USERENV', 'CURRENT_USER') and object_name = 'BADLY_ANNOT_PKG';

drop_badly_ann_pkg;
ut.expect(l_actual).to_be_empty;
end;


end test_annotation_manager;
/
3 changes: 3 additions & 0 deletions test/ut3_tester/core/annotations/test_annotation_manager.pks
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,8 @@ create or replace package test_annotation_manager is

--%endcontext

--%test(Issue #1278 of marking object as annotated when it is not)
procedure issue_1278_correct_annotation;

end test_annotation_manager;
/
Loading