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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
40 changes: 20 additions & 20 deletions source/api/ut.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -259,55 +259,55 @@ create or replace package body ut is
end;

procedure run(
a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := 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
) is
l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter());
begin
ut.run(
ut_varchar2_list(sys_context('userenv', 'current_schema')), a_reporter, a_color_console,
a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, a_include_objects, a_exclude_objects
run_autonomous(
a_paths, l_reporter, ut_utils.boolean_to_int(a_color_console), a_coverage_schemes, a_source_file_mappings, a_test_file_mappings,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change argument to to _a_reporter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, skip it.

a_include_objects, a_exclude_objects
);
ut_output_buffer.lines_to_dbms_output(l_reporter.reporter_id);
end;

procedure run(
a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false,
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
) is
l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter());
begin
ut.run(
ut_varchar2_list(sys_context('userenv', 'current_schema')), a_reporter, a_color_console,
a_coverage_schemes, a_source_files, a_test_files, a_include_objects, a_exclude_objects
run_autonomous(
a_paths, l_reporter, ut_utils.boolean_to_int(a_color_console), a_coverage_schemes, a_source_files, a_test_files,
a_include_objects, a_exclude_objects
);
ut_output_buffer.lines_to_dbms_output(l_reporter.reporter_id);
end;

procedure run(
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_reporter ut_reporter_base := null, a_color_console boolean := 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
) is
l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter());
begin
ut_runner.run(
a_paths, l_reporter, a_color_console, a_coverage_schemes, a_source_file_mappings, a_test_file_mappings,
a_include_objects, a_exclude_objects
ut.run(
ut_varchar2_list(sys_context('userenv', 'current_schema')), a_reporter, a_color_console,
a_coverage_schemes, a_source_file_mappings, a_test_file_mappings, a_include_objects, a_exclude_objects
);
ut_output_buffer.lines_to_dbms_output(l_reporter.reporter_id);
end;

procedure run(
a_paths ut_varchar2_list, a_reporter ut_reporter_base := null, a_color_console boolean := false,
a_reporter ut_reporter_base := null, a_color_console boolean := false,
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
) is
l_reporter ut_reporter_base := coalesce(a_reporter, ut_documentation_reporter());
begin
ut_runner.run(
a_paths, l_reporter, a_color_console, a_coverage_schemes, a_source_files, a_test_files,
a_include_objects, a_exclude_objects
ut.run(
ut_varchar2_list(sys_context('userenv', 'current_schema')), a_reporter, a_color_console,
a_coverage_schemes, a_source_files, a_test_files, a_include_objects, a_exclude_objects
);
ut_output_buffer.lines_to_dbms_output(l_reporter.reporter_id);
end;

procedure run(
Expand Down
23 changes: 12 additions & 11 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ create or replace package body ut_runner is
return l_result;
end;

procedure finish_run(a_reporters ut_reporters) is
begin
ut_utils.cleanup_temp_tables;
ut_output_buffer.close(a_reporters);
ut_metadata.reset_source_definition_cache;
ut_utils.read_cache_to_dbms_output();
end;


/**
Expand Down Expand Up @@ -61,8 +68,8 @@ create or replace package body ut_runner is
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
) is
l_items_to_run ut_run;
l_listener ut_event_listener;
l_items_to_run ut_run;
l_listener ut_event_listener;
begin
begin
ut_output_buffer.cleanup_buffer();
Expand All @@ -85,16 +92,10 @@ create or replace package body ut_runner is
);
l_items_to_run.do_execute(l_listener);

ut_utils.cleanup_temp_tables;
ut_output_buffer.close(l_listener.reporters);
ut_metadata.reset_source_definition_cache;
ut_utils.read_cache_to_dbms_output();
exception
finish_run(l_listener.reporters);
exception
when others then
ut_utils.cleanup_temp_tables;
ut_output_buffer.close(l_listener.reporters);
ut_metadata.reset_source_definition_cache;
ut_utils.read_cache_to_dbms_output();
finish_run(l_listener.reporters);
dbms_output.put_line(dbms_utility.format_error_backtrace);
dbms_output.put_line(dbms_utility.format_error_stack);
raise;
Expand Down
99 changes: 67 additions & 32 deletions test/ut_runner/test_ut_runner.pkb
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
create or replace package body test_ut_runner is

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 keep_an_open_transaction is
l_expected varchar2(300);
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--Arrange
create_test_spec();
create_test_body(0);
l_expected := dbms_transaction.local_transaction_id(true);
--Act
ut3.ut.run('test_cache');
dbms_output.get_lines( l_output_data, l_num_lines);
--Assert
ut.expect(dbms_transaction.local_transaction_id()).to_equal(l_expected);
drop_test_package();
end;

procedure close_newly_opened_transaction is
l_output_data dbms_output.chararr;
l_num_lines integer := 100000;
begin
--Arrange
create_test_spec();
create_test_body(0);
rollback;
--Act
ut3.ut.run('test_cache');
dbms_output.get_lines( l_output_data, l_num_lines);
--Assert
ut.expect(dbms_transaction.local_transaction_id()).to_be_null();
drop_test_package();
end;

procedure version_comp_check_compare is
begin
ut.expect( ut3.ut_runner.version_compatibility_check('v3.0.0.0','v3.0.0.0') ).to_equal(1);
Expand Down Expand Up @@ -41,38 +108,6 @@ 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;
Expand Down
9 changes: 8 additions & 1 deletion test/ut_runner/test_ut_runner.pks
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
create or replace package test_ut_runner is

--%suite(ut_runner)
--%suitepath(utplsql.core)
--%suitepath(utplsql)
--%rollback(manual)

--%test(transaction stays open after the run if it was opened before the run)
procedure keep_an_open_transaction;

--%test(closes open transactions if no transaction was open before run)
procedure close_newly_opened_transaction;

--%test(version_compatibility_check compares major, minor and bugfix number)
procedure version_comp_check_compare;
Expand Down