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
fixed ut_run.sql to execute files from working folder
enhanced Teamcity reporter
  • Loading branch information
Pazus committed Mar 11, 2017
commit 483b4fca3c1aac68099b603e80a0d91c513fc44f
4 changes: 2 additions & 2 deletions client_source/sqlplus/ut_run.sql
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ set define &
/*
* Make SQLPlus parameters optional and pass parameters call to param_list variable
*/
@@define_params_variable.sql.tmp
@define_params_variable.sql.tmp



Expand Down Expand Up @@ -290,8 +290,8 @@ begin
p(' v_reporter.reporter_id := '''||l_reporter_id||''';');
p(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;');
end loop;
close :l_run_params_cur;
end if;
close :l_run_params_cur;
p( ' ut_runner.run( ut_varchar2_list('||:l_paths||'), v_reporters_list, a_color_console => '||:l_color_enabled||' );');
p( 'end;');
p( '/');
Expand Down
100 changes: 63 additions & 37 deletions source/reporters/ut_teamcity_reporter.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ create or replace type body ut_teamcity_reporter is
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -24,84 +24,110 @@ 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.name)));
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.name)));
end;

overriding member procedure before_calling_test(self in out nocopy ut_teamcity_reporter, a_test in ut_test) is
l_test_full_name varchar2(4000);
begin

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));


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));

end;

overriding member procedure after_calling_test(self in out nocopy ut_teamcity_reporter, a_test in ut_test) is
l_assert ut_assert_result;
l_test_full_name varchar2(4000);
l_assert ut_assert_result;
l_test_full_name varchar2(4000);
procedure print_output(a_exectable ut_executable) is
l_lines ut_varchar2_list;
begin
if a_exectable is not null and a_exectable.is_defined and a_exectable.serveroutput is not null and dbms_lob.getlength(a_exectable.serveroutput) > 0 then
if a_exectable is not null and a_exectable.is_defined and a_exectable.serveroutput is not null and
dbms_lob.getlength(a_exectable.serveroutput) > 0 then
l_lines := ut_utils.clob_to_table(a_exectable.serveroutput);
for i in 1..l_lines.count loop
for i in 1 .. l_lines.count loop
self.print_text(l_lines(i));
end loop;
end if;
end;
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);

-- 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);

if a_test.result = ut_utils.tr_ignore then
self.print_text(ut_teamcity_reporter_helper.test_ignored(l_test_full_name));
else

-- reproduce the output from before/after procedures and the test
print_output(a_test.before_each);
print_output(a_test.before_test);
print_output(a_test.item);
print_output(a_test.after_test);
print_output(a_test.after_each);

if a_test.results is not null and a_test.results.count > 0 then

if a_test.result = ut_utils.tr_error then
self.print_text(ut_teamcity_reporter_helper.test_std_err(a_test_name => l_test_full_name
,a_out => coalesce(a_test.before_each.error_backtrace
,a_test.before_test.error_backtrace
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.

If both before_test and after_test will throw, then we will not show the stacktrace from the after block.

,a_test.item.error_backtrace
,a_test.after_test.error_backtrace
,a_test.after_each.error_backtrace)));
self.print_text(ut_teamcity_reporter_helper.test_failed(a_test_name => l_test_full_name
,a_msg => 'Test failed with an exception'
,a_details => coalesce(a_test.before_each.error_stack
,a_test.before_test.error_stack
,a_test.item.error_stack
,a_test.after_test.error_stack
,a_test.after_each.error_stack)));
elsif a_test.results is not null and a_test.results.count > 0 then
for i in 1 .. a_test.results.count loop

l_assert := a_test.results(i);

if l_assert.result > ut_utils.tr_success then
self.print_text(ut_teamcity_reporter_helper.test_failed(a_test_name => l_test_full_name
,a_msg => l_assert.message
,a_expected => l_assert.expected_value_string
,a_actual => l_assert.actual_value_string));
,a_expected => case
when l_assert.matcher_name in
('equal', 'be false', 'be true') then
l_assert.expected_value_string
end
,a_actual => case
when l_assert.matcher_name in
('equal', 'be false', 'be true') then
l_assert.actual_value_string
end));
-- Teamcity supports only a single failure message
exit;
end if;

end loop;
elsif a_test.result = ut_utils.tr_failure then
self.print_text(ut_teamcity_reporter_helper.test_failed(a_test_name => l_test_full_name, a_msg => 'Test failed'));
self.print_text(ut_teamcity_reporter_helper.test_failed(a_test_name => l_test_full_name
,a_msg => 'Test failed'));
elsif a_test.result = ut_utils.tr_error then
self.print_text(ut_teamcity_reporter_helper.test_failed(a_test_name => l_test_full_name, a_msg => 'Error occured'));
self.print_text(ut_teamcity_reporter_helper.test_failed(a_test_name => l_test_full_name
,a_msg => 'Error occured'));
end if;

self.print_text(ut_teamcity_reporter_helper.test_finished(l_test_full_name, trunc(a_test.execution_time * 1e3)));

end if;

end;

end;
Expand Down
4 changes: 2 additions & 2 deletions source/reporters/ut_teamcity_reporter_helper.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ create or replace package body ut_teamcity_reporter_helper is

function escape_value(a_value in varchar2) return varchar2 is
begin
return regexp_replace(a_value, '(''|"|' || chr(13) || '|' || chr(10) || '|[|])', '|\1');
return translate(regexp_replace(a_value, '(''|"|[|]|' || chr(13) || '|' || chr(10) || ')', '|\1'),chr(13)||chr(10),'nr');
end;

function message(a_command in varchar2, a_props t_props default cast(null as t_props)) return varchar2 is
Expand All @@ -30,7 +30,7 @@ create or replace package body ut_teamcity_reporter_helper is
l_value varchar2(32767);
begin
l_message := '##teamcity[' || a_command || ' timestamp=''' ||
regexp_replace(to_char(systimestamp, 'YYYY-MM-DD"T"HH24:MI:ss.FFTZHTZM'), '(\.\d{3})\d+(\+)', '\1\2') || '''';
regexp_replace(to_char(systimestamp, 'YYYY-MM-DD"T"HH24:MI:ss.FF3TZHTZM'), '(\.\d{3})\d+(\+)', '\1\2') || '''';

l_index := a_props.first;
while l_index is not null loop
Expand Down