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

Skip to content

Commit 7e4c170

Browse files
committed
Refactored documentation_reporter. It doesnt store the failed tests anymore, it only counts them and the after_run method is now working fully on the list of executed suites that were passed to the reporter.
1 parent eee6bbd commit 7e4c170

2 files changed

Lines changed: 69 additions & 48 deletions

File tree

source/reporters/ut_documentation_reporter.tpb

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ create or replace type body ut_documentation_reporter is
55
self.name := $$plsql_unit;
66
self.output := a_output;
77
self.lvl := 0;
8-
self.failed_tests := ut_objects_list();
8+
self.failed_test_count := 0;
99
self.test_count := 0;
1010
self.igonred_test_count := 0;
1111
return;
@@ -42,9 +42,8 @@ create or replace type body ut_documentation_reporter is
4242
l_message := coalesce( l_test.name, l_test.test.form_name );
4343
--if test failed, then add it to the failures list, print failure with number
4444
if l_test.result != ut_utils.tr_success then
45-
failed_tests.extend;
46-
failed_tests(failed_tests.last) := l_test;
47-
l_message := l_message || ' (FAILED - '||failed_tests.last||')';
45+
failed_test_count := failed_test_count + 1;
46+
l_message := l_message || ' (FAILED - '||failed_test_count||')';
4847
end if;
4948
self.print( l_message );
5049
end;
@@ -59,54 +58,76 @@ create or replace type body ut_documentation_reporter is
5958
overriding member procedure after_run(self in out nocopy ut_documentation_reporter, a_suites in ut_objects_list) as
6059
l_start_time timestamp with time zone := to_date('9999','yyyy');
6160
l_end_time timestamp with time zone := to_date('0001','yyyy');
61+
62+
procedure print_failure_for_assert(a_assert ut_assert_result) is
63+
begin
64+
if a_assert.result != ut_utils.tr_success then
65+
if a_assert.message is not null then
66+
self.print('message: '||a_assert.message);
67+
end if;
68+
if a_assert.result != ut_utils.tr_success then
69+
if a_assert.actual_value_string is not null or a_assert.actual_type is not null then
70+
self.print('expected: '||ut_utils.indent_lines( a_assert.actual_value_string||'('||a_assert.actual_type||')', self.lvl*2+length('expected: ') ) );
71+
end if;
72+
if a_assert.name is not null or a_assert.additional_info is not null
73+
or a_assert.expected_value_string is not null or a_assert.expected_type is not null then
74+
self.print(
75+
a_assert.name || a_assert.additional_info
76+
|| case
77+
when a_assert.expected_value_string is not null or a_assert.expected_type is not null
78+
then ': '||ut_utils.indent_lines( a_assert.expected_value_string||'('||a_assert.expected_type||')', self.lvl*2+length(a_assert.name || a_assert.additional_info||': ') )
79+
end
80+
);
81+
end if;
82+
end if;
83+
if a_assert.error_message is not null then
84+
self.print('error: '||ut_utils.indent_lines( a_assert.error_message, self.lvl*2+length('error: ') ) );
85+
end if;
86+
if a_assert.caller_info is not null then
87+
self.print(a_assert.caller_info);
88+
end if;
89+
self.print('');
90+
end if;
91+
end;
92+
93+
procedure print_failures_for_test(a_test ut_test, a_failure_no in out nocopy integer) is
94+
begin
95+
if a_test.result != ut_utils.tr_success then
96+
a_failure_no := a_failure_no + 1;
97+
self.print(lpad(a_failure_no, 4,' ')||') '||coalesce( a_test.name, a_test.test.form_name ));
98+
self.lvl := self.lvl + 3;
99+
self.print('Failures/Errors:');
100+
self.lvl := self.lvl + 1;
101+
for j in 1 .. a_test.items.count loop
102+
print_failure_for_assert(treat(a_test.items(j) as ut_assert_result));
103+
end loop;
104+
lvl := lvl - 4;
105+
end if;
106+
end;
107+
108+
procedure print_failures_from_suite(a_suite ut_test_suite, a_failure_no in out nocopy integer) is
109+
begin
110+
for i in 1 .. a_suite.items.count loop
111+
if a_suite.items(i) is of (ut_test_suite) then
112+
print_failures_from_suite(treat( a_suite.items(i) as ut_test_suite), a_failure_no);
113+
elsif a_suite.items(i) is of (ut_test) then
114+
print_failures_for_test(treat(a_suite.items(i) as ut_test), a_failure_no);
115+
end if;
116+
end loop;
117+
end;
118+
62119
procedure print_failures_summary is
63-
l_assert ut_assert_result;
64-
l_test ut_test;
120+
l_failure_no integer := 0;
65121
begin
66-
if failed_tests.count > 0 then
122+
if failed_test_count > 0 then
67123

68124
self.print( 'Failures:' );
69-
70-
for i in 1 .. failed_tests.count loop
71-
l_test := treat(failed_tests(i) as ut_test);
72-
self.print(lpad(i, 4,' ')||') '||coalesce( l_test.name, l_test.test.form_name ));
73-
lvl := lvl + 3;
74-
self.print('Failures/Errors:');
75-
lvl := lvl + 1;
76-
for j in 1 .. l_test.items.count loop
77-
l_assert := treat(l_test.items(j) as ut_assert_result);
78-
if l_assert.result != ut_utils.tr_success then
79-
if l_assert.message is not null then
80-
self.print('message: '||l_assert.message);
81-
end if;
82-
if l_assert.result != ut_utils.tr_success then
83-
if l_assert.actual_value_string is not null or l_assert.actual_type is not null then
84-
self.print('expected: '||ut_utils.indent_lines( l_assert.actual_value_string||'('||l_assert.actual_type||')', self.lvl*2+length('expected: ') ) );
85-
end if;
86-
if l_assert.name is not null or l_assert.additional_info is not null
87-
or l_assert.expected_value_string is not null or l_assert.expected_type is not null then
88-
self.print(
89-
l_assert.name || l_assert.additional_info
90-
|| case
91-
when l_assert.expected_value_string is not null or l_assert.expected_type is not null
92-
then ': '||ut_utils.indent_lines( l_assert.expected_value_string||'('||l_assert.expected_type||')', self.lvl*2+length(l_assert.name || l_assert.additional_info||': ') )
93-
end
94-
);
95-
end if;
96-
end if;
97-
if l_assert.error_message is not null then
98-
self.print('error: '||ut_utils.indent_lines( l_assert.error_message, self.lvl*2+length('error: ') ) );
99-
end if;
100-
if l_assert.caller_info is not null then
101-
self.print(l_assert.caller_info);
102-
end if;
103-
self.print('');
104-
end if;
105-
end loop;
106-
lvl := lvl - 4;
125+
for i in 1 .. a_suites.count loop
126+
print_failures_from_suite(treat(a_suites(i) as ut_test_suite), l_failure_no);
107127
end loop;
108128
end if;
109129
end;
130+
110131
begin
111132
print_failures_summary();
112133
for i in 1 .. a_suites.count loop
@@ -117,8 +138,8 @@ create or replace type body ut_documentation_reporter is
117138
self.print(
118139
test_count || ' tests' ||
119140
case
120-
when failed_tests.count > 1 then ', '||failed_tests.count||' failures'
121-
when failed_tests.count > 0 then ', '||failed_tests.count||' failure'
141+
when failed_test_count > 1 then ', '||failed_test_count||' failures'
142+
when failed_test_count > 0 then ', '||failed_test_count||' failure'
122143
end ||
123144
case
124145
when igonred_test_count > 0 then ', '||igonred_test_count||' ignored'

source/reporters/ut_documentation_reporter.tps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
create or replace type ut_documentation_reporter force under ut_reporter
22
(
33
lvl integer,
4-
failed_tests ut_objects_list,
54
test_count integer,
5+
failed_test_count integer,
66
igonred_test_count integer,
77
constructor function ut_documentation_reporter(self in out nocopy ut_documentation_reporter, a_output ut_output default ut_output_dbms_output()) return self as result,
88
member function tab(self in ut_documentation_reporter) return varchar2,

0 commit comments

Comments
 (0)