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
Package body cache is now invalidated after every test run.
Fixed issues with self-testing.
Fixed issues with version compare for short version numbers.
  • Loading branch information
jgebal committed Aug 29, 2017
commit baaa5cc97d9c5f05963b359286cdbbb54520f213
8 changes: 5 additions & 3 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ create or replace package body ut_runner is
l_current ut_utils.t_version := ut_utils.to_version(coalesce(a_current,version()));
begin
if l_requested.major = l_current.major
and (l_requested.minor < l_current.minor
or l_requested.minor = l_current.minor and l_requested.bugfix <= l_current.bugfix) then
and (l_requested.minor < l_current.minor or l_requested.minor is null
or l_requested.minor = l_current.minor and (l_requested.bugfix <= l_current.bugfix or l_requested.bugfix is null)) then
l_result := true;
end if;
return ut_utils.boolean_to_int(l_result);
Expand Down Expand Up @@ -86,10 +86,12 @@ create or replace package body ut_runner is

ut_utils.cleanup_temp_tables;
ut_output_buffer.close(l_listener.reporters);
exception
ut_metadata.reset_source_definition_cache;
exception
when others then
ut_utils.cleanup_temp_tables;
ut_output_buffer.close(l_listener.reporters);
ut_metadata.reset_source_definition_cache;
dbms_output.put_line(dbms_utility.format_error_backtrace);
dbms_output.put_line(dbms_utility.format_error_stack);
raise;
Expand Down
7 changes: 7 additions & 0 deletions source/core/ut_metadata.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ create or replace package body ut_metadata as
return l_line;
end;

procedure reset_source_definition_cache is
begin
g_source_cache := null;
g_cached_object := null;
end;

function get_dba_view(a_view_name varchar2) return varchar2 is
l_invalid_object_name exception;
l_result varchar2(128) := lower(a_view_name);
Expand All @@ -170,5 +176,6 @@ create or replace package body ut_metadata as
when l_invalid_object_name then
return replace(l_result,'dba_','all_');
end;

end;
/
3 changes: 3 additions & 0 deletions source/core/ut_metadata.pks
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ create or replace package ut_metadata authid current_user as
*/
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2;


procedure reset_source_definition_cache;

/*
function: get_dba_view

Expand Down
28 changes: 27 additions & 1 deletion test/install_tests.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
whenever sqlerror exit failure rollback
whenever oserror exit failure rollback

@core.pks
@ut_utils/test_ut_utils.pks
Expand All @@ -23,6 +25,30 @@
@ut_expectations/test_expectations_cursor.pkb
@@ut_runner/test_ut_runner.pkb

show errors
set linesize 200
set define on
column text format a100
column error_count noprint new_value error_count

prompt Validating installation

set heading on
select type, name, sequence, line, position, text, count(1) over() error_count
from all_errors
where owner = USER
and name not like 'BIN$%' --not recycled
-- errors only. ignore warnings
and attribute = 'ERROR'
order by name, type, sequence
/

begin
if to_number('&&error_count') > 0 then
raise_application_error(-20000, 'Not all sources were successfully installed.');
else
dbms_output.put_line('Installation completed successfully');
end if;
end;
/

exit
56 changes: 56 additions & 0 deletions test/ut_runner/test_ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,61 @@ create or replace package body test_ut_runner is
throws('v3.0.0.0','bad_ver');
end;

procedure create_test_spec
as
pragma autonomous_transaction;
begin
execute immediate q'[create or replace package test_cache as
--%suite

--%test
procedure failing_test;
end;
]';
end;

procedure create_test_body(a_number integer)
as
pragma autonomous_transaction;
begin
execute immediate 'create or replace package body test_cache as
procedure failing_test is
begin
ut3.ut.expect('||a_number||').to_be_null;
end;
end;';
end;

procedure drop_test_package
as
pragma autonomous_transaction;
begin
execute immediate 'drop package test_cache';
end;

procedure run_reset_package_body_cache is
l_results ut3.ut_varchar2_list;
l_expected clob;
l_actual clob;
begin
--Arrange
create_test_spec();
create_test_body(0);
select *
bulk collect into l_results
from table(ut3.ut.run('test_cache'));

--Act
create_test_body(1);
select *
bulk collect into l_results
from table(ut3.ut.run('test_cache'));
--Assert
l_actual := ut3.ut_utils.table_to_clob(l_results);
l_expected := '%ut3.ut.expect(1).to_be_null;%';
ut.expect(l_actual).to_be_like(l_expected);
drop_test_package();
end;

end;
/
4 changes: 2 additions & 2 deletions test/ut_runner/test_ut_runner.pks
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ create or replace package test_ut_runner is
--%test(version_compatibility_check raises exception when invalid version passed)
procedure version_comp_check_exception;

--%test(version_compatibility_check raises exception when invalid version passed)
procedure version_comp_check_exception;
--%test(run resets cache of package body after every run)
procedure run_reset_package_body_cache;

end;
/