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

Skip to content

Commit 2427a3a

Browse files
committed
Added additional tests
1 parent b44e879 commit 2427a3a

3 files changed

Lines changed: 114 additions & 31 deletions

File tree

source/core/ut_suite_builder.pkb

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ create or replace package body ut_suite_builder is
3838
gc_endcontext constant t_annotation_name := 'endcontext';
3939

4040
gc_placeholder constant varchar2(3) := '\\%';
41+
42+
gc_int_exception constant varchar2(1) := 'I';
43+
gc_name_exception constant varchar2(1) := 'N';
44+
gc_unk_exception constant varchar2(1) := 'U';
4145

4246
--list of annotation texts for a given annotation indexed by annotation position:
4347
--This would hold: ('some', 'other') for a single annotation name recurring in a single procedure example
@@ -192,23 +196,23 @@ create or replace package body ut_suite_builder is
192196
l_c varchar2(250);
193197
l_dblink varchar2(250);
194198
l_next_pos pls_integer;
195-
l_exception_type varchar2(50) := 'NUMBER';
199+
l_exception_type varchar2(50) := gc_int_exception;
196200
begin
197201

198202
begin
199-
--check if it is a number first
203+
--check if it is a number first
200204
dbms_utility.name_tokenize(a_exception_name, l_a, l_b, l_c, l_dblink, l_next_pos);
201205
--check if it is a predefined exception
202206
begin
203207
execute immediate 'begin null; exception when '||a_exception_name||' then null; end;';
204-
l_exception_type := 'NAMED';
208+
l_exception_type := gc_name_exception;
205209
exception
206210
when others then
207211
if dbms_utility.format_error_stack() like '%PLS-00485%' then
208212
execute immediate 'declare x positiven := -('||a_exception_name||'); begin null; end;';
209-
l_exception_type := 'NUMBER';
213+
l_exception_type := gc_int_exception;
210214
else
211-
l_exception_type := 'UNKNOWN';
215+
l_exception_type := gc_unk_exception;
212216
end if;
213217
end;
214218
exception when others then
@@ -217,31 +221,38 @@ create or replace package body ut_suite_builder is
217221
return l_exception_type;
218222
end;
219223

220-
221-
function get_exception_number (a_exception_var in varchar2) return number is
222-
l_exception_no number;
223-
l_exception_type varchar2(50);
224+
function get_exception_number (a_exception_var in varchar2) return integer is
225+
l_exc_no integer;
226+
l_exc_type varchar2(50);
227+
l_sql varchar2(32767);
228+
function remap_no_data (a_number integer) return integer is
229+
begin
230+
return case a_number when 100 then -1403 else a_number end;
231+
end;
224232
begin
225-
l_exception_type := check_exception_type(a_exception_var);
226-
if l_exception_type = 'NUMBER' then
227-
execute immediate 'declare
228-
l_exception number;
229-
begin
230-
:l_exception := '||a_exception_var||';
231-
exception
232-
when others then
233-
:l_exception := null;
234-
end;' using in out l_exception_no;
235-
236-
elsif l_exception_type = 'NAMED' then
237-
execute immediate 'begin
238-
raise '||a_exception_var||';
239-
exception
240-
when others then
241-
:l_exception := sqlcode;
242-
end;' using in out l_exception_no;
233+
l_exc_type := check_exception_type(a_exception_var);
234+
235+
if l_exc_type in (gc_int_exception,gc_name_exception) then
236+
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;
243254
end if;
244-
return l_exception_no;
255+
return remap_no_data(l_exc_no);
245256
end;
246257

247258
function is_valid_qualified_name (a_name varchar2) return boolean is

test/core/annotations/test_annot_throws_exception.pkb

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ is
1313
l_exception_spec := q'[
1414
create or replace package exc_pkg is
1515
c_e_single_exc constant number := -20200;
16+
c_e_dummy constant varchar2(10) := 'dummy';
1617
c_e_varch_exc constant varchar2(10) := '-20201';
1718
c_e_list_1 number := -20202;
1819
c_e_list_2 constant number := -20203;
@@ -97,6 +98,22 @@ is
9798
--%throws(DUP_VAL_ON_INDEX)
9899
procedure named_exc_ora_dup_ind;
99100

101+
--%test(Success map no data 100 to -1403)
102+
--%throws(-1403)
103+
procedure nodata_exc_ora;
104+
105+
--%test(Success for exception defined as varchar)
106+
--%throws(exc_pkg.c_e_varch_exc)
107+
procedure defined_varchar_exc;
108+
109+
--%test(Non existing constant exception)
110+
--%throws(dummy.c_dummy);
111+
procedure non_existing_const;
112+
113+
--%test(Bad exception constant)
114+
--%throws(exc_pkg.c_e_dummy);
115+
procedure bad_exc_const;
116+
100117
end;
101118
';
102119

@@ -187,6 +204,26 @@ is
187204
begin
188205
raise DUP_VAL_ON_INDEX;
189206
end;
207+
208+
procedure nodata_exc_ora is
209+
begin
210+
raise NO_DATA_FOUND;
211+
end;
212+
213+
procedure defined_varchar_exc is
214+
begin
215+
raise_application_error(exc_pkg.c_e_varch_exc,''Test'');
216+
end;
217+
218+
procedure non_existing_const is
219+
begin
220+
raise_application_error(-20143, ''Test error'');
221+
end;
222+
223+
procedure bad_exc_const is
224+
begin
225+
raise_application_error(-20143, ''Test error'');
226+
end;
190227

191228
end;
192229
';
@@ -302,7 +339,31 @@ is
302339
ut.expect(g_tests_results).to_match('^\s*Success resolve and match oracle named exception dup val index \[[\.0-9]+ sec\]\s*$','m');
303340
ut.expect(g_tests_results).not_to_match('named_exc_ora_dup_ind');
304341
end;
305-
342+
343+
procedure nodata_exc_ora is
344+
begin
345+
ut.expect(g_tests_results).to_match('^\s*Success map no data 100 to -1403 \[[\.0-9]+ sec\]\s*$','m');
346+
ut.expect(g_tests_results).not_to_match('nodata_exc_ora');
347+
end;
348+
349+
procedure defined_varchar_exc is
350+
begin
351+
ut.expect(g_tests_results).to_match('^\s*Success for exception defined as varchar \[[\.0-9]+ sec\]\s*$','m');
352+
ut.expect(g_tests_results).not_to_match('defined_varchar_exc');
353+
end;
354+
355+
procedure non_existing_const is
356+
begin
357+
ut.expect(g_tests_results).to_match('^\s*Non existing constant exception \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m');
358+
ut.expect(g_tests_results).to_match('non_existing_const\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"');
359+
end;
360+
361+
procedure bad_exc_const is
362+
begin
363+
ut.expect(g_tests_results).to_match('^\s*Bad exception constant \[[\.0-9]+ sec\] \(FAILED - [0-9]+\)\s*$','m');
364+
ut.expect(g_tests_results).to_match('bad_exc_const\s*ORA-20143: Test error\s*ORA-06512: at "UT3_TESTER.ANNOTATED_PACKAGE_WITH_THROWS"');
365+
end;
366+
306367
procedure drop_test_package is
307368
pragma autonomous_transaction;
308369
begin

test/core/annotations/test_annot_throws_exception.pks

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,24 @@ is
5151
--%test(Success resolve and match named exception defined in pragma exception init)
5252
procedure named_exc_pragma;
5353

54-
--%test(Success resolve and match oracle named exception)
55-
--%disabled
54+
--%test(Success resolve and match oracle named exception no data)
5655
procedure named_exc_ora;
5756

5857
--%test(Success resolve and match oracle named exception dup val index)
5958
procedure named_exc_ora_dup_ind;
6059

60+
--%test(Success map no data 100 to -1403)
61+
procedure nodata_exc_ora;
62+
63+
--%test(Success for exception defined as varchar)
64+
procedure defined_varchar_exc;
65+
66+
--%test(Non existing constant exception)
67+
procedure non_existing_const;
68+
69+
--%test(Bad exception constant)
70+
procedure bad_exc_const;
71+
6172
--%afterall
6273
procedure drop_test_package;
6374

0 commit comments

Comments
 (0)