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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c787e47
Added support for multiple occurrences of before and after blocks.
jgebal Mar 4, 2018
2399981
tmp
jgebal Mar 14, 2018
2631355
Fixed issue with null items list.
jgebal Mar 15, 2018
a05475a
Redefined event listeners mechanism.
jgebal Mar 25, 2018
f955d2a
Redefined event listeners mechanism.
jgebal Mar 25, 2018
430f76f
Fixed minor bug in XUnit reporter (showing CDATA for errors even when…
jgebal Mar 25, 2018
2537ced
Changed propagation of rollback. Now rollback will propagate from par…
jgebal Mar 29, 2018
9308662
Fixed examples.
jgebal Mar 29, 2018
17ee8cb
Fixed test for empty description in 11g.
jgebal Mar 29, 2018
93be873
Fixed test for empty description in 11g.
jgebal Mar 29, 2018
75b96c3
Fixed double warning on missing endcontext annotation.
jgebal Mar 29, 2018
a6dadcc
fix in test to overcome 11g XML missing attributes in 3.0.4
jgebal Mar 30, 2018
4bc7ced
Merge branch 'develop' into feature/support_of_context
jgebal Apr 7, 2018
8a26845
Fixes after merging from develop.
jgebal Apr 7, 2018
e9c4e80
Fixed test failure on 11g R2 - some issues with LIKE operator, long p…
jgebal Apr 7, 2018
bfbfa43
Updated documentation.
jgebal Apr 7, 2018
9cd61bf
Marking first column as bold
jgebal Apr 7, 2018
1adf35d
Changed the way reporters events are registered.
jgebal Apr 14, 2018
71d0b70
Fixed issues with comment-replace in big package specs.
jgebal Apr 14, 2018
8617613
Updated test for comments removal to include multi-line comments with…
jgebal Apr 16, 2018
51ba943
Updated documentation with new and changed annotations.
jgebal Apr 16, 2018
ad3f830
Changed behaviour for duplicate annotations - first wins.
jgebal Apr 19, 2018
4346b57
Updates to documentation.
jgebal Apr 20, 2018
b1ff0fc
Updates to documentation.
jgebal Apr 20, 2018
ab5a1ca
Updated and extended documentation for annotations.
jgebal Apr 22, 2018
e672ef0
Added description of `context` to annotations documentation.
jgebal Apr 22, 2018
9897247
Merge remote-tracking branch 'origin/develop' into feature/support_of…
jgebal Apr 22, 2018
b2df93e
Integrated with develop branch changes.
jgebal Apr 22, 2018
d604127
Removed empty header from documentation.
jgebal Apr 24, 2018
9afb7be
A bit of code cleanup and tests alignment.
jgebal Apr 25, 2018
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
Prev Previous commit
Next Next commit
Changed the way reporters events are registered.
Fixed issue with invalid object type passed to events `before_calling_test_execute` `after_calling_test_execute`
Fixed cutting of multi-line comments when parsing-annotations.
Annotation position now indicates line number of annotation in package.
  • Loading branch information
jgebal committed Apr 14, 2018
commit 1adf35d70d697c020e8fbca6f181895ead042aa0
18 changes: 6 additions & 12 deletions source/core/annotations/ut_annotation_parser.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ create or replace package body ut_annotation_parser as
type tt_comment_list is table of varchar2(32767) index by pls_integer;

gc_annotation_qualifier constant varchar2(1) := '%';
gc_multiline_comment_pattern constant varchar2(50) := '/\*.*?\*/';
gc_annot_comment_pattern constant varchar2(30) := '^( |'||chr(09)||')*-- *('||gc_annotation_qualifier||'.*?)$'; -- chr(09) is a tab character
gc_comment_replacer_patter constant varchar2(50) := '{COMMENT#%N%}';
gc_comment_replacer_regex_ptrn constant varchar2(25) := '{COMMENT#(\d+)}';
Expand All @@ -32,13 +31,6 @@ create or replace package body ut_annotation_parser as
gc_annotation_pattern constant varchar2(50) := gc_annotation_qualifier || gc_regexp_identifier || '[ '||chr(9)||']*(\(.*?\)\s*?$)?';


function delete_multiline_comments(a_source in clob) return clob is
begin
return regexp_replace(srcstr => a_source
,pattern => gc_multiline_comment_pattern
,modifier => 'n');
end;

procedure add_annotation(
a_annotations in out nocopy ut_annotations,
a_position positiven,
Expand Down Expand Up @@ -147,7 +139,8 @@ create or replace package body ut_annotation_parser as

function extract_and_replace_comments(a_source in out nocopy clob) return tt_comment_list is
l_comments tt_comment_list;
l_comment_pos pls_integer;
l_comment_pos binary_integer;
l_comment_line binary_integer;
l_comment_replacer varchar2(50);
l_source clob := a_source;
begin
Expand All @@ -165,14 +158,15 @@ create or replace package body ut_annotation_parser as
-- position index is shifted by 1 because gc_annot_comment_pattern contains ^ as first sign
-- but after instr index already points to the char on that line
l_comment_pos := l_comment_pos-1;
l_comments(l_comments.count + 1) := trim(regexp_substr(srcstr => a_source
l_comment_line := regexp_count(substr(a_source,1,l_comment_pos),chr(10),1,'m')+1;
l_comments(l_comment_line) := trim(regexp_substr(srcstr => a_source
,pattern => gc_annot_comment_pattern
,occurrence => 1
,position => l_comment_pos
,modifier => 'm'
,subexpression => 2));

l_comment_replacer := replace(gc_comment_replacer_patter, '%N%', l_comments.count);
l_comment_replacer := replace(gc_comment_replacer_patter, '%N%', l_comment_line);

l_source := regexp_replace(srcstr => a_source
,pattern => gc_annot_comment_pattern
Expand Down Expand Up @@ -203,7 +197,7 @@ create or replace package body ut_annotation_parser as
l_comment_index positive;
begin

l_source := delete_multiline_comments(l_source);
l_source := ut_utils.replace_multiline_comments(l_source);

-- replace all single line comments with {COMMENT#12} element and store it's content for easier processing
-- this call modifies l_source
Expand Down
4 changes: 2 additions & 2 deletions source/core/coverage/ut_coverage_reporter_base.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ create or replace type body ut_coverage_reporter_base is
ut_coverage.coverage_pause();
end;

overriding final member procedure before_calling_test_execute(self in out nocopy ut_coverage_reporter_base, a_test in ut_test) is
overriding final member procedure before_calling_test_execute(self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable) is
begin
ut_coverage.coverage_resume();
end;
overriding final member procedure after_calling_test_execute (self in out nocopy ut_coverage_reporter_base, a_test in ut_test) is
overriding final member procedure after_calling_test_execute (self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable) is
begin
ut_coverage.coverage_pause();
end;
Expand Down
4 changes: 2 additions & 2 deletions source/core/coverage/ut_coverage_reporter_base.tps
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ create or replace type ut_coverage_reporter_base under ut_output_reporter_base(
overriding final member procedure before_calling_before_test(self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable),
overriding final member procedure after_calling_before_test (self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable),

overriding final member procedure before_calling_test_execute(self in out nocopy ut_coverage_reporter_base, a_test in ut_test),
overriding final member procedure after_calling_test_execute (self in out nocopy ut_coverage_reporter_base, a_test in ut_test),
overriding final member procedure before_calling_test_execute(self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable),
overriding final member procedure after_calling_test_execute (self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable),

overriding final member procedure before_calling_after_test(self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable),
overriding final member procedure after_calling_after_test (self in out nocopy ut_coverage_reporter_base, a_executable in ut_executable),
Expand Down
40 changes: 27 additions & 13 deletions source/core/types/ut_reporter_base.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ create or replace type body ut_reporter_base is
null;
end;

member procedure before_calling_test_execute(self in out nocopy ut_reporter_base, a_test in ut_test) is
member procedure before_calling_test_execute(self in out nocopy ut_reporter_base, a_executable in ut_executable) is
begin
null;
end;
member procedure after_calling_test_execute (self in out nocopy ut_reporter_base, a_test in ut_test) is
member procedure after_calling_test_execute (self in out nocopy ut_reporter_base, a_executable in ut_executable) is
begin
null;
end;
Expand Down Expand Up @@ -137,16 +137,30 @@ create or replace type body ut_reporter_base is
end;

overriding member function get_supported_events return ut_varchar2_list is
l_events_list ut_varchar2_list;
begin
select lower(replace(procedure_name,'CALLING_'))
bulk collect into l_events_list
from user_procedures
where object_name = upper(self_type)
and (procedure_name like 'BEFORE_%' or procedure_name like 'AFTER_%');
l_events_list.extend;
l_events_list(l_events_list.last) := ut_utils.gc_finalize;
return l_events_list;
return ut_varchar2_list(
ut_utils.gc_before_run,
ut_utils.gc_before_suite,
ut_utils.gc_before_test,
ut_utils.gc_before_before_all,
ut_utils.gc_before_before_each,
ut_utils.gc_before_before_test,
ut_utils.gc_before_test_execute,
ut_utils.gc_before_after_test,
ut_utils.gc_before_after_each,
ut_utils.gc_before_after_all,
ut_utils.gc_after_run,
ut_utils.gc_after_suite,
ut_utils.gc_after_test,
ut_utils.gc_after_before_all,
ut_utils.gc_after_before_each,
ut_utils.gc_after_before_test,
ut_utils.gc_after_test_execute,
ut_utils.gc_after_after_test,
ut_utils.gc_after_after_each,
ut_utils.gc_after_after_all,
ut_utils.gc_finalize
);
end;

overriding member procedure on_event( self in out nocopy ut_reporter_base, a_event_name varchar2, a_event_item ut_event_item) is
Expand All @@ -165,7 +179,7 @@ create or replace type body ut_reporter_base is
when ut_utils.gc_before_before_test
then self.before_calling_before_test(treat(a_event_item as ut_executable));
when ut_utils.gc_before_test_execute
then self.before_calling_test_execute(treat(a_event_item as ut_test));
then self.before_calling_test_execute(treat(a_event_item as ut_executable));
when ut_utils.gc_before_after_test
then self.before_calling_after_test(treat(a_event_item as ut_executable));
when ut_utils.gc_before_after_each
Expand All @@ -185,7 +199,7 @@ create or replace type body ut_reporter_base is
when ut_utils.gc_after_before_test
then self.after_calling_before_test(treat(a_event_item as ut_executable));
when ut_utils.gc_after_test_execute
then self.after_calling_test_execute(treat(a_event_item as ut_test));
then self.after_calling_test_execute(treat(a_event_item as ut_executable));
when ut_utils.gc_after_after_test
then self.after_calling_after_test(treat(a_event_item as ut_executable));
when ut_utils.gc_after_after_each
Expand Down
4 changes: 2 additions & 2 deletions source/core/types/ut_reporter_base.tps
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ create or replace type ut_reporter_base under ut_event_listener (
member procedure before_calling_before_test(self in out nocopy ut_reporter_base, a_executable in ut_executable),
member procedure after_calling_before_test (self in out nocopy ut_reporter_base, a_executable in ut_executable),

member procedure before_calling_test_execute(self in out nocopy ut_reporter_base, a_test in ut_test),
member procedure after_calling_test_execute (self in out nocopy ut_reporter_base, a_test in ut_test),
member procedure before_calling_test_execute(self in out nocopy ut_reporter_base, a_executable in ut_executable),
member procedure after_calling_test_execute (self in out nocopy ut_reporter_base, a_executable in ut_executable),

member procedure before_calling_after_test(self in out nocopy ut_reporter_base, a_executable in ut_executable),
member procedure after_calling_after_test (self in out nocopy ut_reporter_base, a_executable in ut_executable),
Expand Down
23 changes: 14 additions & 9 deletions source/core/ut_suite_builder.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ create or replace package body ut_suite_builder is
end loop;
end;

procedure duplicate_annotations_warning(
procedure warning_on_duplicate_annot(
a_suite in out nocopy ut_suite_item,
a_annoations tt_annotations_index,
a_for_annotation varchar2
Expand Down Expand Up @@ -290,15 +290,20 @@ create or replace package body ut_suite_builder is
a_before_each_list ut_executables,
a_after_each_list ut_executables
) is
l_test ut_test;
l_test ut_test;
l_context ut_logical_suite;
begin
if a_suite.items is not null then
for i in 1 .. a_suite.items.count loop
if a_suite.items(i) is of (ut_test) then
l_test := treat( a_suite.items(i) as ut_test);
l_test.before_each_list := a_before_each_list;
l_test.after_each_list := a_after_each_list;
l_test.before_each_list := coalesce(a_before_each_list,ut_executables()) multiset union all l_test.before_each_list;
l_test.after_each_list := l_test.after_each_list multiset union all coalesce(a_after_each_list,ut_executables());
a_suite.items(i) := l_test;
elsif a_suite.items(i) is of (ut_logical_suite) then
l_context := treat(a_suite.items(i) as ut_logical_suite);
update_before_after_list(l_context, a_before_each_list, a_after_each_list);
a_suite.items(i) := l_context;
end if;
end loop;
end if;
Expand Down Expand Up @@ -393,7 +398,7 @@ create or replace package body ut_suite_builder is
else
a_suite.put_warning('"--%suitepath" annotation requires a non-empty value. Annotation ignored.');
end if;
duplicate_annotations_warning(a_suite, a_package_ann_index, 'suitepath');
warning_on_duplicate_annot(a_suite, a_package_ann_index, 'suitepath');
end if;
a_suite.path := lower(coalesce(a_suite.path, l_object_name));

Expand All @@ -404,15 +409,15 @@ create or replace package body ut_suite_builder is
else
a_suite.put_warning('"--%displayname" annotation requires a non-empty value. Annotation ignored.');
end if;
duplicate_annotations_warning(a_suite, a_package_ann_index, 'displayname');
warning_on_duplicate_annot(a_suite, a_package_ann_index, 'displayname');
end if;

if a_package_ann_index.exists('rollback') then
l_rollback_type := get_rollback_type(a_annotations(a_package_ann_index('rollback').last).text);
if l_rollback_type is null then
a_suite.put_warning('"--%rollback" annotation requires one of values: "auto" or "manual". Annotation ignored.');
end if;
duplicate_annotations_warning(a_suite, a_package_ann_index, 'rollback');
warning_on_duplicate_annot(a_suite, a_package_ann_index, 'rollback');
end if;

a_suite.disabled_flag := ut_utils.boolean_to_int(a_package_ann_index.exists('disabled'));
Expand Down Expand Up @@ -491,7 +496,7 @@ create or replace package body ut_suite_builder is

l_suite.description := l_annotations(l_package_ann_index('context').first).text;
l_suite.description := l_annotations(l_context_pos).text;
duplicate_annotations_warning( l_suite, l_package_ann_index, 'suite' );
warning_on_duplicate_annot( l_suite, l_package_ann_index, 'suite' );

populate_suite_contents( l_suite, l_annotations, l_package_ann_index, 'context_'||l_context_no );

Expand Down Expand Up @@ -549,7 +554,7 @@ create or replace package body ut_suite_builder is
l_suite := ut_suite(a_package_annotations.owner, a_package_annotations.name);

l_suite.description := l_annotations(l_package_ann_index('suite').last).text;
duplicate_annotations_warning(l_suite, l_package_ann_index, 'suite');
warning_on_duplicate_annot(l_suite, l_package_ann_index, 'suite');

add_suite_contexts( l_suite, l_annotations, l_package_ann_index );
--by this time all contexts were consumed and l_annotations should not have any context/endcontext annotation in it.
Expand Down
101 changes: 98 additions & 3 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab,
if a_list is not null then
l_trimmed_list := ut_varchar2_list();
l_index := a_list.first;

while (l_index is not null) loop
l_trimmed_list.extend;
l_trimmed_list(l_trimmed_list.count) := regexp_replace(a_list(l_index), '(^['||a_regexp_to_trim||']*)|(['||a_regexp_to_trim||']*$)');
Expand All @@ -531,7 +531,7 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab,
if a_list is not null then
l_filtered_list := ut_varchar2_list();
l_index := a_list.first;

while (l_index is not null) loop
if regexp_like(a_list(l_index), a_regexp_filter) then
l_filtered_list.extend;
Expand All @@ -540,9 +540,104 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab,
l_index := a_list.next(l_index);
end loop;
end if;

return l_filtered_list;
end;



function replace_multiline_comments(a_source clob) return clob is
l_result clob;
l_ml_comment_start binary_integer := 1;
l_comment_start binary_integer := 1;
l_text_start binary_integer := 1;
l_escaped_text_start binary_integer := 1;
l_escaped_text_end_char varchar2(1 char);
l_end binary_integer := 1;
l_ml_comment clob;
l_newlines_count binary_integer;
l_offset binary_integer := 1;
l_length binary_integer := coalesce(dbms_lob.getlength(a_source), 0);
function is_before(a_x binary_integer, a_y binary_integer) return boolean is
begin
return a_x < a_y or a_y = 0;
end;
begin
l_ml_comment_start := instr(a_source,'/*');
l_comment_start := instr(a_source,'--');
l_text_start := instr(a_source,'''');
l_escaped_text_start := instr(a_source,q'[q']');
while l_offset > 0 and l_ml_comment_start > 0 loop

if l_ml_comment_start > 0 and (l_ml_comment_start < l_comment_start or l_comment_start = 0)
and (l_ml_comment_start < l_text_start or l_text_start = 0)and (l_ml_comment_start < l_escaped_text_start or l_escaped_text_start = 0)
then
l_end := instr(a_source,'*/',l_ml_comment_start+2);
append_to_clob(l_result, dbms_lob.substr(a_source, l_ml_comment_start-l_offset, l_offset));
if l_end > 0 then
l_ml_comment := substr(a_source, l_ml_comment_start, l_end-l_ml_comment_start);
l_newlines_count := length( l_ml_comment ) - length( translate( l_ml_comment, 'a'||chr(10), 'a') );
if l_newlines_count > 0 then
append_to_clob(l_result, lpad( chr(10), l_newlines_count, chr(10) ) );
end if;
l_end := l_end + 2;
end if;
else

if l_comment_start > 0 and (l_comment_start < l_ml_comment_start or l_ml_comment_start = 0)
and (l_comment_start < l_text_start or l_text_start = 0) and (l_comment_start < l_escaped_text_start or l_escaped_text_start = 0)
then
l_end := instr(a_source,chr(10),l_comment_start+2);
if l_end > 0 then
l_end := l_end + 1;
end if;
elsif l_text_start > 0 and (l_text_start < l_ml_comment_start or l_ml_comment_start = 0)
and (l_text_start < l_comment_start or l_comment_start = 0) and (l_text_start < l_escaped_text_start or l_escaped_text_start = 0)
then
l_end := instr(a_source,q'[']',l_text_start+1);

--skip double quotes while searching for end of quoted text
while l_end > 0 and l_end = instr(a_source,q'['']',l_text_start+1) loop
l_end := instr(a_source,q'[']',l_end+1);
end loop;
if l_end > 0 then
l_end := l_end + 1;
end if;

elsif l_escaped_text_start > 0 and (l_escaped_text_start < l_ml_comment_start or l_ml_comment_start = 0)
and (l_escaped_text_start < l_comment_start or l_comment_start = 0) and (l_escaped_text_start < l_text_start or l_text_start = 0)
then
--translate char "[" from the start of quoted text "q'[someting]'" into "]"
l_escaped_text_end_char := translate( substr(a_source, l_escaped_text_start + 2, 1), '[{(<', ']})>');
l_end := instr(a_source,l_escaped_text_end_char||'''',l_escaped_text_start + 3 );
if l_end > 0 then
l_end := l_end + 2;
end if;
end if;

if l_end = 0 then
append_to_clob(l_result, dbms_lob.substr(a_source, l_length-l_offset, l_offset));
else
append_to_clob(l_result, dbms_lob.substr(a_source, l_end-l_offset, l_offset));
end if;
end if;
l_offset := l_end;
if l_offset >= l_ml_comment_start then
l_ml_comment_start := instr(a_source,'/*',l_offset);
end if;
if l_offset >= l_comment_start then
l_comment_start := instr(a_source,'--',l_offset);
end if;
if l_offset >= l_text_start then
l_text_start := instr(a_source,'''',l_offset);
end if;
if l_offset >= l_escaped_text_start then
l_escaped_text_start := instr(a_source,q'[q']',l_offset);
end if;
end loop;
append_to_clob(l_result, dbms_lob.substr(a_source, offset=>l_end));
return l_result;
end;

end ut_utils;
/
5 changes: 5 additions & 0 deletions source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,10 @@ create or replace package ut_utils authid definer is
/*It takes a collection of type ut_varchar2_list and it only returns the elements which meets the regular expression*/
function filter_list(a_list IN ut_varchar2_list, a_regexp_filter in varchar2) return ut_varchar2_list;

/**
* Replaces multi-line comments in given source-code with empty lines
*/
function replace_multiline_comments(a_source clob) return clob;

end ut_utils;
/
Loading