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

Skip to content

Commit 23d3b86

Browse files
committed
Added tests to cover invalid specs scenarios
1 parent 9923d28 commit 23d3b86

4 files changed

Lines changed: 147 additions & 5 deletions

File tree

test/api/test_ut_run.pkb

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,107 @@ Failures:%
114114
execute immediate 'drop package test_stateful';
115115
end;
116116

117+
procedure run_in_invalid_state is
118+
l_results ut3.ut_varchar2_list;
119+
l_actual clob;
120+
l_expected varchar2(32767);
121+
begin
122+
select *
123+
bulk collect into l_results
124+
from table(ut3.ut.run('failing_invalid_spec'));
125+
126+
l_actual := ut3.ut_utils.table_to_clob(l_results);
127+
ut.expect(l_actual).to_be_like('%Call params for % are not valid: package does not exist or is invalid: %FAILING_INVALID_SPEC%');
128+
129+
end;
130+
131+
procedure compile_invalid_package is
132+
ex_compilation_error exception;
133+
pragma exception_init(ex_compilation_error,-24344);
134+
pragma autonomous_transaction;
135+
begin
136+
begin
137+
execute immediate q'[create or replace package failing_invalid_spec as
138+
--%suite
139+
gv_glob_val non_existing_table.id%type := 0;
140+
141+
--%test
142+
procedure test1;
143+
end;]';
144+
exception when ex_compilation_error then null;
145+
end;
146+
begin
147+
execute immediate q'[create or replace package body failing_invalid_spec as
148+
procedure test1 is begin ut.expect(1).to_equal(1); end;
149+
end;]';
150+
exception when ex_compilation_error then null;
151+
end;
152+
end;
153+
procedure drop_invalid_package is
154+
pragma autonomous_transaction;
155+
begin
156+
execute immediate 'drop package failing_invalid_spec';
157+
end;
158+
159+
procedure run_and_revalidate_specs is
160+
l_results ut3.ut_varchar2_list;
161+
l_actual clob;
162+
l_is_invalid number;
163+
begin
164+
execute immediate q'[select count(1) from all_objects o where o.owner = :object_owner and o.object_type = 'PACKAGE'
165+
and o.status = 'INVALID' and o.object_name= :object_name]' into l_is_invalid
166+
using user,'FAILING_INVALID_SPEC';
167+
168+
select *
169+
bulk collect into l_results
170+
from table(ut3.ut.run('failing_invalid_spec'));
171+
172+
l_actual := ut3.ut_utils.table_to_clob(l_results);
173+
ut.expect(1).to_equal(l_is_invalid);
174+
ut.expect(l_actual).to_be_like('%failing_invalid_spec%invalidspecs [% sec]%
175+
%Finished in % seconds%
176+
%1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%');
177+
178+
end;
179+
180+
procedure generate_invalid_spec is
181+
ex_compilation_error exception;
182+
pragma exception_init(ex_compilation_error,-24344);
183+
pragma autonomous_transaction;
184+
begin
185+
186+
execute immediate q'[create or replace package parent_specs as
187+
c_test constant varchar2(1) := 'Y';
188+
end;]';
189+
190+
execute immediate q'[create or replace package failing_invalid_spec as
191+
--%suite
192+
g_var varchar2(1) := parent_specs.c_test;
193+
194+
--%test(invalidspecs)
195+
procedure test1;
196+
end;]';
197+
198+
execute immediate q'[create or replace package body failing_invalid_spec as
199+
procedure test1 is begin ut.expect('Y').to_equal(g_var); end;
200+
end;]';
201+
202+
-- That should invalidate test package and we can then revers
203+
execute immediate q'[create or replace package parent_specs as
204+
c_test_error constant varchar2(1) := 'Y';
205+
end;]';
206+
207+
execute immediate q'[create or replace package parent_specs as
208+
c_test constant varchar2(1) := 'Y';
209+
end;]';
210+
211+
end;
212+
procedure drop_test_package is
213+
pragma autonomous_transaction;
214+
begin
215+
execute immediate 'drop package failing_invalid_spec';
216+
execute immediate 'drop package parent_specs';
217+
end;
218+
117219
end;
118220
/

test/api/test_ut_run.pks

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,20 @@ create or replace package test_ut_run is
88
--%beforetest(create_test_suite)
99
--%aftertest(drop_test_suite)
1010
procedure raise_in_invalid_state;
11+
12+
--%test(ut.run - run invalid package and fail expectation)
13+
--%beforetest(compile_invalid_package)
14+
--%aftertest(drop_invalid_package)
15+
procedure run_in_invalid_state;
16+
procedure compile_invalid_package;
17+
procedure drop_invalid_package;
18+
19+
--%test( Invalidate package specs via rebuild but still execute package)
20+
--%beforetest(generate_invalid_spec)
21+
--%aftertest(drop_test_package)
22+
procedure run_and_revalidate_specs;
23+
procedure generate_invalid_spec;
24+
procedure drop_test_package;
25+
1126
end;
1227
/

test/core/test_suite_manager.pkb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,9 @@ end test_package_3;]';
872872
l_objects_to_run ut3.ut_suite_items;
873873
begin
874874
l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list('failing_invalid_spec'));
875-
ut.fail('Invalid package didnt raised exception');
876-
exception
877-
when others then
878-
ut.expect(sqlerrm).to_be_like('%failing_invalid_spec%');
875+
876+
ut3.ut.expect(l_objects_to_run.count).to_be_greater_than(0);
877+
ut3.ut.expect(l_objects_to_run(l_objects_to_run.first).object_name).to_equal('failing_invalid_spec');
879878
end;
880879

881880
procedure compile_invalid_package is
@@ -912,6 +911,26 @@ end;]';
912911
execute immediate 'drop package failing_invalid_spec';
913912
end;
914913

914+
procedure test_search_nonexisting_pck is
915+
l_objects_to_run ut3.ut_suite_items;
916+
begin
917+
l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list('ut3.failing_non_existing'));
918+
ut.fail('Non existing package didnt raised exception');
919+
exception
920+
when others then
921+
ut.expect(sqlerrm).to_be_like('%failing_non_existing%');
922+
end;
923+
924+
procedure test_search_nonexist_sch_pck is
925+
l_objects_to_run ut3.ut_suite_items;
926+
begin
927+
l_objects_to_run := ut3.ut_suite_manager.configure_execution_by_path(ut3.ut_varchar2_list('failing_non_existing'));
928+
ut.fail('Non existing package without schema didnt raised exception');
929+
exception
930+
when others then
931+
ut.expect(sqlerrm).to_be_like('%ORA-44001: invalid schema%');
932+
end;
933+
915934
procedure test_desc_with_comma is
916935
l_objects_to_run ut3.ut_suite_items;
917936
l_suite ut3.ut_suite;

test/core/test_suite_manager.pks

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ create or replace package test_suite_manager is
6565
--%test(Prepare runner for the suites package by path for current user)
6666
procedure test_top_subpck_by_path_cu;
6767

68-
--%test(Prepare runner for invalid package)
68+
--%test(Prepare runner for invalid package - it will add to suite but fail on exec )
6969
--%beforetest(compile_invalid_package)
7070
--%aftertest(drop_invalid_package)
7171
procedure test_search_invalid_pck;
7272
procedure compile_invalid_package;
7373
procedure drop_invalid_package;
74+
75+
--%test(Prepare runner for nonexisting package with schema)
76+
procedure test_search_nonexisting_pck;
77+
78+
--%test(Prepare runner for nonexisting package without schema)
79+
procedure test_search_nonexist_sch_pck;
7480

7581
--%test(Test description with comma)
7682
--%beforetest(setup_desc_with_comma)

0 commit comments

Comments
 (0)