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

Skip to content

Commit 97cd689

Browse files
authored
Merge pull request #512 from utPLSQL/bugfix/coverage_filter_options
Fixed coverage filtering issue.
2 parents 04bda1d + e5a786b commit 97cd689

8 files changed

Lines changed: 126 additions & 60 deletions

File tree

source/api/ut.pkb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ create or replace package body ut is
119119
ut_runner.run(
120120
a_paths, ut_reporters(coalesce(a_reporter,ut_documentation_reporter())),
121121
ut_utils.int_to_boolean(a_color_console), a_coverage_schemes,
122-
a_source_files, a_test_files, a_include_objects, a_exclude_objects
122+
ut_file_mapper.build_file_mappings(a_source_files),
123+
ut_file_mapper.build_file_mappings(a_test_files),
124+
a_include_objects, a_exclude_objects
123125
);
124126
rollback;
125127
end;

source/api/ut_runner.pkb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,6 @@ create or replace package body ut_runner is
105105
end if;
106106
end;
107107

108-
procedure run(
109-
a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false,
110-
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
111-
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false
112-
) is
113-
begin
114-
run(
115-
a_paths, a_reporters, a_color_console, a_coverage_schemes,
116-
ut_file_mapper.build_file_mappings(a_source_files),
117-
ut_file_mapper.build_file_mappings(a_test_files),
118-
a_include_objects, a_exclude_objects, a_fail_on_errors
119-
);
120-
end;
121-
122108
procedure rebuild_annotation_cache(a_object_owner varchar2, a_object_type varchar2) is
123109
begin
124110
ut_annotation_manager.rebuild_annotation_cache(a_object_owner, a_object_type);

source/api/ut_runner.pks

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,34 @@ create or replace package ut_runner authid current_user is
3333
function version_compatibility_check( a_requested varchar2, a_current varchar2 := null ) return integer;
3434

3535
/**
36-
* Run suites/tests by path
37-
* Accepts value of the following formats:
38-
* schema - executes all suites in the schema
39-
* schema:suite1[.suite2] - executes all items of suite1 (suite2) in the schema.
36+
* Execute specified suites/tests by paths
37+
* @param a_paths list of schemes, packages, procedures or suite-paths to execute
38+
* @param a_reporters list of reporter objects (formats) to use for reporting
39+
* @param a_color_console true/false - should the console format reporters use ANSI color tags
40+
* @param a_coverage_schemes list of database schemes to include in coverage
41+
* @param a_source_file_mappings list of project source files mapped to DB objects that coverage should be reported on
42+
* @param a_test_file_mappings list of project test files mapped to DB objects that test results should be reported on
43+
* @param a_include_objects list of database objects (in format 'owner.name') that coverage should be reported on
44+
* @param a_exclude_objects list of database objects (in format 'owner.name') that coverage should be skipped for
45+
* @param a_fail_on_errors true/false - should an exception be thrown when tests are completed with failures/errors
46+
*
47+
* @example
48+
* Parameter `a_paths` accepts values of the following formats:
49+
* schema - executes all suites in the schema
50+
* schema:suite1[.suite2] - executes all items of suite1 (suite2) in the schema.
4051
* suite1.suite2 is a suitepath variable
41-
* schema:suite1[.suite2][.test1] - executes test1 in suite suite1.suite2
42-
* schema.suite1 - executes the suite package suite1 in the schema "schema"
52+
* schema:suite1[.suite2][.test1] - executes test1 in suite suite1.suite2
53+
* schema.suite1 - executes the suite package suite1 in the schema "schema"
4354
* all the parent suites in the hiearcy setups/teardown procedures as also executed
4455
* all chile items are executed
45-
* schema.suite1.test2 - executes test2 procedure of suite1 suite with execution of all
46-
* parent setup/teardown procedures
56+
* schema.suite1.test2 - executes test2 procedure of suite1 suite with execution of all parent setup/teardown procedures
4757
*/
48-
4958
procedure run(
5059
a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false,
5160
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
5261
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false
5362
);
5463

55-
procedure run(
56-
a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false,
57-
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
58-
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false
59-
);
60-
6164
/**
6265
* Rebuilds annotation cache for a specified schema and object type.
6366
* The procedure is called internally by `get_annotated_objects` function.

source/core/coverage/ut_coverage.pkb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,26 @@ create or replace package body ut_coverage is
7272
then 'Y'
7373
end as to_be_skipped
7474
from ]'||l_view_name||q'[ s]';
75-
if a_coverage_options.file_mappings is not null and a_coverage_options.file_mappings.count > 0 then
75+
if a_coverage_options.file_mappings is not empty then
7676
l_result := l_result || '
7777
join table(:file_mappings) f
7878
on s.name = f.object_name
7979
and s.type = f.object_type
8080
and s.owner = f.object_owner
8181
where 1 = 1';
82+
elsif a_coverage_options.include_objects is not empty then
83+
l_result := l_result || '
84+
where (s.owner, s.name) in (select il.owner, il.name from table(:include_objects) il)';
8285
else
8386
l_result := l_result || '
8487
where s.owner in (select upper(t.column_value) from table(:l_schema_names) t)';
8588
end if;
8689
l_result := l_result || q'[
8790
and s.type not in ('PACKAGE', 'TYPE', 'JAVA SOURCE')
8891
--Exclude calls to utPLSQL framework, Unit Test packages and objects from a_exclude_list parameter of coverage reporter
89-
and (s.owner, s.name) not in (select el.owner, el.name from table(:l_skipped_objects) el)]';
90-
if a_coverage_options.include_objects is null then
91-
l_result := l_result || '
92-
and :include_objects is null';
93-
else
94-
l_result := l_result || '
95-
and (s.owner, s.name) in (select il.owner, il.name from table(:include_objects) il)';
96-
end if;
97-
l_result := l_result || '
92+
and (s.owner, s.name) not in (select el.owner, el.name from table(:l_skipped_objects) el)
9893
)
99-
where line > 0';
94+
where line > 0]';
10095
return l_result;
10196
end;
10297

@@ -113,9 +108,11 @@ create or replace package body ut_coverage is
113108
end if;
114109
l_sql := get_cov_sources_sql(a_coverage_options);
115110
if a_coverage_options.file_mappings is not empty then
116-
open l_cursor for l_sql using a_coverage_options.file_mappings, l_skip_objects, a_coverage_options.include_objects;
111+
open l_cursor for l_sql using a_coverage_options.file_mappings, l_skip_objects;
112+
elsif a_coverage_options.include_objects is not empty then
113+
open l_cursor for l_sql using a_coverage_options.include_objects, l_skip_objects;
117114
else
118-
open l_cursor for l_sql using l_schema_names, l_skip_objects, a_coverage_options.include_objects;
115+
open l_cursor for l_sql using l_schema_names, l_skip_objects;
119116
end if;
120117
return l_cursor;
121118
end;

test/ut_reporters/test_coverage.pkb

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ create or replace package body test_coverage is
1212

1313
procedure create_dummy_coverage_package is
1414
begin
15-
dbms_output.put_line('creating DUMMY_COVERAGE');
16-
execute immediate q'[create or replace package DUMMY_COVERAGE is
15+
dbms_output.put_line('creating UT3.DUMMY_COVERAGE');
16+
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE is
1717
procedure do_stuff;
1818
end;]';
19-
execute immediate q'[create or replace package body DUMMY_COVERAGE is
19+
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE is
2020
procedure do_stuff is
2121
begin
2222
if 1 = 2 then
@@ -30,14 +30,14 @@ create or replace package body test_coverage is
3030

3131
procedure create_dummy_coverage_test is
3232
begin
33-
dbms_output.put_line('creating TEST_DUMMY_COVERAGE');
34-
execute immediate q'[create or replace package TEST_DUMMY_COVERAGE is
33+
dbms_output.put_line('creating UT3.TEST_DUMMY_COVERAGE');
34+
execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE is
3535
--%suite(dummy coverage test)
3636

3737
--%test
3838
procedure test_do_stuff;
3939
end;]';
40-
execute immediate q'[create or replace package body TEST_DUMMY_COVERAGE is
40+
execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE is
4141
procedure test_do_stuff is
4242
begin
4343
dummy_coverage.do_stuff;
@@ -52,7 +52,7 @@ create or replace package body test_coverage is
5252
values(a_run_id, user, sysdate, 'unit testing utPLSQL');
5353

5454
insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name)
55-
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3_TESTER', 'DUMMY_COVERAGE');
55+
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE');
5656

5757
insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time)
5858
select a_run_id, c_unit_id, 4, 1, 1 from dual union all
@@ -74,15 +74,85 @@ create or replace package body test_coverage is
7474
procedure cleanup_dummy_coverage is
7575
pragma autonomous_transaction;
7676
begin
77-
dbms_output.put_line('dopping TEST_DUMMY_COVERAGE');
78-
execute immediate q'[drop package test_dummy_coverage]';
79-
dbms_output.put_line('dopping DUMMY_COVERAGE');
80-
execute immediate q'[drop package dummy_coverage]';
77+
dbms_output.put_line('dopping UT3.TEST_DUMMY_COVERAGE');
78+
execute immediate q'[drop package ut3.test_dummy_coverage]';
79+
dbms_output.put_line('dopping UT3.DUMMY_COVERAGE');
80+
execute immediate q'[drop package ut3.dummy_coverage]';
8181
delete from ut3.plsql_profiler_data where runid = g_run_id;
8282
delete from ut3.plsql_profiler_units where runid = g_run_id;
8383
delete from ut3.plsql_profiler_runs where runid = g_run_id;
8484
commit;
8585
end;
8686

87+
procedure coverage_for_object is
88+
l_expected clob;
89+
l_actual clob;
90+
l_results ut3.ut_varchar2_list;
91+
begin
92+
--Arrange
93+
l_expected := '%<file path="ut3.dummy_coverage">%';
94+
--Act
95+
select *
96+
bulk collect into l_results
97+
from table(
98+
ut3.ut.run(
99+
a_path => 'ut3.test_dummy_coverage',
100+
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
101+
a_include_objects => ut3.ut_varchar2_list( 'ut3.dummy_coverage' )
102+
)
103+
);
104+
--Assert
105+
l_actual := ut3.ut_utils.table_to_clob(l_results);
106+
ut.expect(l_actual).to_be_like(l_expected);
107+
end;
108+
109+
procedure coverage_for_schema is
110+
l_expected clob;
111+
l_actual clob;
112+
l_results ut3.ut_varchar2_list;
113+
begin
114+
--Arrange
115+
l_expected := '<file path="ut3.%">';
116+
l_expected := '%'||l_expected||'%'||l_expected||'%';
117+
--Act
118+
select *
119+
bulk collect into l_results
120+
from table(
121+
ut3.ut.run(
122+
a_path => 'ut3.test_dummy_coverage',
123+
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
124+
a_coverage_schemes => ut3.ut_varchar2_list( 'ut3' )
125+
)
126+
);
127+
--Assert
128+
l_actual := ut3.ut_utils.table_to_clob(l_results);
129+
ut.expect(l_actual).to_be_like(l_expected);
130+
end;
131+
132+
procedure coverage_for_file is
133+
l_expected clob;
134+
l_actual clob;
135+
l_results ut3.ut_varchar2_list;
136+
l_file_path varchar2(100);
137+
begin
138+
--Arrange
139+
l_file_path := lower('test/ut3.dummy_coverage.pkb');
140+
l_expected := '%<file path="'||l_file_path||'">%';
141+
--Act
142+
select *
143+
bulk collect into l_results
144+
from table(
145+
ut3.ut.run(
146+
a_path => 'ut3.test_dummy_coverage',
147+
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
148+
a_source_files => ut3.ut_varchar2_list( l_file_path ),
149+
a_test_files => ut3.ut_varchar2_list( )
150+
)
151+
);
152+
--Assert
153+
l_actual := ut3.ut_utils.table_to_clob(l_results);
154+
ut.expect(l_actual).to_be_like(l_expected);
155+
end;
156+
87157
end;
88158
/

test/ut_reporters/test_coverage.pks

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,13 @@ create or replace package test_coverage is
99
--%afterall
1010
procedure cleanup_dummy_coverage;
1111

12+
--%test(Coverage is gathered for specified object)
13+
procedure coverage_for_object;
14+
15+
--%test(Coverage is gathered for specified schema)
16+
procedure coverage_for_schema;
17+
18+
--%test(Coverage is gathered for specified file)
19+
procedure coverage_for_file;
1220
end;
1321
/

test/ut_reporters/test_coverage_sonar_reporter.pkb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ create or replace package body test_coverage_sonar_reporter is
77
begin
88
--Arrange
99
l_expected := '<coverage version="1">
10-
<file path="test/dummy_coverage.pkb">
10+
<file path="test/ut3.dummy_coverage.pkb">
1111
<lineToCover lineNumber="4" covered="true"/>
1212
<lineToCover lineNumber="5" covered="false"/>
1313
<lineToCover lineNumber="7" covered="true"/>
@@ -18,9 +18,9 @@ create or replace package body test_coverage_sonar_reporter is
1818
bulk collect into l_results
1919
from table(
2020
ut3.ut.run(
21-
a_path => 'test_dummy_coverage',
21+
a_path => 'ut3.test_dummy_coverage',
2222
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
23-
a_source_files => ut3.ut_varchar2_list( 'test/dummy_coverage.pkb' ),
23+
a_source_files => ut3.ut_varchar2_list( 'test/ut3.dummy_coverage.pkb' ),
2424
a_test_files => ut3.ut_varchar2_list( )
2525
)
2626
);

test/ut_reporters/test_coveralls_reporter.pkb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ create or replace package body test_coveralls_reporter is
77
begin
88
--Arrange
99
l_expected := '{"source_files":[
10-
{ "name": "test/dummy_coverage.pkb",
10+
{ "name": "test/ut3.dummy_coverage.pkb",
1111
"coverage": [null,null,null,1,0,null,1]}]}
1212
';
1313
--Act
1414
select *
1515
bulk collect into l_results
1616
from table(
1717
ut3.ut.run(
18-
a_path => 'test_dummy_coverage',
18+
a_path => 'ut3.test_dummy_coverage',
1919
a_reporter=> ut3.ut_coveralls_reporter( ),
20-
a_source_files => ut3.ut_varchar2_list( 'test/dummy_coverage.pkb' ),
20+
a_source_files => ut3.ut_varchar2_list( 'test/ut3.dummy_coverage.pkb' ),
2121
a_test_files => ut3.ut_varchar2_list( )
2222
)
2323
);

0 commit comments

Comments
 (0)