Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Binary file added docs/images/tap_reporter_colored.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/tap_reporter_no_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions docs/userguide/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ Details:
utPLSQL comes with a set of build-in coverage reporters.
[Code coverage](coverage.md) section describes in details how to use configure and use code coverage.

## TAP Reporter

The `ut_tap_reporter` produces output compatible with the [Test Anything Protocol](https://testanything.org) (Version 14). TAP output can be consumed by a TAP consumer that can aggregate results from testsuites across different programming languages while maintaining good readability for humans.

![tap_output_no_color](../images/tap_reporter_no_color.png)

If you use a compatible terminal, you can also have a colored result. Only top level `not ok`-results will be colored:

![tap_colored_output](../images/tap_reporter_colored.png)

## Debug reporter

The `ut_debug_reporter` provides a highly verbose output containing thorough details about framework and test execution.
Expand Down
1 change: 1 addition & 0 deletions source/create_grants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ grant execute on &&ut3_owner..ut_tfs_junit_reporter to &ut3_user;
grant execute on &&ut3_owner..ut_documentation_reporter to &ut3_user;
grant execute on &&ut3_owner..ut_sonar_test_reporter to &ut3_user;
grant execute on &&ut3_owner..ut_realtime_reporter to &ut3_user;
grant execute on &&ut3_owner..ut_tap_reporter to &ut3_user;
--reporters - coverage
grant execute on &&ut3_owner..ut_coverage_html_reporter to &ut3_user;
grant execute on &&ut3_owner..ut_coverage_sonar_reporter to &ut3_user;
Expand Down
1 change: 1 addition & 0 deletions source/create_synonyms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ create &action_type. synonym &ut3_user.ut_tfs_junit_reporter for &&ut3_owner..ut
create &action_type. synonym &ut3_user.ut_documentation_reporter for &&ut3_owner..ut_documentation_reporter;
create &action_type. synonym &ut3_user.ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter;
create &action_type. synonym &ut3_user.ut_realtime_reporter for &&ut3_owner..ut_realtime_reporter;
create &action_type. synonym &ut3_user.ut_tap_reporter for &&ut3_owner..ut_tap_reporter;
--reporters - coverage
create &action_type. synonym &ut3_user.ut_coverage_html_reporter for &&ut3_owner..ut_coverage_html_reporter;
create &action_type. synonym &ut3_user.ut_coverage_sonar_reporter for &&ut3_owner..ut_coverage_sonar_reporter;
Expand Down
2 changes: 2 additions & 0 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
@@install_component.sql 'reporters/ut_xunit_reporter.tpb'
@@install_component.sql 'reporters/ut_sonar_test_reporter.tps'
@@install_component.sql 'reporters/ut_sonar_test_reporter.tpb'
@@install_component.sql 'reporters/ut_tap_reporter.tps'
@@install_component.sql 'reporters/ut_tap_reporter.tpb'

@@install_component.sql 'reporters/ut_coverage_html_reporter.tps'
@@install_component.sql 'reporters/ut_coverage_report_html_helper.pks'
Expand Down
124 changes: 124 additions & 0 deletions source/reporters/ut_tap_reporter.tpb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
create or replace type body ut_tap_reporter is


constructor function ut_tap_reporter(self in out nocopy ut_tap_reporter) return self as result is
begin
self.init($$plsql_unit);
self.lvl := 0;
return;
end ut_tap_reporter;

member procedure print_comment(self in out nocopy ut_tap_reporter, a_comment clob) as
begin
self.print_clob(regexp_replace(a_comment, '^', '# ', 1, 0, 'm'));
end print_comment;

member function escape_special_chars(self in out nocopy ut_tap_reporter, a_string_to_escape clob) return clob as
begin
return regexp_replace(a_string_to_escape, '([\\#])', '\\\1');
end escape_special_chars;

overriding member procedure before_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite) as
begin
self.print_text('# Subtest: ' || self.escape_special_chars(coalesce(a_suite.description, a_suite.name)));
lvl := lvl + 2;
self.print_text('1..' || a_suite.items.count);
end before_calling_suite;


overriding member procedure after_calling_test(self in out nocopy ut_tap_reporter, a_test ut_test) as
l_message varchar2(4000);
l_test_name varchar2(4000) := self.escape_special_chars(coalesce(a_test.description, a_test.name));

procedure print_failed_expectation(a_test ut_test) is
l_lines ut_varchar2_list;
l_failed boolean;
begin
if a_test.get_error_stack_traces().count = 0 then
-- If no error occurred, print failed expectation
l_lines := a_test.all_expectations(a_test.all_expectations.last).get_result_lines();
l_failed := a_test.all_expectations(a_test.all_expectations.last).status >= ut_utils.gc_success;
if l_failed then
self.print_text('message: ''' || l_lines(1) || '''');
self.print_text('severity: fail');
end if;
else
-- Print multi-line YAML-String with implicit newline characters
self.print_text('message: |');
self.lvl := self.lvl + 1;
self.print_text(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
self.lvl := self.lvl - 1;
self.print_text('severity: error');
end if;
end print_failed_expectation;

begin

if a_test.result = ut_utils.gc_disabled then
self.print_text('ok - ' || l_test_name || ' # SKIP'||
case when a_test.disabled_reason is not null
then ': '|| self.escape_special_chars(a_test.disabled_reason)
else null
end );
elsif a_test.result = ut_utils.gc_success then
self.print_text('ok - ' || l_test_name);
elsif a_test.result > ut_utils.gc_success then
if self.lvl = 0 then
self.print_text(ut_ansiconsole_helper.red('not ok') || ' - ' || l_test_name);
else
self.print_text('not ok - ' || l_test_name);
end if;
self.lvl := self.lvl + 1;
self.print_text('---');
print_failed_expectation(a_test);
self.print_text('...');
self.lvl := self.lvl - 1;
end if;

self.print_comment(a_test.get_serveroutputs);

end after_calling_test;

overriding member procedure after_calling_before_all(self in out nocopy ut_tap_reporter, a_executable in ut_executable) is
begin
if a_executable.serveroutput is not null and a_executable.serveroutput != empty_clob() then
self.print_comment(a_executable.serveroutput);
end if;
end after_calling_before_all;

overriding member procedure after_calling_after_all(self in out nocopy ut_tap_reporter, a_executable in ut_executable) is
begin
if a_executable.serveroutput is not null and a_executable.serveroutput != empty_clob() then
self.print_comment(a_executable.serveroutput);
end if;
end after_calling_after_all;

overriding member procedure after_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite) as
l_suite_name varchar2(4000) := coalesce(a_suite.description, a_suite.name);
begin
lvl := lvl - 2;
if lvl = 0 then
if a_suite.result = ut_utils.gc_success or a_suite.result = ut_utils.gc_disabled then
self.print_text('ok - ' || self.escape_special_chars(l_suite_name));
elsif a_suite.result > ut_utils.gc_success then
self.print_text(ut_ansiconsole_helper.red('not ok') || ' - ' || self.escape_special_chars(l_suite_name));
end if;

self.print_text(' ');
end if;

end after_calling_suite;

overriding member procedure before_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run) as
begin
self.print_text('TAP version 14');
self.print_text('1..' || a_run.items.count);
self.print_text(' ');
end before_calling_run;

overriding member procedure after_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run) as
begin
self.lvl := 0;
end;
end;
/
18 changes: 18 additions & 0 deletions source/reporters/ut_tap_reporter.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
create or replace type ut_tap_reporter under ut_documentation_reporter(

constructor function ut_tap_reporter(self in out nocopy ut_tap_reporter) return self as result,
member procedure print_comment(self in out nocopy ut_tap_reporter, a_comment clob),
member function escape_special_chars(self in out nocopy ut_tap_reporter, a_string_to_escape clob) return clob,
overriding member procedure before_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite),

overriding member procedure after_calling_test(self in out nocopy ut_tap_reporter, a_test ut_test),

overriding member procedure after_calling_before_all (self in out nocopy ut_tap_reporter, a_executable in ut_executable),
overriding member procedure after_calling_after_all (self in out nocopy ut_tap_reporter, a_executable in ut_executable),
overriding member procedure before_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run),
overriding member procedure after_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite),
overriding member procedure after_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run)

)
not final
/
2 changes: 2 additions & 0 deletions test/install_ut3_user_tests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set define off
@@ut3_user/reporters/test_documentation_reporter.pks
@@ut3_user/reporters/test_debug_reporter.pks
@@ut3_user/reporters/test_realtime_reporter.pks
@@ut3_user/reporters/test_tap_reporter.pks
@@ut3_user/reporters/test_coverage.pks
@@ut3_user/reporters/test_coverage/test_coverage_standalone.pks
set define on
Expand Down Expand Up @@ -86,6 +87,7 @@ set define off
@@ut3_user/reporters/test_documentation_reporter.pkb
@@ut3_user/reporters/test_debug_reporter.pkb
@@ut3_user/reporters/test_realtime_reporter.pkb
@@ut3_user/reporters/test_tap_reporter.pkb
@@ut3_user/reporters/test_coverage/test_coverage_standalone.pkb
set define on
@@ut3_user/reporters/test_coverage/test_extended_coverage.pkb
Expand Down
3 changes: 2 additions & 1 deletion test/ut3_user/api/test_ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ end;';
select 'UT3_DEVELOP.UT_SONAR_TEST_REPORTER', 'Y' from dual union all
select 'UT3_DEVELOP.UT_TEAMCITY_REPORTER', 'Y' from dual union all
select 'UT3_DEVELOP.UT_TFS_JUNIT_REPORTER', 'Y' from dual union all
select 'UT3_DEVELOP.UT_XUNIT_REPORTER', 'Y' from dual
select 'UT3_DEVELOP.UT_XUNIT_REPORTER', 'Y' from dual union all
select 'UT3_DEVELOP.UT_TAP_REPORTER', 'Y' from dual
order by 1;
--Act
open l_actual for select * from table(ut3_develop.ut_runner.GET_REPORTERS_LIST()) order by 1;
Expand Down
Loading