Skip to content

Commit 83dbdaa

Browse files
committed
Updating documentation.
Adding get_suites_info override.
1 parent 95ddec1 commit 83dbdaa

8 files changed

Lines changed: 122 additions & 64 deletions

File tree

docs/userguide/querying_suites.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ To get a full information about suite `TEST_STUFF` including suite description,
3939
select * from table(ut_runner.get_suites_info(USER, 'TEST_STUFF')) where item_type = 'UT_TEST';
4040
```
4141

42+
To get a full information about suites that have a path like `ut3:tests.test_package_*` including suite description, all contexts and tests in a suite
43+
```sql
44+
select * from table(ut_runner.get_suites_info('ut3:tests.test_package_*') where item_type = 'UT_TEST';
45+
```
46+
47+
To get a full information about suites that have object name like `test_package_*` including suite description, all contexts and tests in a suite
48+
```sql
49+
select * from table(ut_runner.get_suites_info('test_package_*'));
50+
```
51+
4252
## Checking if schema contains tests
4353

4454
Function `ut_runner.has_suites(a_owner)` returns boolean value indicating if given schema contains test suites.

docs/userguide/running-unit-tests.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ The **functions** can only be used in SELECT statements. They execute the specif
4545
## ut.run procedures
4646

4747
The examples below illustrate different ways and options to invoke `ut.run` procedures.
48+
As part of the syntax you can use a wildcard character `*` to call test by part of his name or to call few tests that match a call.
49+
Schema name is still mandatory and cannot contain a wildcard character whether is a suitepath or object.
50+
51+
4852

4953
```sql
5054
alter session set current_schema=hr;
@@ -75,6 +79,14 @@ end;
7579
Executes all tests from all packages that are on the _com.my_org.my_project_ suitepath.
7680
Check the [annotations documentation](annotations.md) to find out about suitepaths and how they can be used to organize test packages for your project.
7781

82+
```sql
83+
set serveroutput on
84+
begin
85+
ut.run('hr:com*');
86+
end;
87+
```
88+
89+
Executes all tests from all packages that are on suitepath starting with _com_.
7890

7991
```sql
8092
set serveroutput on
@@ -124,6 +136,22 @@ Using a list of items to execute allows you to execute a fine-grained set of tes
124136

125137
List can be passed as a comma separated list or a list of *ut_varchar2_list objects* or as a list within ut_varchar2_list.
126138

139+
```sql
140+
set serveroutput on
141+
begin
142+
ut.run('hr.test*');
143+
end;
144+
```
145+
Executes all tests from schema _hr_ starting with name _test_.
146+
147+
```sql
148+
set serveroutput on
149+
begin
150+
ut.run('hr.test_apply_bonus.bonus_*');
151+
end;
152+
```
153+
Executes all test procedures from package _hr.test_apply_bonus_ that starting with _bonus_.
154+
127155

128156
**Note:**
129157

source/api/ut_runner.pkb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,31 @@ create or replace package body ut_runner is
172172
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
173173
end;
174174

175-
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined is
175+
function get_suites_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined is
176176
l_cursor sys_refcursor;
177177
l_results ut_suite_items_info;
178178
c_bulk_limit constant integer := 100;
179+
l_path varchar2(4000) := nvl(a_owner,sys_context('userenv', 'current_schema'))||'.'||nvl(a_package_name,'*');
179180
begin
180-
l_cursor := ut_suite_manager.get_suites_info( nvl(a_owner,sys_context('userenv', 'current_schema')), a_package_name );
181+
182+
l_cursor := ut_suite_manager.get_suites_info(ut_varchar2_list(l_path));
183+
loop
184+
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
185+
for i in 1 .. l_results.count loop
186+
pipe row (l_results(i));
187+
end loop;
188+
exit when l_cursor%notfound;
189+
end loop;
190+
close l_cursor;
191+
return;
192+
end;
193+
194+
function get_suites_info(a_path varchar2 := null) return ut_suite_items_info pipelined is
195+
l_cursor sys_refcursor;
196+
l_results ut_suite_items_info;
197+
c_bulk_limit constant integer := 100;
198+
begin
199+
l_cursor := ut_suite_manager.get_suites_info(ut_varchar2_list(nvl(a_path,sys_context('userenv', 'current_schema'))));
181200
loop
182201
fetch l_cursor bulk collect into l_results limit c_bulk_limit;
183202
for i in 1 .. l_results.count loop

source/api/ut_runner.pks

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ create or replace package ut_runner authid current_user is
104104
* @param a_package_name name of unit test package to retrieve (optional), if NULL all unit test packages are returned
105105
* @return ut_suite_items_info table of objects
106106
*/
107-
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined;
107+
function get_suites_info(a_owner varchar2, a_package_name varchar2) return ut_suite_items_info pipelined;
108+
109+
/**
110+
* Returns a pipelined collection containing information about unit test suites and the tests contained in them
111+
*
112+
* @param a_path a path from which we lookg for object or suite
113+
*/
114+
function get_suites_info(a_path varchar2 := null) return ut_suite_items_info pipelined;
108115

109116

110117
/**

source/core/ut_suite_cache_manager.pkb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,20 @@ create or replace package body ut_suite_cache_manager is
148148

149149
return l_results;
150150
end;
151-
151+
/*
152+
The object name is populate but suitepath not
153+
We will use that object and try to match.
154+
We can pass also a wildcard this will result in one to many.
155+
156+
Get all data that do not have an wildcard and not require expanding.
157+
We will take them as they are.
158+
a)suite path is populated
159+
b)suite path and object is empty so schema name is by default ( or passed)
160+
*/
152161
function expand_paths(a_schema_paths ut_path_items) return ut_path_items is
153162
l_schema_paths ut_path_items:= ut_path_items();
154163
begin
155-
with paths_to_expand as (
156-
/*
157-
The object name is populate but suitepath not
158-
We will use that object and try to match.
159-
We can pass also a wildcard this will result in one to many.
160-
*/
164+
with paths_to_expand as (
161165
select /*+ no_parallel */ min(path) as suite_path,sp.schema_name as schema_name,nvl(c.object_name,sp.object_name) as object_name,
162166
nvl2(sp.procedure_name,c.name,null) as procedure_name
163167
from table(a_schema_paths) sp left outer join ut_suite_cache c
@@ -174,12 +178,6 @@ create or replace package body ut_suite_cache_manager is
174178
and c.path like replace(sp.suite_path,'*','%'))
175179
where sp.suite_path is not null and instr(sp.suite_path,'*') > 0
176180
union all
177-
/*
178-
Get all data that do not have an wildcard and not require expanding.
179-
We will take them as they are.
180-
a)suite path is populated
181-
b)suite path and object is empty so schema name is by default ( or passed)
182-
*/
183181
select /*+ no_parallel */ sp.suite_path as suite_path,sp.schema_name,sp.object_name,sp.procedure_name as procedure_name
184182
from table(a_schema_paths) sp
185183
where
@@ -205,7 +203,6 @@ create or replace package body ut_suite_cache_manager is
205203
Were the path is populated we need to make sure we dont return duplicates
206204
as the wildcard can produce multiple results from same path and
207205
parents and child for each can be same resulting in duplicates
208-
TODO: Verify that this not duplicate with a expand paths.
209206
*/
210207
function get_suite_items (
211208
a_schema_paths ut_path_items
@@ -484,22 +481,25 @@ create or replace package body ut_suite_cache_manager is
484481
end;
485482

486483
function get_cached_suite_info(
487-
a_object_owner varchar2,
488-
a_object_name varchar2
484+
a_schema_paths ut_path_items
485+
) return ut_suite_cache_rows is
486+
begin
487+
return get_cached_suite_rows( a_schema_paths );
488+
end;
489+
490+
function get_suite_items_info(
491+
a_suite_cache_items ut_suite_cache_rows
489492
) return ut_suite_items_info is
490-
l_cache_rows ut_suite_cache_rows;
491493
l_results ut_suite_items_info;
492494
begin
493-
l_cache_rows := get_cached_suite_rows( a_object_owner => a_object_owner, a_object_name =>a_object_name );
494495
select /*+ no_parallel */ ut_suite_item_info(
495496
c.object_owner, c.object_name, c.name,
496497
c.description, c.self_type, c.line_no,
497498
c.path, c.disabled_flag, c.disabled_reason, c.tags
498499
)
499500
bulk collect into l_results
500-
from table(l_cache_rows) c;
501-
502-
return l_results;
501+
from table(a_suite_cache_items) c;
502+
return l_results;
503503
end;
504504

505505
function get_cached_packages(

source/core/ut_suite_cache_manager.pks

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ create or replace package ut_suite_cache_manager authid definer is
6868
* Not to be used publicly. Used internally for building suites info.
6969
*/
7070
function get_cached_suite_info(
71-
a_object_owner varchar2,
72-
a_object_name varchar2
71+
a_schema_paths ut_path_items
72+
) return ut_suite_cache_rows;
73+
74+
function get_suite_items_info(
75+
a_suite_cache_items ut_suite_cache_rows
7376
) return ut_suite_items_info;
74-
77+
7578
/*
7679
* Retrieves list of cached suite packages.
7780
* Returned data is not filtered by user access rights.

source/core/ut_suite_manager.pkb

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,6 @@ create or replace package body ut_suite_manager is
533533
l_schema_paths ut_path_items;
534534
l_reconcile_paths ut_path_items;
535535
l_schema varchar2(4000);
536-
l_suites_count pls_integer := 0;
537-
l_index varchar2(4000 char);
538536
begin
539537
ut_event_manager.trigger_event('configure_execution_by_path - start');
540538
a_suites := ut_suite_items();
@@ -567,37 +565,34 @@ create or replace package body ut_suite_manager is
567565
end configure_execution_by_path;
568566

569567
function get_suites_info(
570-
a_owner_name varchar2,
571-
a_package_name varchar2 := null
568+
a_paths ut_varchar2_list
572569
) return sys_refcursor is
573-
l_result sys_refcursor;
574-
l_all_suite_info ut_suite_items_info;
575-
l_owner_name varchar2(250) := ut_utils.qualified_sql_name(a_owner_name);
576-
l_package_name varchar2(250) := ut_utils.qualified_sql_name(a_package_name);
570+
l_result sys_refcursor;
571+
l_all_suite_info ut_suite_items_info;
572+
l_schema_names ut_varchar2_rows;
573+
l_schema_paths ut_path_items;
574+
l_paths ut_varchar2_list := a_paths;
575+
l_schema varchar2(4000);
576+
l_unfiltered_rows ut_suite_cache_rows;
577+
l_filtered_rows ut_suite_cache_rows;
578+
577579
begin
580+
l_schema_names := resolve_schema_names(l_paths);
581+
--refresh cache
582+
l_schema := l_schema_names.first;
583+
while l_schema is not null loop
584+
refresh_cache(upper(l_schema_names(l_schema)));
585+
l_schema := l_schema_names.next(l_schema);
586+
end loop;
587+
l_schema_paths := ut_suite_cache_manager.get_schema_paths(l_paths);
588+
l_unfiltered_rows := ut_suite_cache_manager.get_cached_suite_info(l_schema_paths);
589+
l_filtered_rows := get_filtered_cursor(l_unfiltered_rows);
590+
l_all_suite_info := ut_suite_cache_manager.get_suite_items_info(l_filtered_rows);
591+
open l_result for
592+
select /*+ no_parallel */ value(c)
593+
from table(l_all_suite_info) c
594+
order by c.object_owner, c.object_name, c.item_line_no;
578595

579-
refresh_cache(l_owner_name);
580-
581-
l_all_suite_info := ut_suite_cache_manager.get_cached_suite_info( l_owner_name, l_package_name );
582-
if can_skip_all_objects_scan( l_owner_name ) then
583-
open l_result for
584-
select /*+ no_parallel */ value(c)
585-
from table(l_all_suite_info) c
586-
order by c.object_owner, c.object_name, c.item_line_no;
587-
else
588-
open l_result for
589-
select /*+ no_parallel */ value(c)
590-
from table(l_all_suite_info) c
591-
where exists
592-
( select 1
593-
from all_objects a
594-
where a.object_name = c.object_name
595-
and a.owner = c.object_owner
596-
and a.object_type = 'PACKAGE'
597-
)
598-
or c.item_type = 'UT_LOGICAL_SUITE'
599-
order by c.object_owner, c.object_name, c.item_line_no;
600-
end if;
601596
return l_result;
602597
end;
603598

source/core/ut_suite_manager.pks

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,11 @@ create or replace package ut_suite_manager authid current_user is
7979
/**
8080
* Returns a ref cursor containing information about unit test suites and the tests contained in them
8181
*
82-
* @param a_owner owner of unit tests to retrieve
83-
* @param a_package_name name of test package (optional)
84-
* @param a_procedure_name name of test procedure (optional)
85-
* @return ut_suite_items_info table of objects
82+
* @param a_paths list of paths to be resolved and return a suites.
8683
*/
8784
function get_suites_info(
88-
a_owner_name varchar2,
89-
a_package_name varchar2 := null
90-
) return sys_refcursor;
85+
a_paths ut_varchar2_list
86+
) return sys_refcursor;
9187

9288
/**
9389
* Returns true if given suite item exists

0 commit comments

Comments
 (0)