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

Skip to content

Commit c7e7eb2

Browse files
committed
Refactored code.
1 parent f4b1692 commit c7e7eb2

2 files changed

Lines changed: 56 additions & 67 deletions

File tree

source/core/ut_suite_builder.pkb

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ create or replace package body ut_suite_builder is
3939

4040
gc_placeholder constant varchar2(3) := '\\%';
4141

42-
gc_int_exception constant varchar2(1) := 'I';
43-
gc_name_exception constant varchar2(1) := 'N';
44-
gc_unk_exception constant varchar2(1) := 'U';
42+
gc_integer_exception constant varchar2(1) := 'I';
43+
gc_named_exception constant varchar2(1) := 'N';
4544

4645
--list of annotation texts for a given annotation indexed by annotation position:
4746
--This would hold: ('some', 'other') for a single annotation name recurring in a single procedure example
@@ -160,7 +159,7 @@ create or replace package body ut_suite_builder is
160159
-- Processing annotations
161160
-----------------------------------------------
162161

163-
procedure add_annotation_warning(
162+
procedure add_annotation_ignored_warning(
164163
a_suite in out nocopy ut_suite_item,
165164
a_annotation t_annotation_name,
166165
a_message varchar2,
@@ -191,32 +190,25 @@ create or replace package body ut_suite_builder is
191190
end;
192191

193192
function check_exception_type(a_exception_name in varchar2) return varchar2 is
194-
l_a varchar2(250);
195-
l_b varchar2(250);
196-
l_c varchar2(250);
197-
l_dblink varchar2(250);
198-
l_next_pos pls_integer;
199-
l_exception_type varchar2(50) := gc_int_exception;
193+
l_exception_type varchar2(50);
200194
begin
201-
195+
--check if it is a predefined exception
202196
begin
203-
--check if it is a number first
204-
dbms_utility.name_tokenize(a_exception_name, l_a, l_b, l_c, l_dblink, l_next_pos);
205-
--check if it is a predefined exception
206-
begin
207-
execute immediate 'begin null; exception when '||a_exception_name||' then null; end;';
208-
l_exception_type := gc_name_exception;
209-
exception
210-
when others then
211-
if dbms_utility.format_error_stack() like '%PLS-00485%' then
197+
execute immediate 'begin null; exception when '||a_exception_name||' then null; end;';
198+
l_exception_type := gc_named_exception;
199+
exception
200+
when others then
201+
if dbms_utility.format_error_stack() like '%PLS-00485%' then
202+
begin
212203
execute immediate 'declare x positiven := -('||a_exception_name||'); begin null; end;';
213-
l_exception_type := gc_int_exception;
214-
else
215-
l_exception_type := gc_unk_exception;
216-
end if;
217-
end;
218-
exception when others then
219-
null;
204+
l_exception_type := gc_integer_exception;
205+
exception
206+
when others then
207+
--invalid exception number (positive)
208+
--TODO add warning for this value
209+
null;
210+
end;
211+
end if;
220212
end;
221213
return l_exception_type;
222214
end;
@@ -225,34 +217,34 @@ create or replace package body ut_suite_builder is
225217
l_exc_no integer;
226218
l_exc_type varchar2(50);
227219
l_sql varchar2(32767);
228-
function remap_no_data (a_number integer) return integer is
220+
function remap_no_data_found (a_number integer) return integer is
229221
begin
230222
return case a_number when 100 then -1403 else a_number end;
231223
end;
232224
begin
233225
l_exc_type := check_exception_type(a_exception_var);
234226

235-
if l_exc_type in (gc_int_exception,gc_name_exception) then
227+
if l_exc_type is not null then
236228

237-
execute immediate case l_exc_type
238-
when gc_int_exception then
239-
'declare
240-
l_exception number;
241-
begin
242-
:l_exception := '||a_exception_var||'; '
243-
when gc_name_exception then
244-
'begin
245-
raise '||a_exception_var||'; '
246-
end ||
247-
'exception
248-
when others then
249-
:l_exception := '|| case l_exc_type
250-
when gc_int_exception then 'null;'
251-
when gc_name_exception then 'sqlcode;'
252-
end||'
253-
end;' using in out l_exc_no;
229+
execute immediate
230+
case l_exc_type
231+
when gc_integer_exception then
232+
'declare
233+
l_exception number;
234+
begin
235+
:l_exception := '||a_exception_var||'; '
236+
when gc_named_exception then
237+
'begin
238+
raise '||a_exception_var||';
239+
exception
240+
when others then
241+
:l_exception := sqlcode; '
242+
end ||
243+
'end;'
244+
using out l_exc_no;
245+
254246
end if;
255-
return remap_no_data(l_exc_no);
247+
return remap_no_data_found(l_exc_no);
256248
end;
257249

258250
function is_valid_qualified_name (a_name varchar2) return boolean is
@@ -265,27 +257,24 @@ create or replace package body ut_suite_builder is
265257
end;
266258

267259
function build_exception_numbers_list(a_annotation_text in varchar2) return ut_integer_list is
268-
l_throws_list ut_varchar2_list;
269-
l_exception_number_list ut_integer_list := ut_integer_list();
270-
l_regexp_for_excep_nums varchar2(30) := '^-?[[:digit:]]{1,5}$';
260+
l_throws_list ut_varchar2_list;
261+
l_exception_number_list ut_integer_list := ut_integer_list();
262+
l_regexp_for_exception_no varchar2(30) := '^-?[[:digit:]]{1,5}$';
271263
begin
272264
/*the a_expected_error_codes is converted to a ut_varchar2_list after that is trimmed and filtered to left only valid exception numbers*/
273265
l_throws_list := ut_utils.trim_list_elements(ut_utils.string_to_table(a_annotation_text, ',', 'Y'));
274266

275-
for i in 1..l_throws_list.count
267+
for i in 1 .. l_throws_list.count
276268
loop
277269
/**
278-
* First check if its a valid qualified name and if so try to resolve to number
279-
* If not check if it matches the ora regex number pattern.
270+
* Check if its a valid qualified name and if so try to resolve name to an exception number
280271
*/
281272
if is_valid_qualified_name(l_throws_list(i)) then
282273
l_throws_list(i) := get_exception_number(l_throws_list(i));
283-
else
284-
l_throws_list(i) := l_throws_list(i);
285274
end if;
286275
end loop;
287276

288-
l_throws_list := ut_utils.filter_list( ut_utils.trim_list_elements(l_throws_list), l_regexp_for_excep_nums);
277+
l_throws_list := ut_utils.filter_list( ut_utils.trim_list_elements(l_throws_list), l_regexp_for_exception_no);
289278

290279
l_exception_number_list.extend(l_throws_list.count);
291280
for i in 1 .. l_throws_list.count loop
@@ -352,7 +341,7 @@ create or replace package body ut_suite_builder is
352341
--start from second occurrence of annotation
353342
l_line_no := a_annotations(a_for_annotation).next( a_annotations(a_for_annotation).first );
354343
while l_line_no is not null loop
355-
add_annotation_warning( a_suite, a_for_annotation, 'Duplicate annotation %%%.', l_line_no );
344+
add_annotation_ignored_warning( a_suite, a_for_annotation, 'Duplicate annotation %%%.', l_line_no );
356345
l_line_no := a_annotations(a_for_annotation).next( l_line_no );
357346
end loop;
358347
end if;
@@ -373,7 +362,7 @@ create or replace package body ut_suite_builder is
373362
--start from second occurrence of annotation
374363
l_line_no := a_annotations(a_for_annotation).next( a_annotations(a_for_annotation).first );
375364
while l_line_no is not null loop
376-
add_annotation_warning( a_suite, a_for_annotation, 'Duplicate annotation %%%.', l_line_no, a_procedure_name );
365+
add_annotation_ignored_warning( a_suite, a_for_annotation, 'Duplicate annotation %%%.', l_line_no, a_procedure_name );
377366
l_line_no := a_annotations(a_for_annotation).next( l_line_no );
378367
end loop;
379368
end if;
@@ -396,7 +385,7 @@ create or replace package body ut_suite_builder is
396385
if l_annotation_name member of a_invalid_annotations then
397386
l_line_no := a_proc_annotations(l_annotation_name).first;
398387
while l_line_no is not null loop
399-
add_annotation_warning(
388+
add_annotation_ignored_warning(
400389
a_suite, l_annotation_name, 'Annotation %%% cannot be used with "--%'|| a_for_annotation || '".',
401390
l_line_no, a_procedure_name
402391
);
@@ -432,7 +421,7 @@ create or replace package body ut_suite_builder is
432421
l_annotation_texts := a_annotations(gc_rollback);
433422
l_test.rollback_type := get_rollback_type(l_annotation_texts(l_annotation_texts.first));
434423
if l_test.rollback_type is null then
435-
add_annotation_warning(
424+
add_annotation_ignored_warning(
436425
a_suite, gc_rollback, 'Annotation %%% must be provided with one of values: "auto" or "manual".',
437426
l_annotation_texts.first, a_procedure_name
438427
);
@@ -569,13 +558,13 @@ create or replace package body ut_suite_builder is
569558
if regexp_like(l_annotation_text,'^((\w|[$#])+\.)*(\w|[$#])+$') then
570559
a_suite.path := l_annotation_text||'.'||l_object_name;
571560
else
572-
add_annotation_warning(
561+
add_annotation_ignored_warning(
573562
a_suite, gc_suitepath||'('||l_annotation_text||')',
574563
'Invalid path value in annotation %%%.', a_package_ann_index(gc_suitepath).first
575564
);
576565
end if;
577566
else
578-
add_annotation_warning(
567+
add_annotation_ignored_warning(
579568
a_suite, gc_suitepath, '%%% annotation requires a non-empty parameter value.',
580569
a_package_ann_index(gc_suitepath).first
581570
);
@@ -589,7 +578,7 @@ create or replace package body ut_suite_builder is
589578
if l_annotation_text is not null then
590579
a_suite.description := l_annotation_text;
591580
else
592-
add_annotation_warning(
581+
add_annotation_ignored_warning(
593582
a_suite, gc_displayname, '%%% annotation requires a non-empty parameter value.',
594583
a_package_ann_index(gc_displayname).first
595584
);
@@ -600,7 +589,7 @@ create or replace package body ut_suite_builder is
600589
if a_package_ann_index.exists(gc_rollback) then
601590
l_rollback_type := get_rollback_type(a_annotations(a_package_ann_index(gc_rollback).first).text);
602591
if l_rollback_type is null then
603-
add_annotation_warning(
592+
add_annotation_ignored_warning(
604593
a_suite, gc_rollback, '%%% annotation requires one of values as parameter: "auto" or "manual".',
605594
a_package_ann_index(gc_rollback).first
606595
);
@@ -712,7 +701,7 @@ create or replace package body ut_suite_builder is
712701
if a_package_ann_index.exists(gc_context) then
713702
l_annotation_pos := a_package_ann_index(gc_context).first;
714703
while l_annotation_pos is not null loop
715-
add_annotation_warning(
704+
add_annotation_ignored_warning(
716705
a_suite, gc_context, 'Invalid annotation %%%. Cannot find following "--%endcontext".',
717706
l_annotation_pos
718707
);
@@ -722,7 +711,7 @@ create or replace package body ut_suite_builder is
722711
if a_package_ann_index.exists(gc_endcontext) then
723712
l_annotation_pos := a_package_ann_index(gc_endcontext).first;
724713
while l_annotation_pos is not null loop
725-
add_annotation_warning(
714+
add_annotation_ignored_warning(
726715
a_suite, gc_endcontext, 'Invalid annotation %%%. Cannot find preceding "--%context".',
727716
l_annotation_pos
728717
);

source/core/ut_utils.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ procedure append_to_clob(a_src_clob in out nocopy clob, a_clob_table t_clob_tab,
525525
return l_trimmed_list;
526526
end;
527527

528-
function filter_list(a_list IN ut_varchar2_list, a_regexp_filter in varchar2) return ut_varchar2_list is
528+
function filter_list(a_list in ut_varchar2_list, a_regexp_filter in varchar2) return ut_varchar2_list is
529529
l_filtered_list ut_varchar2_list;
530530
l_index integer;
531531
begin

0 commit comments

Comments
 (0)