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

Skip to content

Commit 97f4fb8

Browse files
committed
addressed reviewer comments
1 parent 8eae19d commit 97f4fb8

5 files changed

Lines changed: 127 additions & 83 deletions

File tree

source/core/ut_suite_manager.pkb

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,26 @@ create or replace package body ut_suite_manager is
129129
l_proc_annotations := l_annotation_data.procedure_annotations(i).annotations;
130130
if l_proc_annotations.exists('test') then
131131
declare
132-
l_setup_procedure varchar2(30 char);
133-
l_teardown_procedure varchar2(30 char);
134-
l_rollback_annotation varchar2(4000);
135-
l_rollback_type integer := l_suite_rollback;
136-
l_displayname varchar2(4000);
132+
l_beforetest_procedure varchar2(30 char);
133+
l_aftertest_procedure varchar2(30 char);
134+
l_rollback_annotation varchar2(4000);
135+
l_rollback_type integer := l_suite_rollback;
136+
l_displayname varchar2(4000);
137137
begin
138138
if l_proc_annotations.exists('beforetest') then
139-
l_setup_procedure := ut_annotations.get_annotation_param(l_proc_annotations('beforetest'), 1);
139+
l_beforetest_procedure := ut_annotations.get_annotation_param(l_proc_annotations('beforetest'), 1);
140140
end if;
141-
141+
142142
if l_proc_annotations.exists('aftertest') then
143-
l_teardown_procedure := ut_annotations.get_annotation_param(l_proc_annotations('aftertest'), 1);
143+
l_aftertest_procedure := ut_annotations.get_annotation_param(l_proc_annotations('aftertest'), 1);
144144
end if;
145-
145+
146146
if l_proc_annotations.exists('displayname') then
147147
l_displayname := ut_annotations.get_annotation_param(l_proc_annotations('displayname'), 1);
148-
elsif l_proc_annotations('test').count>0 then
148+
elsif l_proc_annotations('test').count > 0 then
149149
l_displayname := ut_annotations.get_annotation_param(l_proc_annotations('test'), 1);
150150
end if;
151-
151+
152152
if l_proc_annotations.exists('rollback') then
153153
l_rollback_annotation := ut_annotations.get_annotation_param(l_proc_annotations('rollback'), 1);
154154
l_rollback_type := case lower(l_rollback_annotation)
@@ -162,21 +162,19 @@ create or replace package body ut_suite_manager is
162162
l_suite_rollback
163163
end;
164164
end if;
165-
166-
l_test := ut_test(
167-
a_object_owner => l_owner_name,
168-
a_object_name => l_object_name,
169-
a_name => l_proc_name,
170-
a_description => l_displayname,
171-
a_path => l_suite.path || '.' || l_proc_name,
172-
a_rollback_type => l_rollback_type,
173-
a_ignore_flag => l_proc_annotations.exists('disabled'),
174-
a_before_test_proc_name => l_setup_procedure,
175-
a_after_test_proc_name => l_teardown_procedure,
176-
a_before_each_proc_name => l_default_setup_proc,
177-
a_after_each_proc_name => l_default_teardown_proc
178-
);
179-
165+
166+
l_test := ut_test(a_object_owner => l_owner_name
167+
,a_object_name => l_object_name
168+
,a_name => l_proc_name
169+
,a_description => l_displayname
170+
,a_path => l_suite.path || '.' || l_proc_name
171+
,a_rollback_type => l_rollback_type
172+
,a_ignore_flag => l_proc_annotations.exists('disabled')
173+
,a_before_test_proc_name => l_beforetest_procedure
174+
,a_after_test_proc_name => l_aftertest_procedure
175+
,a_before_each_proc_name => l_default_setup_proc
176+
,a_after_each_proc_name => l_default_teardown_proc);
177+
180178
l_suite.add_item(l_test);
181179
end;
182180
end if;

source/reporters/ut_documentation_reporter.tpb

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ create or replace type body ut_documentation_reporter is
22
/*
33
utPLSQL - Version X.X.X.X
44
Copyright 2016 - 2017 utPLSQL Project
5-
5+
66
Licensed under the Apache License, Version 2.0 (the "License"):
77
you may not use this file except in compliance with the License.
88
You may obtain a copy of the License at
9-
9+
1010
http://www.apache.org/licenses/LICENSE-2.0
11-
11+
1212
Unless required by applicable law or agreed to in writing, software
1313
distributed under the License is distributed on an "AS IS" BASIS,
1414
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,6 +29,18 @@ create or replace type body ut_documentation_reporter is
2929
return rpad(' ', self.lvl * 2);
3030
end tab;
3131

32+
member procedure print_output(a_executable ut_executable) is
33+
l_lines ut_varchar2_list;
34+
begin
35+
if a_executable is not null and a_executable.is_defined and a_executable.serveroutput is not null and
36+
dbms_lob.getlength(a_executable.serveroutput) > 0 then
37+
l_lines := ut_utils.clob_to_table(a_executable.serveroutput);
38+
for i in 1 .. l_lines.count loop
39+
self.print_text(l_lines(i));
40+
end loop;
41+
end if;
42+
end;
43+
3244
overriding member procedure print_text(self in out nocopy ut_documentation_reporter, a_text varchar2) is
3345
begin
3446
if a_text is not null then
@@ -38,35 +50,25 @@ create or replace type body ut_documentation_reporter is
3850

3951
overriding member procedure before_calling_suite(self in out nocopy ut_documentation_reporter, a_suite ut_logical_suite) as
4052
begin
41-
self.print_text( coalesce( a_suite.description, a_suite.name ) );
53+
self.print_text(coalesce(a_suite.description, a_suite.name));
4254
lvl := lvl + 1;
4355
end;
4456

4557
overriding member procedure after_calling_test(self in out nocopy ut_documentation_reporter, a_test ut_test) as
4658
l_message varchar2(4000);
47-
48-
procedure print_output(a_exectable ut_executable) is
49-
l_lines ut_varchar2_list;
50-
begin
51-
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
52-
l_lines := ut_utils.clob_to_table(a_exectable.serveroutput);
53-
for i in 1..l_lines.count loop
54-
self.print_text(l_lines(i));
55-
end loop;
56-
end if;
57-
end;
59+
5860
begin
59-
l_message := coalesce( a_test.description, a_test.name );
61+
l_message := coalesce(a_test.description, a_test.name);
6062
--if test failed, then add it to the failures list, print failure with number
6163
if a_test.result = ut_utils.tr_ignore then
6264
self.print_yellow_text(l_message || ' (IGNORED)');
6365
elsif a_test.result = ut_utils.tr_success then
6466
self.print_green_text(l_message);
6567
elsif a_test.result > ut_utils.tr_success then
6668
failed_test_running_count := failed_test_running_count + 1;
67-
self.print_red_text(l_message || ' (FAILED - '||failed_test_running_count||')');
69+
self.print_red_text(l_message || ' (FAILED - ' || failed_test_running_count || ')');
6870
end if;
69-
71+
7072
-- reproduce the output from before/after procedures and the test
7173
print_output(a_test.before_each);
7274
print_output(a_test.before_test);
@@ -75,6 +77,15 @@ create or replace type body ut_documentation_reporter is
7577
print_output(a_test.after_each);
7678
end;
7779

80+
overriding member procedure after_calling_after_all(self in out nocopy ut_documentation_reporter, a_suite in ut_logical_suite) is
81+
begin
82+
self.print_output(treat(a_suite as ut_suite).after_all);
83+
end;
84+
overriding member procedure after_calling_before_all(self in out nocopy ut_documentation_reporter, a_suite in ut_logical_suite) is
85+
begin
86+
self.print_output(treat(a_suite as ut_suite).before_all);
87+
end;
88+
7889
overriding member procedure after_calling_suite(self in out nocopy ut_documentation_reporter, a_suite ut_logical_suite) as
7990
begin
8091
lvl := lvl - 1;
@@ -85,7 +96,7 @@ create or replace type body ut_documentation_reporter is
8596

8697
overriding member procedure after_calling_run(self in out nocopy ut_documentation_reporter, a_run in ut_run) as
8798
l_summary_text varchar2(4000);
88-
l_warnings ut_varchar2_list := ut_varchar2_list();
99+
l_warnings ut_varchar2_list := ut_varchar2_list();
89100
procedure print_failure_for_assert(a_assert ut_assert_result) is
90101
l_lines ut_varchar2_list;
91102
begin
@@ -96,12 +107,13 @@ create or replace type body ut_documentation_reporter is
96107
self.print_cyan_text(a_assert.caller_info);
97108
self.print_text(' ');
98109
end;
99-
110+
100111
procedure print_failures_for_test(a_test ut_test, a_failure_no in out nocopy integer) is
101112
begin
102113
if a_test.result > ut_utils.tr_success then
103114
a_failure_no := a_failure_no + 1;
104-
self.print_text(lpad(a_failure_no, length(failed_test_running_count)+2,' ')||') '||nvl( a_test.name, a_test.item.form_name ));
115+
self.print_text(lpad(a_failure_no, length(failed_test_running_count) + 2, ' ') || ') ' ||
116+
nvl(a_test.name, a_test.item.form_name));
105117
self.lvl := self.lvl + 3;
106118
for j in 1 .. a_test.results.count loop
107119
if a_test.results(j).result > ut_utils.tr_success then
@@ -111,79 +123,81 @@ create or replace type body ut_documentation_reporter is
111123
lvl := lvl - 3;
112124
end if;
113125
end;
114-
126+
115127
procedure print_failures_from_suite(a_suite ut_logical_suite, a_failure_no in out nocopy integer) is
116128
begin
117129
for i in 1 .. a_suite.items.count loop
118-
if a_suite.items(i) is of (ut_logical_suite) then
119-
print_failures_from_suite(treat( a_suite.items(i) as ut_logical_suite), a_failure_no);
120-
elsif a_suite.items(i) is of (ut_test) then
130+
if a_suite.items(i) is of(ut_logical_suite) then
131+
print_failures_from_suite(treat(a_suite.items(i) as ut_logical_suite), a_failure_no);
132+
elsif a_suite.items(i) is of(ut_test) then
121133
print_failures_for_test(treat(a_suite.items(i) as ut_test), a_failure_no);
122134
end if;
123135
end loop;
124136
end;
125-
137+
126138
procedure print_failures_details(a_run in ut_run) is
127139
l_failure_no integer := 0;
128140
begin
129141
if a_run.results_count.failure_count > 0 or a_run.results_count.errored_count > 0 then
130-
131-
self.print_text( 'Failures:' );
132-
self.print_text( ' ' );
142+
143+
self.print_text('Failures:');
144+
self.print_text(' ');
133145
for i in 1 .. a_run.items.count loop
134146
print_failures_from_suite(treat(a_run.items(i) as ut_logical_suite), l_failure_no);
135147
end loop;
136148
end if;
137149
end;
138-
139-
procedure print_warnings(a_run in ut_run) is
150+
151+
procedure print_warnings(a_run in ut_run) is
140152
procedure gather_warnings(a_item ut_suite_item) is
141153
l_suite ut_logical_suite;
142154
begin
143155
--process warnings of child items first
144156
if a_item is of(ut_logical_suite) then
145157
l_suite := treat(a_item as ut_logical_suite);
146-
for item_ind in 1..l_suite.items.count loop
158+
for item_ind in 1 .. l_suite.items.count loop
147159
gather_warnings(l_suite.items(item_ind));
148160
end loop;
149161
end if;
150-
162+
151163
--then process self warnings
152164
if a_item.warnings is not null and a_item.warnings.count > 0 then
153-
for warn_ind in 1..a_item.warnings.count loop
165+
for warn_ind in 1 .. a_item.warnings.count loop
154166
l_warnings.extend;
155-
l_warnings(l_warnings.last) := ' '||l_warnings.last||') '||a_item.path||' - '||
156-
regexp_replace(a_item.warnings(warn_ind),'('||chr(10)||'|'||chr(13)||')','\1 ');
167+
l_warnings(l_warnings.last) := ' ' || l_warnings.last || ') ' || a_item.path || ' - ' ||
168+
regexp_replace(a_item.warnings(warn_ind)
169+
,'(' || chr(10) || '|' || chr(13) || ')'
170+
,'\1 ');
157171
end loop;
158172
end if;
159173
end;
160174
begin
161-
if a_run.items is not null and a_run.items.count >0 then
162-
for run_item in 1..a_run.items.count loop
175+
if a_run.items is not null and a_run.items.count > 0 then
176+
for run_item in 1 .. a_run.items.count loop
163177
gather_warnings(a_run.items(run_item));
164178
end loop;
165179
end if;
166-
167-
if l_warnings.count>0 then
168-
self.print_text( 'Warnings:' );
169-
self.print_text( ' ' );
180+
181+
if l_warnings.count > 0 then
182+
self.print_text('Warnings:');
183+
self.print_text(' ');
170184
for i in 1 .. l_warnings.count loop
171185
self.print_text(l_warnings(i));
172186
self.print_text(' ');
173187
end loop;
174188
end if;
175189
end;
176-
190+
177191
begin
178192
print_failures_details(a_run);
179193
print_warnings(a_run);
180-
self.print_text( 'Finished in '||a_run.execution_time||' seconds' );
181-
l_summary_text :=
182-
a_run.results_count.total_count || ' tests, '
183-
||a_run.results_count.failure_count||' failed, '
184-
||a_run.results_count.errored_count||' errored, '
185-
||a_run.results_count.ignored_count||' ignored.'||
186-
case when l_warnings.count>0 then ' '||l_warnings.count||' warning(s)' end;
194+
self.print_text('Finished in ' || a_run.execution_time || ' seconds');
195+
l_summary_text := a_run.results_count.total_count || ' tests, ' || a_run.results_count.failure_count || ' failed, ' ||
196+
a_run.results_count.errored_count || ' errored, ' || a_run.results_count.ignored_count ||
197+
' ignored.' || case
198+
when l_warnings.count > 0 then
199+
' ' || l_warnings.count || ' warning(s)'
200+
end;
187201
if a_run.results_count.failure_count > 0 then
188202
self.print_red_text(l_summary_text);
189203
else

source/reporters/ut_documentation_reporter.tps

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ create or replace type ut_documentation_reporter force under ut_console_reporter
1919
failed_test_running_count integer,
2020
constructor function ut_documentation_reporter(self in out nocopy ut_documentation_reporter) return self as result,
2121
member function tab(self in ut_documentation_reporter) return varchar2,
22+
member procedure print_output(a_executable ut_executable),
2223

2324
overriding member procedure print_text(self in out nocopy ut_documentation_reporter, a_text varchar2),
2425
overriding member procedure before_calling_suite(self in out nocopy ut_documentation_reporter, a_suite ut_logical_suite),
2526
overriding member procedure after_calling_test(self in out nocopy ut_documentation_reporter, a_test ut_test),
27+
overriding member procedure after_calling_after_all (self in out nocopy ut_documentation_reporter, a_suite in ut_logical_suite),
28+
overriding member procedure after_calling_before_all (self in out nocopy ut_documentation_reporter, a_suite in ut_logical_suite),
2629
overriding member procedure after_calling_suite(self in out nocopy ut_documentation_reporter, a_suite ut_logical_suite),
2730
overriding member procedure after_calling_run(self in out nocopy ut_documentation_reporter, a_run in ut_run)
2831

tests/ut_test/ut_test.TestOutputGathering.sql

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ as
1717

1818
procedure aftertest;
1919

20+
--%beforeall
21+
procedure beforeall;
22+
--%afterall
23+
procedure afterall;
24+
2025
end;
2126
/
2227

@@ -51,6 +56,16 @@ as
5156
dbms_output.put_line('<!thetest!>');
5257
ut.expect(1,'Test 1 Should Pass').to_equal(1);
5358
end;
59+
60+
procedure beforeall is
61+
begin
62+
dbms_output.put_line('<!beforeall!>');
63+
end;
64+
65+
procedure afterall is
66+
begin
67+
dbms_output.put_line('<!afterall!>');
68+
end;
5469

5570
end;
5671
/
@@ -70,7 +85,7 @@ begin
7085
dbms_lob.append(l_output,l_output_data(i));
7186
end loop;
7287

73-
if l_output like '%<!beforeeach!>%<!beforetest!>%<!thetest!>%<!aftertest!>%<!aftereach!>%1 tests, 0 failed, 0 errored%' then
88+
if l_output like '%<!beforeall!>%<!beforeeach!>%<!beforetest!>%<!thetest!>%<!aftertest!>%<!aftereach!>%<!afterall!>%1 tests, 0 failed, 0 errored%' then
7489
:test_result := ut_utils.tr_success;
7590
end if;
7691

0 commit comments

Comments
 (0)