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

Skip to content

Commit f80c7d4

Browse files
committed
Implemented shortcuts for suitepaths for current user
1 parent 0303361 commit f80c7d4

1 file changed

Lines changed: 40 additions & 3 deletions

File tree

source/core/ut_suite_manager.pkb

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ create or replace package body ut_suite_manager is
330330
else
331331
for i in 1 .. a_paths.count loop
332332
l_path := a_paths(i);
333-
if l_path is null or not (regexp_like(l_path, '^\w+(\.\w+){0,2}$') or regexp_like(l_path, '^\w+:\w+(\.\w+)*$')) then
333+
if l_path is null or not (regexp_like(l_path, '^\w+(\.\w+){0,2}$') or regexp_like(l_path, '^(\w+)?:\w+(\.\w+)*$')) then
334334
raise_application_error(ut_utils.gc_invalid_path_format, 'Invalid path format: ' || nvl(l_path, 'NULL'));
335335
end if;
336336
end loop;
@@ -347,6 +347,7 @@ create or replace package body ut_suite_manager is
347347
l_suite_path varchar2(4000);
348348
l_root_suite_name varchar2(4000);
349349
l_objects_to_run ut_suite_items;
350+
c_current_schema constant all_tables.owner%type := sys_context('USERENV','CURRENT_SCHEMA');
350351

351352
function clean_paths(a_paths ut_varchar2_list) return ut_varchar2_list is
352353
l_paths_temp ut_varchar2_list := ut_varchar2_list();
@@ -400,6 +401,18 @@ create or replace package body ut_suite_manager is
400401
end if;
401402
end skip_by_path;
402403

404+
function package_exists_in_cur_schema(p_package_name varchar2) return boolean is
405+
l_cnt number;
406+
begin
407+
select count(*)
408+
into l_cnt
409+
from all_objects t
410+
where t.object_name = upper(p_package_name)
411+
and t.object_type = 'PACKAGE'
412+
and t.owner = c_current_schema;
413+
return l_cnt > 0;
414+
end package_exists_in_cur_schema;
415+
403416
begin
404417
l_paths := clean_paths(a_paths);
405418

@@ -410,9 +423,33 @@ create or replace package body ut_suite_manager is
410423
-- to be improved later
411424
for i in 1 .. l_paths.count loop
412425
l_path := l_paths(i);
413-
l_schema := regexp_substr(l_path, '^(\w+)(\.|:|$)', 1, 1, null, 1);
414426

415-
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
427+
if regexp_like(l_path, '^(\w+)?:') then
428+
l_schema := regexp_substr(l_path, '^(\w+)?:',subexpression => 1);
429+
-- transform ":path1[.path2]" to "schema:path1[.path2]"
430+
if l_schema is not null then
431+
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
432+
else
433+
l_path := c_current_schema || l_path;
434+
l_schema := c_current_schema;
435+
end if;
436+
else
437+
-- When path is one of: schema or schema.package[.object] or package[.object]
438+
-- transform it back to schema[.package[.object]]
439+
begin
440+
l_schema := regexp_substr(l_path, '^\w+');
441+
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
442+
exception
443+
when sys.dbms_assert.invalid_schema_name then
444+
if package_exists_in_cur_schema(l_schema) then
445+
l_path := c_current_schema || '.' || l_path;
446+
l_schema := c_current_schema;
447+
else
448+
raise;
449+
end if;
450+
end;
451+
452+
end if;
416453

417454
l_schema_suites := get_schema_suites(upper(l_schema));
418455

0 commit comments

Comments
 (0)