Skip to content
Merged
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
106 changes: 60 additions & 46 deletions source/reporters/ut_sonar_test_reporter.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,75 @@ create or replace type body ut_sonar_test_reporter is
return;
end;

overriding member procedure before_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run) is
begin
self.file_mappings := coalesce(a_run.test_file_mappings,ut_file_mappings());
self.print_text('<testExecutions version="1">');
end;
overriding member procedure after_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run) is

overriding member procedure before_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite) is
function map_package_to_file(a_suite ut_suite, a_file_mappings ut_file_mappings) return varchar2 is
l_file_name varchar2(4000);
begin
for i in 1 .. self.file_mappings.count loop
if upper(self.file_mappings(i).object_name) = upper(a_suite.object_name)
and upper(self.file_mappings(i).object_owner) = upper(a_suite.object_owner) then
l_file_name := self.file_mappings(i).file_name;
exit;
begin
if a_file_mappings is not null then
for i in 1 .. a_file_mappings.count loop
if upper(a_file_mappings(i).object_name) = upper(a_suite.object_name)
and upper(a_file_mappings(i).object_owner) = upper(a_suite.object_owner) then
l_file_name := a_file_mappings(i).file_name;
exit;
end if;
end loop;
end if;
end loop;
l_file_name := coalesce(l_file_name, a_suite.path);
self.print_text('<file path="'||l_file_name||'">');
end;
return coalesce(l_file_name, a_suite.path);
end;

overriding member procedure after_calling_test(self in out nocopy ut_sonar_test_reporter, a_test ut_test) is
l_message varchar2(32757);
l_lines ut_varchar2_list;
begin
self.print_text('<testCase name="'||a_test.name||'" duration="'||round(a_test.execution_time()*1000,0)||'" >');
if a_test.result = ut_utils.tr_disabled then
self.print_text('<skipped message="skipped"/>');
elsif a_test.result = ut_utils.tr_error then
self.print_text('<error message="encountered errors">');
self.print_text('<![CDATA[');
self.print_clob(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
self.print_text(']]>');
self.print_text('</error>');
elsif a_test.result > ut_utils.tr_success then
self.print_text('<failure message="some expectations have failed">');
self.print_text('<![CDATA[');
for i in 1 .. a_test.results.count loop
l_lines := a_test.results(i).get_result_lines();
for i in 1 .. l_lines.count loop
self.print_text(l_lines(i));
procedure print_test_results(a_test ut_test) is
l_lines ut_varchar2_list;
begin
self.print_text('<testCase name="'||a_test.name||'" duration="'||round(a_test.execution_time()*1000,0)||'" >');
if a_test.result = ut_utils.tr_disabled then
self.print_text('<skipped message="skipped"/>');
elsif a_test.result = ut_utils.tr_error then
self.print_text('<error message="encountered errors">');
self.print_text('<![CDATA[');
self.print_clob(ut_utils.table_to_clob(a_test.get_error_stack_traces()));
self.print_text(']]>');
self.print_text('</error>');
elsif a_test.result > ut_utils.tr_success then
self.print_text('<failure message="some expectations have failed">');
self.print_text('<![CDATA[');
for i in 1 .. a_test.results.count loop
l_lines := a_test.results(i).get_result_lines();
for i in 1 .. l_lines.count loop
self.print_text(l_lines(i));
end loop;
end loop;
self.print_text(']]>');
self.print_text('</failure>');
end if;
self.print_text('</testCase>');
end;

procedure print_suite_results(a_suite ut_logical_suite, a_file_mappings ut_file_mappings) is
begin
for i in 1 .. a_suite.items.count loop
if a_suite.items(i) is of(ut_logical_suite) then
print_suite_results(treat(a_suite.items(i) as ut_logical_suite), a_file_mappings);
end if;
end loop;
self.print_text(']]>');
self.print_text('</failure>');
end if;
self.print_text('</testCase>');
end;
if a_suite is of(ut_suite) then
self.print_text('<file path="'||map_package_to_file(treat(a_suite as ut_suite), a_file_mappings)||'">');

overriding member procedure after_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite) is
begin
self.print_text('</file>');
end;
for i in 1 .. a_suite.items.count loop
if a_suite.items(i) is of(ut_test) then
print_test_results(treat(a_suite.items(i) as ut_test));
end if;
end loop;
self.print_text('</file>');
end if;
end;

overriding member procedure after_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run) is
begin
self.print_text('<testExecutions version="1">');
for i in 1 .. a_run.items.count loop
print_suite_results(treat(a_run.items(i) as ut_logical_suite), a_run.test_file_mappings);
end loop;

self.print_text('</testExecutions>');
end;

Expand Down
5 changes: 0 additions & 5 deletions source/reporters/ut_sonar_test_reporter.tps
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ create or replace type ut_sonar_test_reporter under ut_reporter_base(
See the License for the specific language governing permissions and
limitations under the License.
*/
file_mappings ut_file_mappings,

constructor function ut_sonar_test_reporter(
self in out nocopy ut_sonar_test_reporter
) return self as result,

overriding member procedure before_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run),
overriding member procedure before_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite),
overriding member procedure after_calling_test(self in out nocopy ut_sonar_test_reporter, a_test ut_test),
overriding member procedure after_calling_suite(self in out nocopy ut_sonar_test_reporter, a_suite ut_logical_suite),
overriding member procedure after_calling_run(self in out nocopy ut_sonar_test_reporter, a_run in ut_run)
)
not final
Expand Down
26 changes: 16 additions & 10 deletions source/reporters/ut_teamcity_reporter.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ create or replace type body ut_teamcity_reporter is

overriding member procedure before_calling_suite(self in out nocopy ut_teamcity_reporter, a_suite in ut_logical_suite) is
begin
self.print_text(ut_teamcity_reporter_helper.test_suite_started(a_suite_name => nvl(replace(trim(a_suite.description)
,'.')
,a_suite.name)));
self.print_text(
ut_teamcity_reporter_helper.test_suite_started(
a_suite_name => nvl(replace(trim(a_suite.description),'.'),a_suite.path)
)
);
end;

overriding member procedure after_calling_suite(self in out nocopy ut_teamcity_reporter, a_suite in ut_logical_suite) is
begin
self.print_text(ut_teamcity_reporter_helper.test_suite_finished(a_suite_name => nvl(replace(trim(a_suite.description)
,'.')
,a_suite.name)));
self.print_text(
ut_teamcity_reporter_helper.test_suite_finished(
a_suite_name => nvl(replace(trim(a_suite.description),'.'),a_suite.path)
)
);
end;

overriding member procedure before_calling_test(self in out nocopy ut_teamcity_reporter, a_test in ut_test) is
Expand All @@ -43,8 +47,12 @@ create or replace type body ut_teamcity_reporter is
l_test_full_name := lower(a_test.item.owner_name) || '.' || lower(a_test.item.object_name) || '.' ||
lower(a_test.item.procedure_name);

self.print_text(ut_teamcity_reporter_helper.test_started(a_test_name => l_test_full_name
,a_capture_standard_output => true));
self.print_text(
ut_teamcity_reporter_helper.test_started(
a_test_name => l_test_full_name,
a_capture_standard_output => true
)
);

end;

Expand All @@ -53,8 +61,6 @@ create or replace type body ut_teamcity_reporter is
l_test_full_name varchar2(4000);
l_std_err_msg varchar2(32767);
begin
-- l_test_full_name := self.suite_names_stack(self.suite_names_stack.last) || ':' ||
-- nvl(replace(a_test.description, '.'), a_test.name);
l_test_full_name := lower(a_test.item.owner_name) || '.' || lower(a_test.item.object_name) || '.' ||
lower(a_test.item.procedure_name);

Expand Down
35 changes: 1 addition & 34 deletions source/reporters/ut_teamcity_reporter_helper.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ create or replace package body ut_teamcity_reporter_helper is

end message;

-- function block_opened(a_name varchar2, a_flow_id varchar2 default null) return varchar2 is
-- l_props t_props;
-- begin
-- l_props('name') := a_name;
-- l_props('flowId') := a_flow_id;
-- return message('blockOpened', l_props);
-- end;
--
-- function block_closed(a_name varchar2, a_flow_id varchar2 default null) return varchar2 is
-- l_props t_props;
-- begin
-- l_props('name') := a_name;
-- l_props('flowId') := a_flow_id;
-- return message('blockClosed', l_props);
-- end;
--
function test_suite_started(a_suite_name varchar2, a_flow_id varchar2 default null) return varchar2 is
l_props t_props;
begin
Expand Down Expand Up @@ -123,14 +107,7 @@ create or replace package body ut_teamcity_reporter_helper is

return message('testFailed', l_props);
end;
-- function test_std_out(a_test_name varchar2, a_out in varchar2, a_flow_id in varchar2 default null) return varchar2 is
-- l_props t_props;
-- begin
-- l_props('name') := a_test_name;
-- l_props('out') := a_out;
-- l_props('flowId') := a_flow_id;
-- return message('testStdOut', l_props);
-- end;

function test_std_err(a_test_name varchar2, a_out in varchar2, a_flow_id in varchar2 default null) return varchar2 is
l_props t_props;
begin
Expand All @@ -140,15 +117,5 @@ create or replace package body ut_teamcity_reporter_helper is
return message('testStdErr', l_props);
end;

-- function custom_message(a_text in varchar2, a_status in varchar2, a_error_deatils in varchar2 default null, a_flow_id in varchar2 default null) return varchar2 is
-- l_props t_props;
-- begin
-- l_props('text') := a_text;
-- l_props('status') := a_status;
-- l_props('errorDetails') := a_error_deatils;
-- l_props('flowId') := a_flow_id;
-- return message('message', l_props);
-- end;

end ut_teamcity_reporter_helper;
/
6 changes: 0 additions & 6 deletions source/reporters/ut_teamcity_reporter_helper.pks
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ create or replace package ut_teamcity_reporter_helper is
limitations under the License.
*/

-- function block_opened(a_name varchar2, a_flow_id varchar2 default null) return varchar2;
-- function block_closed(a_name varchar2, a_flow_id varchar2 default null) return varchar2;

function test_suite_started(a_suite_name varchar2, a_flow_id varchar2 default null) return varchar2;
function test_suite_finished(a_suite_name varchar2, a_flow_id varchar2 default null) return varchar2;

function test_started(a_test_name varchar2, a_capture_standard_output boolean default null, a_flow_id varchar2 default null) return varchar2;
function test_finished(a_test_name varchar2, a_test_duration_milisec number default null, a_flow_id varchar2 default null) return varchar2;
function test_disabled(a_test_name varchar2, a_flow_id varchar2 default null) return varchar2;
function test_failed(a_test_name varchar2, a_msg in varchar2 default null, a_details varchar2 default null, a_flow_id varchar2 default null, a_actual varchar2 default null, a_expected varchar2 default null) return varchar2;
-- function test_std_out(a_test_name varchar2, a_out in varchar2, a_flow_id in varchar2 default null) return varchar2;
function test_std_err(a_test_name varchar2, a_out in varchar2, a_flow_id in varchar2 default null) return varchar2;

-- function custom_message(a_text in varchar2, a_status in varchar2, a_error_deatils in varchar2 default null, a_flow_id in varchar2 default null) return varchar2;

end ut_teamcity_reporter_helper;
/
2 changes: 1 addition & 1 deletion tests/helpers/test_reporters.pks
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
create or replace package test_reporters
as
--%suite(A suite for testing different outcomes from reporters)

--%suitepath(org.utplsql.utplsql.test)
--%beforeall
procedure beforeall;

Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/test_reporters_1.pks
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
create or replace package test_reporters_1
as
--%suite(A suite for testing html coverage options)

--%suitepath(org.utplsql.utplsql.test.test_reporters)

--%test(a test calling package outside schema)
procedure diffrentowner_test;

Expand Down
6 changes: 3 additions & 3 deletions tests/ut/ut.run.AcceptsSutePaths.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ begin
dbms_output.get_lines( l_output_data, l_num_lines);

for i in 1 .. l_num_lines loop
if l_output_data(i) like '%Finished %''test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''test_package_2''%'
or l_output_data(i) like '%Finished %''test_package_3''%' then
if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''%test_package_2''%'
or l_output_data(i) like '%Finished %''%test_package_3''%' then
l_packages_executed := l_packages_executed + 1;
end if;
end loop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ begin
dbms_output.get_lines( l_output_data, l_num_lines);

for i in 1 .. l_num_lines loop
if l_output_data(i) like '%Finished %''test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''test_package_2''%'
or l_output_data(i) like '%Finished %''test_package_3''%' then
if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''%test_package_2''%'
or l_output_data(i) like '%Finished %''%test_package_3''%' then
l_packages_executed := l_packages_executed + 1;
end if;
end loop;
Expand Down
6 changes: 3 additions & 3 deletions tests/ut/ut.run.function.AcceptsSutePaths.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ begin
from table(ut.run(ut_varchar2_list('test_package_1','test_package_3'),ut_teamcity_reporter()));

for i in 1 .. l_output_data.count loop
if l_output_data(i) like '%Finished %''test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''test_package_2''%'
or l_output_data(i) like '%Finished %''test_package_3''%' then
if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''%test_package_2''%'
or l_output_data(i) like '%Finished %''%test_package_3''%' then
l_packages_executed := l_packages_executed + 1;
end if;
end loop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ begin
from table(ut.run(ut_teamcity_reporter()));

for i in 1 .. l_output_data.count loop
if l_output_data(i) like '%Finished %''test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''test_package_2''%'
or l_output_data(i) like '%Finished %''test_package_3''%' then
if l_output_data(i) like '%Finished %''%test\_package\_1''%' escape '\'
or l_output_data(i) like '%Finished %''%test_package_2''%'
or l_output_data(i) like '%Finished %''%test_package_3''%' then
l_packages_executed := l_packages_executed + 1;
end if;
end loop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ begin
%ORA-06502%
%ORA-06512%
Finished %
4 tests, 1 failed, 1 errored%]';
5 tests, 1 failed, 1 errored%]';

--act
select *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ declare
l_expected varchar2(32767);
begin
l_expected := q'[<testExecutions version="1">
<file path="tests/helpers/test_reporters_1.pkb">
<testCase name="diffrentowner_test" duration="%" >%</testCase>
</file>
<file path="tests/helpers/test_reporters.pkb">
<testCase name="passing_test" duration="%" >%</testCase>
<testCase name="failing_test" duration="%" >%<failure message="some expectations have failed">%</failure>%</testCase>
Expand All @@ -19,7 +22,7 @@ begin
ut.run(
'test_reporters',
ut_sonar_test_reporter(),
a_test_file_mappings => ut_file_mapper.build_file_mappings( user, ut_varchar2_list('tests/helpers/test_reporters.pkb'))
a_test_file_mappings => ut_file_mapper.build_file_mappings( user, ut_varchar2_list('tests/helpers/test_reporters.pkb', 'tests/helpers/test_reporters_1.pkb'))
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ declare
l_expected varchar2(32767);
begin
l_expected := q'[<testExecutions version="1">
<file path="tests/helpers/test_reporters_1.pkb">
<testCase name="diffrentowner_test" duration="%" >%</testCase>
</file>
<file path="tests/helpers/test_reporters.pkb">
<testCase name="passing_test" duration="%" >%</testCase>
<testCase name="failing_test" duration="%" >%<failure message="some expectations have failed">%</failure>%</testCase>
Expand All @@ -15,7 +18,7 @@ begin
--act
select *
bulk collect into l_output_data
from table(ut.run('test_reporters',ut_sonar_test_reporter(),a_source_files=> null, a_test_files=>ut_varchar2_list('tests/helpers/test_reporters.pkb')));
from table(ut.run('test_reporters',ut_sonar_test_reporter(),a_source_files=> null, a_test_files=>ut_varchar2_list('tests/helpers/test_reporters.pkb', 'tests/helpers/test_reporters_1.pkb')));

l_output := ut_utils.table_to_clob(l_output_data);

Expand Down
Loading