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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Splitting skipped framework objects and excluded objects into separat…
…e table types.

Update docs.
  • Loading branch information
lwasylow committed Feb 25, 2022
commit e7d59b4b3eea36cea8fbbaeb7640b1f82ec8ba7b
32 changes: 28 additions & 4 deletions docs/userguide/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,34 @@ exec ut.run('unit_test_schema', ut_coverage_html_reporter(), a_coverage_schemes
There are six options that can be used to narrow down the scope of coverage report:
- `a_include_objects` - list of `[object_owner.].object_name` to be included in the coverage report.
- `a_exclude_objects` - list of `[object_owner.].object_name` to be excluded from the coverage report
- `a_include_schema_expr` - string of regex expression of schemas to be included in the coverage report. It will override `a_include_objects`
- `a_include_object_expr` - string of regex expression of objects ( no schema names included ) to be included in the coverage report. It will override `a_include_objects`
- `a_exclude_schema_expr` - string of regex expression of schemas to be excluded from the coverage report. It will override `a_exclude_objects`
- `a_exclude_object_expr` - string of regex expression of objects to be excluded from the coverage report. It will override `a_exclude_objects`
- `a_include_schema_expr` - string of regex expression of schemas to be included in the coverage report. It will override `a_include_objects` for example :
```sql
a_include_schema_expr => '^ut3_develop',
a_include_objects => ut3_develop.ut_varchar2_list( 'ut3_tester_helper.regex_dummy_cov' )
```
Will result in showing coverage for all schemas that match regular expression `^ut3_develop` and ignore objectes defined by parameter `a_include_objects`

- `a_include_object_expr` - string of regex expression of objects ( no schema names included ) to be included in the coverage report. It will override `a_include_objects` for example:
```sql
a_include_object_expr => 'regex123',
a_include_objects => ut3_develop.ut_varchar2_list( 'ut3_tester_helper.regex_dummy_cov' )
```
Will result in showing coverage for all objects that name match regular expression `regex123` and ignore objectes defined by parameter `a_include_objects`

- `a_exclude_schema_expr` - string of regex expression of schemas to be excluded from the coverage report. It will override `a_exclude_objects` for example:
```sql
a_exclude_schema_expr => '^ut3_tester',
a_exclude_objects => ut3_develop.ut_varchar2_list( 'ut3_develop.regex_dummy_cov' )
```
Will result in showing coverage for all objects that schema is not matching regular expression `^ut3_tester` and ignore exclusion defined by parameter `a_exclude_objects`

- `a_exclude_object_expr` - string of regex expression of objects to be excluded from the coverage report. It will override `a_exclude_objects` for example
```sql
a_exclude_object_expr => 'regex123',
a_exclude_objects => ut3_develop.ut_varchar2_list( 'ut3_develop.regex_dummy_cov' )
```
Will result in showing coverage for all objects that name is not matching regular expression `regex123` and ignore exclusion defined by parameter `a_exclude_objects`


You may specify both _include_ and _exclude_ options to gain more control over what needs to be included / excluded from the coverage report.

Expand Down
40 changes: 27 additions & 13 deletions source/core/coverage/ut_coverage.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ create or replace package body ut_coverage is
end;

function get_cov_sources_sql(a_coverage_options ut_coverage_options, a_skip_objects ut_object_names) return varchar2 is
l_result varchar2(32767); --QUESTION: Given fact that we can pass large regex filters same as objects filter should we consider a clob ?
l_result varchar2(32767);
l_full_name varchar2(32767);
l_join_mappings varchar2(32767);
l_filters varchar2(32767);
Expand All @@ -55,7 +55,12 @@ create or replace package body ut_coverage is
from {sources_view} s {join_file_mappings}
where s.type in ('PACKAGE BODY', 'TYPE BODY', 'PROCEDURE', 'FUNCTION', 'TRIGGER')
{filters}
{regex_exc_filters}
{regex_exc_filters}
and not exists (
select /*+ cardinality(el {excuded_objects_cardinality})*/ 1
from table(:l_excluded_objects) el
where s.owner = el.owner and s.name = el.name
)
),
coverage_sources as (
select full_name, owner, name, type, line, text,
Expand Down Expand Up @@ -146,40 +151,49 @@ create or replace package body ut_coverage is
l_result := replace(l_result, '{filters}', l_filters);
l_result := replace(l_result, '{mappings_cardinality}', l_mappings_cardinality);
l_result := replace(l_result, '{skipped_objects_cardinality}', ut_utils.scale_cardinality(cardinality(a_skip_objects)));
l_result := replace(l_result, '{excuded_objects_cardinality}', ut_utils.scale_cardinality(cardinality(coalesce(a_coverage_options.exclude_objects, ut_object_names()))));
l_result := replace(l_result, '{regex_exc_filters}', l_regex_exc_filters);

return l_result;

end;

function get_cov_sources_cursor(a_coverage_options in ut_coverage_options) return sys_refcursor is
l_cursor sys_refcursor;
l_skip_objects ut_object_names;
l_sql varchar2(32767);
l_cursor sys_refcursor;
l_skip_objects ut_object_names;
l_excluded_objects ut_object_names;
l_sql varchar2(32767);
begin
if not is_develop_mode() then
--skip all the utplsql framework objects and all the unit test packages that could potentially be reported by coverage.
l_skip_objects := coalesce(ut_utils.get_utplsql_objects_list(),ut_object_names());
--Regex exclusion override the standard exclusion objects.
if a_coverage_options.exclude_schema_expr is null and a_coverage_options.exclude_object_expr is null then
l_skip_objects := l_skip_objects multiset union all coalesce(a_coverage_options.exclude_objects, ut_object_names());
end if;
end if;

--Regex exclusion override the standard exclusion objects.
if a_coverage_options.exclude_schema_expr is null and a_coverage_options.exclude_object_expr is null then
l_excluded_objects := coalesce(a_coverage_options.exclude_objects, ut_object_names());
end if;

l_sql := get_cov_sources_sql(a_coverage_options, l_skip_objects);

ut_event_manager.trigger_event(ut_event_manager.gc_debug, ut_key_anyvalues().put('l_sql',l_sql) );

if a_coverage_options.file_mappings is not empty then
open l_cursor for l_sql using a_coverage_options.file_mappings,a_coverage_options.exclude_schema_expr,a_coverage_options.exclude_object_expr,l_skip_objects;
open l_cursor for l_sql using a_coverage_options.file_mappings,a_coverage_options.exclude_schema_expr,
a_coverage_options.exclude_object_expr,l_excluded_objects,
l_skip_objects;
elsif a_coverage_options.include_schema_expr is not null or a_coverage_options.include_object_expr is not null then
open l_cursor for l_sql using a_coverage_options.include_schema_expr,a_coverage_options.include_object_expr,
a_coverage_options.exclude_schema_expr,a_coverage_options.exclude_object_expr,
l_skip_objects;
l_excluded_objects,l_skip_objects;
elsif a_coverage_options.include_objects is not empty then
open l_cursor for l_sql using a_coverage_options.include_objects,a_coverage_options.exclude_schema_expr,a_coverage_options.exclude_object_expr,l_skip_objects;
open l_cursor for l_sql using a_coverage_options.include_objects,a_coverage_options.exclude_schema_expr,
a_coverage_options.exclude_object_expr,l_excluded_objects,
l_skip_objects;
else
open l_cursor for l_sql using a_coverage_options.schema_names,a_coverage_options.exclude_schema_expr,a_coverage_options.exclude_object_expr,l_skip_objects;
open l_cursor for l_sql using a_coverage_options.schema_names,a_coverage_options.exclude_schema_expr,
a_coverage_options.exclude_object_expr,l_excluded_objects,
l_skip_objects;
end if;
return l_cursor;
end;
Expand Down