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
tmp
  • Loading branch information
jgebal committed Mar 24, 2018
commit 2399981668a19b8761ad098ca44ae6339881fee2
113 changes: 90 additions & 23 deletions source/core/ut_suite_builder.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,51 @@ create or replace package body ut_suite_builder is
subtype t_procedure_name is varchar2(500);
subtype t_annotation_position is binary_integer;

type tt_annotations is table of t_annotation_text index by t_annotation_name;

type t_package_annotation is record(
--list of annotation texts for a given annotation indexed by annotation position:
--This would hold: ('some', 'other') for a single annotation name recurring in a single procedure example
-- --%beforetest(some)
-- --%beforetest(other)
-- --%test(some test with two before test procedures)
-- procedure some_test ...
-- when you'd like to have two beforetest procedures executed in a single test
type tt_annotation_texts is table of t_annotation_text index by t_annotation_position;

type tt_annotations_by_name is table of tt_annotation_texts index by t_annotation_name;

type t_object_annotation is record(
text varchar2(4000),
name varchar2(4000),
procedure_name varchar2(500),
procedure_annotations tt_annotations
procedure_annotations tt_annotations_by_name
);

type tt_package_annotations is table of t_package_annotation index by t_annotation_position;
--holds a list of package level annotations indexed (order) by position.
type tt_object_annotations is table of t_object_annotation index by t_annotation_position;

--holds all annotations for object
type t_package_annotations_info is record(
owner t_procedure_name,
name t_procedure_name,
annotations tt_package_annotations
annotations tt_object_annotations
);

type tt_positions is table of boolean index by t_annotation_position;
type tt_annotations_index is table of tt_positions index by t_annotation_name;
--list of all package level annotation positions for a given annotaion name
type tt_package_annot_positions is table of boolean index by t_annotation_position;
--index used to lookup package level annotations by package-level annotation name
type tt_annotations_index is table of tt_package_annot_positions index by t_annotation_name;

function is_last_annotation_for_proc(a_annotations ut_annotations, a_index binary_integer) return boolean is
begin
return a_index = a_annotations.count or a_annotations(a_index).subobject_name != nvl(a_annotations(a_index+1).subobject_name, ' ');
end;

function get_procedure_annotations(a_annotations ut_annotations, a_index binary_integer) return tt_annotations is
l_result tt_annotations;
function get_procedure_annotations(a_annotations ut_annotations, a_index binary_integer) return tt_annotations_by_name is
l_result tt_annotations_by_name;
i binary_integer := a_index;
begin
loop
l_result(a_annotations(i).name) := a_annotations(i).text;
l_result(a_annotations(i).name)(i) := a_annotations(i).text;
exit when is_last_annotation_for_proc(a_annotations, i);
i := a_annotations.next(i);
end loop;
Expand All @@ -71,14 +86,16 @@ create or replace package body ut_suite_builder is
else
l_result.annotations(l_annotation_no).procedure_name := a_object.annotations(l_annotation_no).subobject_name;
l_result.annotations(l_annotation_no).procedure_annotations := get_procedure_annotations(a_object.annotations, l_annotation_no);
l_annotation_no := l_annotation_no + l_result.annotations(l_annotation_no).procedure_annotations.count - 1;
if l_result.annotations(l_annotation_no).procedure_annotations.count > 0 then
l_annotation_no := l_annotation_no + l_result.annotations(l_annotation_no).procedure_annotations.count - 1;
end if;
end if;
l_annotation_no := a_object.annotations.next(l_annotation_no);
end loop;
return l_result;
end;

function build_annotation_index(a_annotations tt_package_annotations) return tt_annotations_index is
function build_annotation_index(a_annotations tt_object_annotations ) return tt_annotations_index is
l_result tt_annotations_index;
i binary_integer;
begin
Expand Down Expand Up @@ -137,6 +154,20 @@ create or replace package body ut_suite_builder is
return l_exception_number_list;
end;

procedure add_to_throws_numbers_list(
a_list in out nocopy ut_integer_list,
a_throws_ann_text tt_annotation_texts
) is
l_annotation_pos binary_integer;
begin
a_list := ut_integer_list();
l_annotation_pos := a_throws_ann_text.first;
while l_annotation_pos is not null loop
a_list := a_list multiset union build_exception_numbers_list( a_throws_ann_text(l_annotation_pos));
l_annotation_pos := a_throws_ann_text.next(l_annotation_pos);
end loop;
end;

procedure add_to_list(
a_executables in out nocopy ut_executables,
a_procedure_name varchar2,
Expand All @@ -151,9 +182,24 @@ create or replace package body ut_suite_builder is
a_executables(a_executables.last) := ut_executable(a_suite_item, a_procedure_name, a_event_name);
end;

procedure add_to_list(
a_executables in out nocopy ut_executables,
a_annotation_texts tt_annotation_texts,
a_event_name ut_utils.t_event_name,
a_suite_item ut_suite_item
) is
l_annotation_pos binary_integer;
begin
l_annotation_pos := a_annotation_texts.first;
while l_annotation_pos is not null loop
add_to_list(a_executables, a_annotation_texts(l_annotation_pos), a_event_name, a_suite_item );
l_annotation_pos := a_annotation_texts.next( l_annotation_pos);
end loop;
end;

procedure warning_on_extra_annotations(
a_suite in out nocopy ut_suite_item,
a_procedure_info t_package_annotation,
a_procedure_info t_object_annotation,
a_for_annotation varchar2
) is
l_annotation_name t_annotation_name;
Expand All @@ -176,20 +222,26 @@ create or replace package body ut_suite_builder is
procedure add_test(
a_suite in out nocopy ut_suite,
a_procedure_name varchar2,
a_annotations tt_annotations
a_annotations tt_annotations_by_name
) is
l_test ut_test;
l_test ut_test;
l_annotation_texts tt_annotation_texts;
l_annotation_pos binary_integer;
begin
l_test := ut_test(a_suite.object_owner, a_suite.object_name, a_procedure_name);

if a_annotations.exists('displayname') then
l_test.description := a_annotations('displayname');
l_annotation_texts := a_annotations('displayname');
--take the last definition if more than one was provided
l_test.description := l_annotation_texts(l_annotation_texts.last);
--TODO if more than one - warning
end if;
l_test.description := coalesce(l_test.description,a_annotations('test'));
l_test.description := coalesce(l_test.description,a_annotations('test')(a_annotations('test').last));
l_test.path := a_suite.path ||'.'||a_procedure_name;

if a_annotations.exists('rollback') then
l_test.rollback_type := get_rollback_type(a_annotations('rollback'));
l_annotation_texts := a_annotations('rollback');
l_test.rollback_type := get_rollback_type(l_annotation_texts(l_annotation_texts.last));
end if;

if a_annotations.exists('beforetest') then
Expand All @@ -199,7 +251,7 @@ create or replace package body ut_suite_builder is
add_to_list( l_test.after_test_list, a_annotations('aftertest'), ut_utils.gc_after_test, l_test );
end if;
if a_annotations.exists('throws') then
l_test.expected_error_codes := build_exception_numbers_list(a_annotations('throws'));
add_to_throws_numbers_list(l_test.expected_error_codes, a_annotations('throws'));
end if;
l_test.disabled_flag := ut_utils.boolean_to_int(a_annotations.exists('disabled'));

Expand All @@ -224,7 +276,7 @@ create or replace package body ut_suite_builder is
end;

procedure add_procedures_from_annot(
l_annotations tt_package_annotations,
l_annotations tt_object_annotations,
l_suite in out nocopy ut_suite,
l_before_each_list out ut_executables,
l_after_each_list out ut_executables
Expand Down Expand Up @@ -256,9 +308,24 @@ create or replace package body ut_suite_builder is
end loop;
end;

function build_suite(a_package t_package_annotations_info) return ut_logical_suite is
procedure add_suite_context(
a_suite in out nocopy ut_suite,
a_package_ann_index in out nocopy tt_annotations_index,
a_annotations in out nocopy tt_object_annotations
) is
begin
null;
-- while l_package_ann_index.exists('context') loop
-- if l_package_ann_index.exists('endcontext')
-- and l_package_ann_index.exists('endcontext').first > l_package_ann_index.exists('context').first then
-- null;
-- end if;
-- end loop;
end;

function create_suite(a_package t_package_annotations_info) return ut_logical_suite is
l_package_ann_index tt_annotations_index;
l_annotations tt_package_annotations;
l_annotations tt_object_annotations;
l_suite ut_suite;
l_before_each_list ut_executables;
l_after_each_list ut_executables;
Expand Down Expand Up @@ -323,7 +390,7 @@ create or replace package body ut_suite_builder is

function create_suite(a_object ut_annotated_object) return ut_logical_suite is
begin
return build_suite(convert_object_annotations(a_object));
return create_suite(convert_object_annotations(a_object));
end create_suite;

function build_suites_hierarchy(a_suites_by_path tt_schema_suites) return tt_schema_suites is
Expand Down
31 changes: 31 additions & 0 deletions test/core/test_suite_builder.pkb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
create or replace package body test_suite_builder is

function invoke_builder_for_annotations(
a_annotations ut3.ut_annotations,
a_package_name varchar2 := 'TEST_SUITE_BUILDER_PACKAGE'
) return clob is
l_suites ut3.ut_suite_builder.tt_schema_suites;
l_cursor sys_refcursor;
begin
open l_cursor for select value(x) from table(
ut3.ut_annotated_objects(
ut3.ut_annotated_object('UT3_TESTER', a_package_name, 'PACKAGE', a_annotations)
) ) x;
l_suites := ut3.ut_suite_builder.build_suites(l_cursor).schema_suites;
return xmltype(l_suites(l_suites.first)).getClobVal();
end;

procedure no_suite_description is
l_actual clob;
l_annotations ut3.ut_annotations;
begin
l_annotations := ut3.ut_annotations(
ut3.ut_annotation(1, 'suite',null, null)
);
l_actual := invoke_builder_for_annotations(l_annotations, 'SOME_PACKAGE');
ut.expect(l_actual).to_be_like('%<OBJECT_OWNER>UT3_TESTER</OBJECT_OWNER><OBJECT_NAME>some_package</OBJECT_NAME><NAME>some_package</NAME><DESCRIPTION/>%');
end;


end;
/
8 changes: 8 additions & 0 deletions test/core/test_suite_builder.pks
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
create or replace package test_suite_builder is
--%suite(suite_builder)
--%suitepath(utplsql.core)

--%test(Sets suite name from package name and leaves description empty)
procedure no_suite_description;
end;
/
Loading