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
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
Next Next commit
12.2 coverage
Fixes to order of new attribute.
Rename package to more meaningful name
Introduce an raise an error for non existing coverage type
Update tests
  • Loading branch information
lwasylow committed Apr 3, 2018
commit 35e5e1376557817cec7cd1236406ed512f736703
106 changes: 53 additions & 53 deletions source/api/ut.pkb

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions source/api/ut.pks
Original file line number Diff line number Diff line change
Expand Up @@ -49,74 +49,74 @@ create or replace package ut authid current_user as

function run(
a_reporter ut_reporter_base := null, a_color_console integer := 0,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
) return ut_varchar2_rows pipelined;

function run(
a_reporter ut_reporter_base := null, a_color_console integer := 0,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
) return ut_varchar2_rows pipelined;

function run(
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console integer := 0,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
) return ut_varchar2_rows pipelined;

function run(
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console integer := 0,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
) return ut_varchar2_rows pipelined;

function run(
a_path varchar2, a_reporter ut_reporter_base := null, a_color_console integer := 0,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
) return ut_varchar2_rows pipelined;

function run(
a_path varchar2, a_reporter ut_reporter_base := null, a_color_console integer := 0,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
) return ut_varchar2_rows pipelined;

procedure run(
a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
);

procedure run(
a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
);

procedure run(
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
);

procedure run(
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
);

procedure run(
a_path varchar2, a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
);

procedure run(
a_path varchar2, a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2:=null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null
a_coverage_schemes ut_varchar2_list := null, a_source_files ut_varchar2_list, a_test_files ut_varchar2_list,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_coverage_type varchar2:=null
);

/**
Expand Down
4 changes: 2 additions & 2 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ create or replace package body ut_runner is

procedure run(
a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2 := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false,a_coverage_type varchar2 := null
) is
l_items_to_run ut_run;
l_listener ut_event_listener;
Expand Down
5 changes: 3 additions & 2 deletions source/api/ut_runner.pks
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ create or replace package ut_runner authid current_user is
*/
procedure run(
a_paths ut_varchar2_list, a_reporters ut_reporters, a_color_console boolean := false,
a_coverage_schemes ut_varchar2_list := null,a_coverage_type varchar2 := null , a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null, a_fail_on_errors boolean default false
a_coverage_schemes ut_varchar2_list := null, a_source_file_mappings ut_file_mappings := null, a_test_file_mappings ut_file_mappings := null,
a_include_objects ut_varchar2_list := null, a_exclude_objects ut_varchar2_list := null,
a_fail_on_errors boolean default false, a_coverage_type varchar2 := null
);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create or replace package body ut_block_helper is
create or replace package body ut_block_coverage_helper is
/*
utPLSQL - Version 3
Copyright 2016 - 2017 utPLSQL Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create or replace package ut_block_helper authid definer is
create or replace package ut_block_coverage_helper authid definer is
/*
utPLSQL - Version 3
Copyright 2016 - 2017 utPLSQL Project
Expand Down
2 changes: 1 addition & 1 deletion source/core/coverage/ut_coverage_block.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ create or replace package body ut_coverage_block is
exit when l_source_objects_crsr%notfound;

--get coverage data
l_line_calls := ut_block_helper.get_raw_coverage_data_block(l_source_object.owner, l_source_object.name);
l_line_calls := ut_block_coverage_helper.get_raw_coverage_data_block(l_source_object.owner, l_source_object.name);

--if there is coverage, we need to filter out the garbage (badly indicated data)
if l_line_calls.count > 0 then
Expand Down
8 changes: 4 additions & 4 deletions source/core/coverage/ut_coverage_helper.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ create or replace package body ut_coverage_helper is
set_coverage_type(a_coverage_type);
if get_coverage_type = ut_coverage.c_block_coverage then
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
ut_block_helper.coverage_start(a_run_comment => a_run_comment ,a_coverage_id => g_coverage_id );
ut_block_coverage_helper.coverage_start(a_run_comment => a_run_comment ,a_coverage_id => g_coverage_id );
$else
null;
raise_application_error(ut_utils.gc_invalid_coverage_type,'Invalid coverage type requested. Please validate your Oracle install');
$end
else
ut_proftab_helper.coverage_start(a_run_comment => a_run_comment, a_coverage_id => g_coverage_id);
Expand Down Expand Up @@ -123,7 +123,7 @@ create or replace package body ut_coverage_helper is
g_is_started := false;
if get_coverage_type = ut_coverage.c_block_coverage then
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
ut_block_helper.coverage_stop();
ut_block_coverage_helper.coverage_stop();
$else
null;
$end
Expand All @@ -139,7 +139,7 @@ create or replace package body ut_coverage_helper is
g_is_started := false;
if get_coverage_type = ut_coverage.c_block_coverage then
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
ut_block_helper.coverage_stop();
ut_block_coverage_helper.coverage_stop();
$else
null;
$end
Expand Down
5 changes: 5 additions & 0 deletions source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ create or replace package ut_utils authid definer is
gc_invalid_version_no constant pls_integer := -20214;
pragma exception_init(ex_invalid_version_no, -20214);

-- Invalid coverage type
ex_invalid_coverage_type exception;
gc_invalid_coverage_type constant pls_integer := -20215;
pragma exception_init(ex_invalid_coverage_type, -20215);

gc_max_storage_varchar2_len constant integer := 4000;
gc_max_output_string_length constant integer := 4000;
gc_max_input_string_length constant integer := gc_max_output_string_length - 2; --we need to remove 2 chars for quotes around string
Expand Down
4 changes: 2 additions & 2 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
--gathering coverage
@@install_component.sql 'core/coverage/ut_coverage_sources_tmp.sql'
@@install_component.sql 'core/coverage/ut_coverage_helper.pks'
@@install_above_12_1.sql 'core/coverage/ut_block_helper.pks'
@@install_above_12_1.sql 'core/coverage/ut_block_coverage_helper.pks'
@@install_component.sql 'core/coverage/ut_proftab_helper.pks'
@@install_component.sql 'core/coverage/ut_coverage.pks'
@@install_above_12_1.sql 'core/coverage/ut_coverage_block.pks'
@@install_component.sql 'core/coverage/ut_coverage_proftab.pks'
@@install_component.sql 'core/coverage/ut_coverage_reporter_base.tps'
@@install_component.sql 'core/coverage/ut_coverage_helper.pkb'
@@install_above_12_1.sql 'core/coverage/ut_block_helper.pkb'
@@install_above_12_1.sql 'core/coverage/ut_block_coverage_helper.pkb'
@@install_component.sql 'core/coverage/ut_proftab_helper.pkb'
@@install_component.sql 'core/coverage/ut_coverage.pkb'
@@install_above_12_1.sql 'core/coverage/ut_coverage_block.pkb'
Expand Down
145 changes: 145 additions & 0 deletions test/core/reporters/test_not_existing_block.pkb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
create or replace package body test_coverage is

g_run_id integer;

function get_mock_run_id return integer is
v_result integer;
begin
select nvl(min(runid),0) - 1 into v_result
from ut3.plsql_profiler_runs;
return v_result;
end;

procedure create_dummy_coverage_package is
pragma autonomous_transaction;
begin
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE is
procedure do_stuff;
end;]';
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE is
procedure do_stuff is
begin
if 1 = 2 then
dbms_output.put_line('should not get here');
else
dbms_output.put_line('should get here');
end if;
end;
end;]';
end;

procedure create_dummy_coverage_test is
pragma autonomous_transaction;
begin
execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE is
--%suite(dummy coverage test)
--%suitepath(coverage_testing)

--%test
procedure test_do_stuff;
end;]';
execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE is
procedure test_do_stuff is
begin
dummy_coverage.do_stuff;
end;
end;]';
end;

procedure create_dummy_coverage_test_1 is
pragma autonomous_transaction;
begin
execute immediate q'[create or replace package UT3.DUMMY_COVERAGE_1 is
procedure do_stuff;
end;]';
execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE_1 is
procedure do_stuff is
begin
if 1 = 2 then
dbms_output.put_line('should not get here');
else
dbms_output.put_line('should get here');
end if;
end;
end;]';
execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE_1 is
--%suite(dummy coverage test 1)
--%suitepath(coverage_testing)

--%test
procedure test_do_stuff;
end;]';
execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE_1 is
procedure test_do_stuff is
begin
dummy_coverage_1.do_stuff;
end;
end;]';
end;

procedure drop_dummy_coverage_test_1 is
pragma autonomous_transaction;
begin
execute immediate q'[drop package UT3.DUMMY_COVERAGE_1]';
execute immediate q'[drop package UT3.TEST_DUMMY_COVERAGE_1]';
end;


procedure mock_coverage_data(a_run_id integer) is
c_unit_id constant integer := 1;
begin
insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment)
values(a_run_id, user, sysdate, 'unit testing utPLSQL');

insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name)
values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE');

insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time)
select a_run_id, c_unit_id, 4, 1, 1 from dual union all
select a_run_id, c_unit_id, 5, 0, 0 from dual union all
select a_run_id, c_unit_id, 7, 1, 1 from dual;
end;

procedure setup_dummy_coverage is
pragma autonomous_transaction;
begin
create_dummy_coverage_package();
create_dummy_coverage_test();
g_run_id := get_mock_run_id();
ut3.ut_coverage_helper.mock_coverage_id(g_run_id);
mock_coverage_data(g_run_id);
commit;
end;

procedure cleanup_dummy_coverage is
pragma autonomous_transaction;
begin
begin execute immediate q'[drop package ut3.test_dummy_coverage]'; exception when others then null; end;
begin execute immediate q'[drop package ut3.dummy_coverage]'; exception when others then null; end;
delete from ut3.plsql_profiler_data where runid = g_run_id;
delete from ut3.plsql_profiler_units where runid = g_run_id;
delete from ut3.plsql_profiler_runs where runid = g_run_id;
commit;
end;

procedure invalid_coverage_type is
l_expected clob;
l_actual clob;
l_results ut3.ut_varchar2_list;
begin
--Arrange
l_expected := '%<file path="ut3.dummy_coverage">%';
--Act
select *
bulk collect into l_results
from table(
ut3.ut.run(
a_path => 'ut3.test_dummy_coverage',
a_reporter=> ut3.ut_coverage_sonar_reporter( ),
a_include_objects => ut3.ut_varchar2_list( 'ut3.dummy_coverage' )
)
);
end;

end;
/
18 changes: 18 additions & 0 deletions test/core/reporters/test_not_existing_block.pks
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
create or replace package test_coverage is

--%suite
--%suitepath(utplsql.core.reporters)

--%beforeall
procedure setup_dummy_coverage;

--%afterall
procedure cleanup_dummy_coverage;


--%test(Coverage is requested for invalid type of coverage)
--%throws(-20215)
procedure invalid_coverage_type;

end;
/
28 changes: 28 additions & 0 deletions test/install_below_12_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set termout off
set echo off
spool dummy.sql
prompt whenever sqlerror exit failure rollback
spool off


def FILE_NAME = '&&1'
column SCRIPT_NAME new_value SCRIPT_NAME noprint

VAR V_FILE_NAME VARCHAR2(1000);
begin
if dbms_db_version.version = 12 and dbms_db_version.release < 2
or dbms_db_version.version < 12
then
:V_FILE_NAME := '&&FILE_NAME';
else
:V_FILE_NAME := 'dummy.sql';
end if;
end;
/
set verify off
select :V_FILE_NAME as SCRIPT_NAME from dual;
set termout on


@@&&SCRIPT_NAME

Loading