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

Skip to content

Commit d211348

Browse files
committed
Added control over rollback behavior in ut_runner.run
Fixed failing test.
1 parent eb3df21 commit d211348

11 files changed

Lines changed: 55 additions & 29 deletions

File tree

source/api/ut_runner.pkb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ create or replace package body ut_runner is
8383
a_include_objects ut_varchar2_list := null,
8484
a_exclude_objects ut_varchar2_list := null,
8585
a_fail_on_errors boolean := false,
86-
a_client_character_set varchar2 := null
86+
a_client_character_set varchar2 := null,
87+
a_perform_rollback boolean := true
8788
) is
8889
l_run ut_run;
8990
l_coverage_schema_names ut_varchar2_rows;
@@ -141,13 +142,17 @@ create or replace package body ut_runner is
141142
l_run.do_execute();
142143

143144
finish_run(l_run);
144-
rollback;
145+
if a_perform_rollback then
146+
rollback;
147+
end if;
145148
exception
146149
when others then
147150
finish_run(l_run);
148151
dbms_output.put_line(dbms_utility.format_error_backtrace);
149152
dbms_output.put_line(dbms_utility.format_error_stack);
150-
rollback;
153+
if a_perform_rollback then
154+
rollback;
155+
end if;
151156
raise;
152157
end;
153158
if a_fail_on_errors and l_run.result in (ut_utils.gc_failure, ut_utils.gc_error) then

source/api/ut_runner.pks

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ create or replace package ut_runner authid current_user is
4343
* @param a_include_objects list of database objects (in format 'owner.name') that coverage should be reported on
4444
* @param a_exclude_objects list of database objects (in format 'owner.name') that coverage should be skipped for
4545
* @param a_fail_on_errors true/false - should an exception be thrown when tests are completed with failures/errors
46+
* @param a_client_character_set if provided, affects some of reporters by setting specific character set for XML/HTML reports
47+
* @param a_perform_rollback true/false - should rollback be performed as part of test execution (default true)
48+
4649
*
4750
* @example
4851
* Parameter `a_paths` accepts values of the following formats:
@@ -65,7 +68,8 @@ create or replace package ut_runner authid current_user is
6568
a_include_objects ut_varchar2_list := null,
6669
a_exclude_objects ut_varchar2_list := null,
6770
a_fail_on_errors boolean := false,
68-
a_client_character_set varchar2 := null
71+
a_client_character_set varchar2 := null,
72+
a_perform_rollback boolean := true
6973
);
7074

7175
/**

source/core/annotations/ut_annotation_manager.pkb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ create or replace package body ut_annotation_manager as
2222
function get_missing_objects(a_object_owner varchar2, a_object_type varchar2) return ut_annotation_objs_cache_info is
2323
l_rows sys_refcursor;
2424
l_ut_owner varchar2(250) := ut_utils.ut_owner;
25-
l_objects_view varchar2(200) := ut_metadata.get_dba_view('dba_objects');
25+
l_objects_view varchar2(200) := ut_metadata.get_objects_view_name();
2626
l_cursor_text varchar2(32767);
2727
l_result ut_annotation_objs_cache_info;
2828
begin
@@ -54,7 +54,7 @@ create or replace package body ut_annotation_manager as
5454
function get_annotation_objs_info(a_object_owner varchar2, a_object_type varchar2, a_parse_date timestamp := null) return ut_annotation_objs_cache_info is
5555
l_rows sys_refcursor;
5656
l_ut_owner varchar2(250) := ut_utils.ut_owner;
57-
l_objects_view varchar2(200) := ut_metadata.get_dba_view('dba_objects');
57+
l_objects_view varchar2(200) := ut_metadata.get_objects_view_name();
5858
l_cursor_text varchar2(32767);
5959
l_result ut_annotation_objs_cache_info;
6060
begin
@@ -86,7 +86,7 @@ create or replace package body ut_annotation_manager as
8686

8787
function get_sources_to_annotate(a_object_owner varchar2, a_object_type varchar2) return sys_refcursor is
8888
l_result sys_refcursor;
89-
l_sources_view varchar2(200) := ut_metadata.get_dba_view('dba_source');
89+
l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
9090
begin
9191
open l_result for
9292
q'[select s.name, s.text
@@ -109,7 +109,7 @@ create or replace package body ut_annotation_manager as
109109

110110
function get_sources_to_annotate(a_object_owner varchar2, a_object_type varchar2, a_objects_to_refresh ut_annotation_objs_cache_info) return sys_refcursor is
111111
l_result sys_refcursor;
112-
l_sources_view varchar2(200) := ut_metadata.get_dba_view('dba_source');
112+
l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
113113
l_card natural;
114114
begin
115115
l_card := ut_utils.scale_cardinality(cardinality(a_objects_to_refresh));

source/core/coverage/ut_coverage.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ create or replace package body ut_coverage is
3838
function get_cov_sources_sql(a_coverage_options ut_coverage_options) return varchar2 is
3939
l_result varchar2(32767);
4040
l_full_name varchar2(100);
41-
l_view_name varchar2(200) := ut_metadata.get_dba_view('dba_source');
41+
l_view_name varchar2(200) := ut_metadata.get_source_view_name();
4242
begin
4343
if a_coverage_options.file_mappings is not null and a_coverage_options.file_mappings.count > 0 then
4444
l_full_name := 'f.file_name';

source/core/ut_metadata.pkb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ create or replace package body ut_metadata as
6666
l_schema varchar2(200);
6767
l_package_name varchar2(200);
6868
l_procedure_name varchar2(200);
69-
l_view_name varchar2(200) := get_dba_view('dba_objects');
69+
l_view_name varchar2(200) := get_objects_view_name;
7070
begin
7171

7272
l_schema := a_owner_name;
@@ -116,7 +116,7 @@ create or replace package body ut_metadata as
116116
end;
117117

118118
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2 is
119-
l_view_name varchar2(128) := get_dba_view('dba_source');
119+
l_view_name varchar2(128) := get_source_view_name();
120120
l_line all_source.text%type;
121121
c_key constant varchar2(500) := a_owner || '.' || a_object_name;
122122
begin
@@ -155,6 +155,17 @@ create or replace package body ut_metadata as
155155
return l_result;
156156
end;
157157

158+
function get_source_view_name return varchar2 is
159+
begin
160+
return get_dba_view('dba_source');
161+
end;
162+
163+
164+
function get_objects_view_name return varchar2 is
165+
begin
166+
return get_dba_view('dba_objects');
167+
end;
168+
158169
function user_has_execute_any_proc return boolean is
159170
l_ut_owner varchar2(250) := ut_utils.ut_owner;
160171
l_dummy varchar2(250);

source/core/ut_metadata.pks

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,21 @@ create or replace package ut_metadata authid current_user as
6464
procedure reset_source_definition_cache;
6565

6666
/**
67-
* Returns dba_... view name if it is accessible, otherwise it returns all_xxx view
67+
* Returns dba_... view name if it is accessible, otherwise it returns all_... view
6868
* @param a_dba_view_name the name of dba view requested
6969
*/
7070
function get_dba_view(a_dba_view_name varchar2) return varchar2;
7171

72+
/**
73+
* Returns dba_source if accessible otherwise returns all_source
74+
*/
75+
function get_source_view_name return varchar2;
76+
77+
/**
78+
* Returns dba_objects if accessible otherwise returns all_objects
79+
*/
80+
function get_objects_view_name return varchar2;
81+
7282
/**
7383
* Returns true if object is accessible to current user
7484
* @param a_object_name fully qualified object name (with schema name)

source/core/ut_suite_manager.pkb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,15 @@ create or replace package body ut_suite_manager is
268268
c_bulk_limit constant pls_integer := 1000;
269269
l_items_at_level t_item_levels;
270270
l_rows tt_cached_suites;
271-
l_logical_suite ut_logical_suite;
272271
l_level pls_integer;
273272
l_prev_level pls_integer;
274273
l_idx integer;
275274
begin
276275
loop
277276
fetch a_suite_data_cursor bulk collect into l_rows limit c_bulk_limit;
278-
exit when l_rows.count = 0;
279277

280278
l_idx := l_rows.first;
281-
loop
279+
while l_idx is not null loop
282280
l_level := length(l_rows(l_idx).path) - length( replace(l_rows(l_idx).path, '.') ) + 1;
283281
if l_level > 1 then
284282
if not l_items_at_level.exists(l_level) then
@@ -315,9 +313,8 @@ create or replace package body ut_suite_manager is
315313
end if;
316314
l_prev_level := l_level;
317315
l_idx := l_rows.next(l_idx);
318-
exit when l_idx is null;
319316
end loop;
320-
exit when l_rows.count < c_bulk_limit;
317+
exit when a_suite_data_cursor%NOTFOUND;
321318
end loop;
322319

323320
reverse_list_order( a_suites );
@@ -331,7 +328,7 @@ create or replace package body ut_suite_manager is
331328
function get_missing_objects(a_object_owner varchar2) return ut_varchar2_rows is
332329
l_rows sys_refcursor;
333330
l_ut_owner varchar2(250) := ut_utils.ut_owner;
334-
l_objects_view varchar2(200) := ut_metadata.get_dba_view('dba_objects');
331+
l_objects_view varchar2(200) := ut_metadata.get_objects_view_name();
335332
l_cursor_text varchar2(32767);
336333
l_result ut_varchar2_rows;
337334
begin

source/core/ut_utils.pkb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ create or replace package body ut_utils is
350350
end;
351351

352352
procedure append_to_list(a_list in out nocopy ut_varchar2_rows, a_item varchar2) is
353-
l_items ut_varchar2_rows;
354353
begin
355354
if a_item is not null then
356355
if a_list is null then

source/reporters/ut_coveralls_reporter.tpb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ create or replace type body ut_coveralls_reporter is
6161
function get_coverage_json(
6262
a_coverage_data ut_coverage.t_coverage
6363
) return ut_varchar2_rows is
64-
l_file_part varchar2(32767);
6564
l_result ut_varchar2_rows := ut_varchar2_rows();
6665
l_unit ut_coverage.t_full_name;
6766
c_coverage_header constant varchar2(30) := '{"source_files":[';

test/api/test_ut_runner.pkb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,13 @@ end;';
8181

8282
procedure keep_an_open_transaction is
8383
l_expected varchar2(300);
84-
l_output_data dbms_output.chararr;
85-
l_num_lines integer := 100000;
8684
begin
8785
--Arrange
8886
create_test_spec();
8987
create_test_body(0);
9088
l_expected := dbms_transaction.local_transaction_id(true);
9189
--Act
92-
ut3.ut.run('test_cache');
93-
dbms_output.get_lines( l_output_data, l_num_lines);
90+
ut3.ut_runner.run(ut3.ut_varchar2_list('test_cache'),null, a_perform_rollback => false);
9491
--Assert
9592
ut.expect(dbms_transaction.local_transaction_id()).to_equal(l_expected);
9693
drop_test_package();
@@ -105,7 +102,7 @@ end;';
105102
create_test_body(0);
106103
rollback;
107104
--Act
108-
ut3.ut.run('test_cache');
105+
ut3.ut_runner.run(ut3.ut_varchar2_list('test_cache'),null);
109106
dbms_output.get_lines( l_output_data, l_num_lines);
110107
--Assert
111108
ut.expect(dbms_transaction.local_transaction_id()).to_be_null();

0 commit comments

Comments
 (0)