Skip to content

Commit 7ce1909

Browse files
authored
Merge pull request #1305 from WayneNani/feature/add-tap-reporter
Add TAP reporter
2 parents c36fbb3 + 18af6b0 commit 7ce1909

File tree

13 files changed

+471
-1
lines changed

13 files changed

+471
-1
lines changed
35.3 KB
Loading
43.9 KB
Loading
42.3 KB
Loading

docs/userguide/reporters.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ Details:
126126
utPLSQL comes with a set of build-in coverage reporters.
127127
[Code coverage](coverage.md) section describes in details how to use configure and use code coverage.
128128

129+
## TAP Reporter
130+
131+
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.
132+
133+
![tap_output_no_color](../images/tap_reporter_no_color.png)
134+
135+
If you use a compatible terminal, you can also have a colored result. Only top level `not ok`-results will be colored:
136+
137+
![tap_colored_output](../images/tap_reporter_colored.png)
138+
139+
Suites (and suitepaths) and contexts are included as [commented subtests](https://testanything.org/tap-version-14-specification.html#:~:text=Commented%20Subtests) including a summary of the tests performed for that specific context/suite. This example package has the suitepath "org.utplsql.tests.helpers":
140+
141+
![tap_include_suitepath](../images/tap_reporter_suitepath.png)
142+
129143
## Debug reporter
130144

131145
The `ut_debug_reporter` provides a highly verbose output containing thorough details about framework and test execution.

source/create_grants.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ grant execute on &&ut3_owner..ut_tfs_junit_reporter to &ut3_user;
104104
grant execute on &&ut3_owner..ut_documentation_reporter to &ut3_user;
105105
grant execute on &&ut3_owner..ut_sonar_test_reporter to &ut3_user;
106106
grant execute on &&ut3_owner..ut_realtime_reporter to &ut3_user;
107+
grant execute on &&ut3_owner..ut_tap_reporter to &ut3_user;
107108
--reporters - coverage
108109
grant execute on &&ut3_owner..ut_coverage_html_reporter to &ut3_user;
109110
grant execute on &&ut3_owner..ut_coverage_sonar_reporter to &ut3_user;

source/create_synonyms.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ create &action_type. synonym &ut3_user.ut_tfs_junit_reporter for &&ut3_owner..ut
119119
create &action_type. synonym &ut3_user.ut_documentation_reporter for &&ut3_owner..ut_documentation_reporter;
120120
create &action_type. synonym &ut3_user.ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter;
121121
create &action_type. synonym &ut3_user.ut_realtime_reporter for &&ut3_owner..ut_realtime_reporter;
122+
create &action_type. synonym &ut3_user.ut_tap_reporter for &&ut3_owner..ut_tap_reporter;
122123
--reporters - coverage
123124
create &action_type. synonym &ut3_user.ut_coverage_html_reporter for &&ut3_owner..ut_coverage_html_reporter;
124125
create &action_type. synonym &ut3_user.ut_coverage_sonar_reporter for &&ut3_owner..ut_coverage_sonar_reporter;

source/install.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ prompt Installing DBMSPLSQL Tables objects into &&ut3_owner schema
346346
@@install_component.sql 'reporters/ut_xunit_reporter.tpb'
347347
@@install_component.sql 'reporters/ut_sonar_test_reporter.tps'
348348
@@install_component.sql 'reporters/ut_sonar_test_reporter.tpb'
349+
@@install_component.sql 'reporters/ut_tap_reporter.tps'
350+
@@install_component.sql 'reporters/ut_tap_reporter.tpb'
349351

350352
@@install_component.sql 'reporters/ut_coverage_html_reporter.tps'
351353
@@install_component.sql 'reporters/ut_coverage_report_html_helper.pks'
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
create or replace type body ut_tap_reporter is
2+
3+
4+
constructor function ut_tap_reporter(self in out nocopy ut_tap_reporter) return self as result is
5+
begin
6+
self.init($$plsql_unit);
7+
self.lvl := 0;
8+
return;
9+
end ut_tap_reporter;
10+
11+
member procedure print_comment(self in out nocopy ut_tap_reporter, a_comment clob) as
12+
begin
13+
self.print_clob(regexp_replace(a_comment, '^', '# ', 1, 0, 'm'));
14+
end print_comment;
15+
16+
member function escape_special_chars(self in out nocopy ut_tap_reporter, a_string_to_escape clob) return clob as
17+
begin
18+
return regexp_replace(a_string_to_escape, '([\\#])', '\\\1');
19+
end escape_special_chars;
20+
21+
overriding member procedure before_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite) as
22+
begin
23+
self.print_text('# Subtest: ' || self.escape_special_chars(coalesce(a_suite.description, a_suite.name)));
24+
lvl := lvl + 2;
25+
self.print_text('1..' || a_suite.items.count);
26+
end before_calling_suite;
27+
28+
29+
overriding member procedure after_calling_test(self in out nocopy ut_tap_reporter, a_test ut_test) as
30+
l_message varchar2(4000);
31+
l_test_name varchar2(4000) := self.escape_special_chars(coalesce(a_test.description, a_test.name));
32+
33+
procedure print_failed_expectation(a_test ut_test) is
34+
l_lines ut_varchar2_list;
35+
l_failed boolean;
36+
begin
37+
if a_test.get_error_stack_traces().count = 0 then
38+
-- If no error occurred, print failed expectation
39+
l_lines := a_test.all_expectations(a_test.all_expectations.last).get_result_lines();
40+
l_failed := a_test.all_expectations(a_test.all_expectations.last).status >= ut_utils.gc_success;
41+
if l_failed then
42+
self.print_text('message: ''' || l_lines(1) || '''');
43+
self.print_text('severity: fail');
44+
end if;
45+
else
46+
-- Print multi-line YAML-String with implicit newline characters
47+
self.print_text('message: |');
48+
self.lvl := self.lvl + 1;
49+
self.print_text(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
50+
self.lvl := self.lvl - 1;
51+
self.print_text('severity: error');
52+
end if;
53+
end print_failed_expectation;
54+
55+
begin
56+
57+
if a_test.result = ut_utils.gc_disabled then
58+
self.print_text('ok - ' || l_test_name || ' # SKIP'||
59+
case when a_test.disabled_reason is not null
60+
then ': '|| self.escape_special_chars(a_test.disabled_reason)
61+
else null
62+
end );
63+
elsif a_test.result = ut_utils.gc_success then
64+
self.print_text('ok - ' || l_test_name);
65+
elsif a_test.result > ut_utils.gc_success then
66+
if self.lvl = 0 then
67+
self.print_text(ut_ansiconsole_helper.red('not ok') || ' - ' || l_test_name);
68+
else
69+
self.print_text('not ok - ' || l_test_name);
70+
end if;
71+
self.lvl := self.lvl + 1;
72+
self.print_text('---');
73+
print_failed_expectation(a_test);
74+
self.print_text('...');
75+
self.lvl := self.lvl - 1;
76+
end if;
77+
78+
self.print_comment(a_test.get_serveroutputs);
79+
80+
end after_calling_test;
81+
82+
overriding member procedure after_calling_before_all(self in out nocopy ut_tap_reporter, a_executable in ut_executable) is
83+
begin
84+
if a_executable.serveroutput is not null and a_executable.serveroutput != empty_clob() then
85+
self.print_comment(a_executable.serveroutput);
86+
end if;
87+
end after_calling_before_all;
88+
89+
overriding member procedure after_calling_after_all(self in out nocopy ut_tap_reporter, a_executable in ut_executable) is
90+
begin
91+
if a_executable.serveroutput is not null and a_executable.serveroutput != empty_clob() then
92+
self.print_comment(a_executable.serveroutput);
93+
end if;
94+
end after_calling_after_all;
95+
96+
overriding member procedure after_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite) as
97+
l_suite_name varchar2(4000) := coalesce(a_suite.description, a_suite.name);
98+
begin
99+
lvl := lvl - 2;
100+
if lvl = 0 then
101+
if a_suite.result = ut_utils.gc_success or a_suite.result = ut_utils.gc_disabled then
102+
self.print_text('ok - ' || self.escape_special_chars(l_suite_name));
103+
elsif a_suite.result > ut_utils.gc_success then
104+
self.print_text(ut_ansiconsole_helper.red('not ok') || ' - ' || self.escape_special_chars(l_suite_name));
105+
end if;
106+
107+
self.print_text(' ');
108+
end if;
109+
110+
end after_calling_suite;
111+
112+
overriding member procedure before_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run) as
113+
begin
114+
self.print_text('TAP version 14');
115+
self.print_text('1..' || a_run.items.count);
116+
self.print_text(' ');
117+
end before_calling_run;
118+
119+
overriding member procedure after_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run) as
120+
begin
121+
self.lvl := 0;
122+
end;
123+
end;
124+
/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
create or replace type ut_tap_reporter under ut_documentation_reporter(
2+
3+
constructor function ut_tap_reporter(self in out nocopy ut_tap_reporter) return self as result,
4+
member procedure print_comment(self in out nocopy ut_tap_reporter, a_comment clob),
5+
member function escape_special_chars(self in out nocopy ut_tap_reporter, a_string_to_escape clob) return clob,
6+
overriding member procedure before_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite),
7+
8+
overriding member procedure after_calling_test(self in out nocopy ut_tap_reporter, a_test ut_test),
9+
10+
overriding member procedure after_calling_before_all (self in out nocopy ut_tap_reporter, a_executable in ut_executable),
11+
overriding member procedure after_calling_after_all (self in out nocopy ut_tap_reporter, a_executable in ut_executable),
12+
overriding member procedure before_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run),
13+
overriding member procedure after_calling_suite(self in out nocopy ut_tap_reporter, a_suite ut_logical_suite),
14+
overriding member procedure after_calling_run(self in out nocopy ut_tap_reporter, a_run in ut_run)
15+
16+
)
17+
not final
18+
/

test/install_ut3_user_tests.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ set define off
4343
@@ut3_user/reporters/test_documentation_reporter.pks
4444
@@ut3_user/reporters/test_debug_reporter.pks
4545
@@ut3_user/reporters/test_realtime_reporter.pks
46+
@@ut3_user/reporters/test_tap_reporter.pks
4647
@@ut3_user/reporters/test_coverage.pks
4748
@@ut3_user/reporters/test_coverage/test_coverage_standalone.pks
4849
set define on
@@ -86,6 +87,7 @@ set define off
8687
@@ut3_user/reporters/test_documentation_reporter.pkb
8788
@@ut3_user/reporters/test_debug_reporter.pkb
8889
@@ut3_user/reporters/test_realtime_reporter.pkb
90+
@@ut3_user/reporters/test_tap_reporter.pkb
8991
@@ut3_user/reporters/test_coverage/test_coverage_standalone.pkb
9092
set define on
9193
@@ut3_user/reporters/test_coverage/test_extended_coverage.pkb

0 commit comments

Comments
 (0)