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

Skip to content

Commit f19f5b6

Browse files
authored
Merge pull request #177 from jgebal/feature/output_buffer_through_table
Cleanup of outputs - removing pipe and dbms_output as a buffer
2 parents d53a85c + e397ffb commit f19f5b6

69 files changed

Lines changed: 618 additions & 1210 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

client_source/sqlplus/ut_run.sql

Lines changed: 182 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -69,51 +69,171 @@ set longchunksize 30000
6969
set verify off
7070
set heading off
7171

72+
73+
74+
column param_list new_value param_list noprint;
75+
/*
76+
* Prepare script to make SQLPlus parameters optional and pass parameters call to param_list variable
77+
*/
7278
set define off
73-
spool make_input_params_optional.sql.tmp
79+
spool define_params_variable.sql.tmp
7480
declare
7581
l_sql_columns varchar2(4000);
82+
l_params varchar2(4000);
7683
begin
7784
for i in 1 .. 100 loop
7885
dbms_output.put_line('column '||i||' new_value '||i);
7986
l_sql_columns := l_sql_columns ||'null as "'||i||'",';
87+
l_params := l_params || '''''&&'||i||''''',';
8088
end loop;
8189
dbms_output.put_line('select '||rtrim(l_sql_columns, ',') ||' from dual where rownum = 0;');
90+
dbms_output.put_line('select '''||rtrim(l_params, ',')||''' as param_list from dual;' );
8291
end;
8392
/
8493
spool off
8594
set define &
8695

87-
@@make_input_params_optional.sql.tmp
96+
/*
97+
* Make SQLPlus parameters optional and pass parameters call to param_list variable
98+
*/
99+
@@define_params_variable.sql.tmp
88100

101+
var l_paths varchar2(4000);
102+
var l_color_enabled varchar2(5);
103+
var l_run_params_cur refcursor;
104+
var l_out_params_cur refcursor;
105+
/*
106+
* Parse parameters and returning as variables
107+
*/
108+
declare
89109

90-
--prepare executor scripts
110+
type t_call_param is record (
111+
ut_reporter_name varchar2(4000) := 'ut_documentation_reporter',
112+
output_file_name varchar2(4000),
113+
output_to_screen varchar2(3) := 'on',
114+
reporter_id varchar2(250)
115+
);
116+
117+
type tt_call_params is table of t_call_param;
118+
119+
l_input_params ut_varchar2_list := ut_varchar2_list(&&param_list);
120+
l_call_params tt_call_params;
121+
122+
l_run_cursor_sql varchar2(32767);
123+
l_out_cursor_sql varchar2(32767);
124+
125+
function parse_reporting_params(a_params ut_varchar2_list) return tt_call_params is
126+
l_default_call_param t_call_param;
127+
l_call_params tt_call_params := tt_call_params();
128+
l_force_out_to_screen boolean;
129+
begin
130+
for param in(
131+
with
132+
param_vals as(
133+
select regexp_substr(column_value,'-([fos])\=?(.*)',1,1,'c',1) param_type,
134+
regexp_substr(column_value,'-([fos])\=(.*)',1,1,'c',2) param_value
135+
from table(a_params)
136+
where column_value is not null)
137+
select param_type, param_value
138+
from param_vals
139+
where param_type is not null
140+
) loop
141+
if param.param_type = 'f' or l_call_params.last is null then
142+
l_call_params.extend;
143+
l_call_params(l_call_params.last) := l_default_call_param;
144+
if param.param_type = 'f' then
145+
l_call_params(l_call_params.last).ut_reporter_name := dbms_assert.simple_sql_name(param.param_value);
146+
end if;
147+
l_force_out_to_screen := false;
148+
end if;
149+
if param.param_type = 'o' then
150+
l_call_params(l_call_params.last).output_file_name := param.param_value;
151+
if not l_force_out_to_screen then
152+
l_call_params(l_call_params.last).output_to_screen := 'off';
153+
end if;
154+
elsif param.param_type = 's' then
155+
l_call_params(l_call_params.last).output_to_screen := 'on';
156+
l_force_out_to_screen := true;
157+
end if;
158+
end loop;
159+
if l_call_params.count = 0 then
160+
l_call_params.extend;
161+
l_call_params(1) := l_default_call_param;
162+
end if;
163+
for i in 1 .. cardinality(l_call_params) loop
164+
l_call_params(i).reporter_id := sys_guid();
165+
end loop;
166+
return l_call_params;
167+
end;
168+
169+
function parse_paths_param(a_params ut_varchar2_list) return varchar2 is
170+
l_paths varchar2(4000);
171+
begin
172+
begin
173+
select ''''||replace(ut_paths,',',''',''')||''''
174+
into l_paths
175+
from (select regexp_substr(column_value,'-p\=(.*)',1,1,'c',1) as ut_paths from table(a_params) )
176+
where ut_paths is not null;
177+
exception
178+
when no_data_found then
179+
l_paths := 'user';
180+
when too_many_rows then
181+
raise_application_error(-20000, 'Parameter "-p=ut_path(s)" defined more than once. Only one "-p=ut_path(s)" parameter can be used.');
182+
end;
183+
return l_paths;
184+
end;
185+
186+
function parse_color_enabled(a_params ut_varchar2_list) return varchar2 is
187+
begin
188+
for i in 1 .. cardinality(a_params) loop
189+
if a_params(i) = '-c' then
190+
return 'true';
191+
end if;
192+
end loop;
193+
return 'false';
194+
end;
91195

92-
set define off
93-
spool set_run_params.sql.tmp
94-
declare
95-
l_params varchar2(4000);
96196
begin
97-
for i in 1 .. 100 loop
98-
l_params := l_params || '''&&'||i||''',';
197+
l_call_params := parse_reporting_params(l_input_params);
198+
for i in l_call_params.first .. l_call_params.last loop
199+
l_run_cursor_sql :=
200+
l_run_cursor_sql ||
201+
'select '''||l_call_params(i).reporter_id||''' as reporter_id,' ||
202+
' '''||l_call_params(i).ut_reporter_name||''' as reporter_name' ||
203+
' from dual';
204+
l_out_cursor_sql :=
205+
l_out_cursor_sql ||
206+
'select '''||l_call_params(i).reporter_id||''' as reporter_id,' ||
207+
' '''||l_call_params(i).output_to_screen||''' as output_to_screen,' ||
208+
' '''||l_call_params(i).output_file_name||''' as output_file_name' ||
209+
' from dual';
210+
if i < l_call_params.last then
211+
l_run_cursor_sql := l_run_cursor_sql || ' union all ';
212+
l_out_cursor_sql := l_out_cursor_sql || ' union all ';
213+
end if;
99214
end loop;
100-
dbms_output.put_line('exec ut_runner.set_run_params(ut_varchar2_list('||rtrim(l_params, ',')||'));' );
215+
216+
:l_paths := parse_paths_param(l_input_params);
217+
:l_color_enabled := parse_color_enabled(l_input_params);
218+
219+
if l_run_cursor_sql is not null then
220+
open :l_run_params_cur for l_run_cursor_sql;
221+
end if;
222+
if l_out_cursor_sql is not null then
223+
open :l_out_params_cur for l_out_cursor_sql;
224+
end if;
101225
end;
102226
/
103-
spool off
104-
set define &
105227

106-
@@set_run_params.sql.tmp
107228

229+
/*
230+
* Generate runner script
231+
*/
108232
spool run_in_backgroung.sql.tmp
109233
declare
110-
l_output_type varchar2(256) := ut_runner.get_streamed_output_type_name();
111-
l_run_params ut_runner.t_run_params := ut_runner.get_run_params();
112-
l_color_enabled varchar2(5) := case when l_run_params.color_enabled then 'true' else 'false' end;
113-
procedure p(a_text varchar2) is
114-
begin
115-
dbms_output.put_line(a_text);
116-
end;
234+
l_reporter_id varchar2(250);
235+
l_reporter_name varchar2(250);
236+
procedure p(a_text varchar2) is begin dbms_output.put_line(a_text); end;
117237
begin
118238
p( 'set serveroutput on size unlimited format truncated');
119239
p( 'set trimspool on');
@@ -124,14 +244,17 @@ begin
124244
p( ' v_reporter ut_reporter_base;');
125245
p( ' v_reporters_list ut_reporters := ut_reporters();');
126246
p( 'begin');
127-
if l_run_params.call_params is not null then
128-
for i in 1 .. l_run_params.call_params.count loop
129-
p(' v_reporter := '||l_run_params.call_params(i).ut_reporter_name||'('||l_output_type||'());');
130-
p(' v_reporter.output.output_id := '''||l_run_params.call_params(i).output_id||''';');
131-
p(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;');
247+
if :l_run_params_cur%isopen then
248+
loop
249+
fetch :l_run_params_cur into l_reporter_id, l_reporter_name;
250+
exit when :l_run_params_cur%notfound;
251+
p(' v_reporter := '||l_reporter_name||'();');
252+
p(' v_reporter.reporter_id := '''||l_reporter_id||''';');
253+
p(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;');
132254
end loop;
133255
end if;
134-
p( ' ut_runner.run( ut_varchar2_list('||l_run_params.ut_paths||'), v_reporters_list, a_color_console => '||l_color_enabled||' );');
256+
close :l_run_params_cur;
257+
p( ' ut_runner.run( ut_varchar2_list('||:l_paths||'), v_reporters_list, a_color_console => '||:l_color_enabled||' );');
135258
p( 'end;');
136259
p( '/');
137260
p( 'spool off');
@@ -140,49 +263,63 @@ end;
140263
/
141264
spool off
142265

266+
/*
267+
* Generate output retrieval script
268+
*/
143269
spool gather_data_from_outputs.sql.tmp
144270
declare
145-
l_output_type varchar2(256) := ut_runner.get_streamed_output_type_name();
146-
l_run_params ut_runner.t_run_params := ut_runner.get_run_params();
271+
l_reporter_id varchar2(250);
272+
l_output_file_name varchar2(250);
273+
l_output_to_screen varchar2(250);
147274
l_need_spool boolean;
148-
procedure p(a_text varchar2) is
149-
begin
150-
dbms_output.put_line(a_text);
151-
end;
275+
procedure p(a_text varchar2) is begin dbms_output.put_line(a_text); end;
152276
begin
153-
p('declare l_date date := sysdate; begin loop exit when l_date < sysdate; end loop; end;');
154-
p('/');
155-
if l_run_params.call_params is not null then
156-
for i in 1 .. l_run_params.call_params.count loop
157-
p('set termout '||l_run_params.call_params(i).output_to_screen);
158-
l_need_spool := (l_run_params.call_params(i).output_file_name is not null);
159-
p(case when l_need_spool then 'spool '||l_run_params.call_params(i).output_file_name||chr(10) end||
160-
'select * from table( '||l_output_type||'().get_lines('''||l_run_params.call_params(i).output_id||''') );'||
161-
case when l_need_spool then chr(10)||'spool off' end);
277+
if :l_out_params_cur%isopen then
278+
loop
279+
fetch :l_out_params_cur into l_reporter_id, l_output_to_screen, l_output_file_name;
280+
exit when :l_out_params_cur%notfound;
281+
l_need_spool := (l_output_file_name is not null);
282+
p( 'set termout '||l_output_to_screen);
283+
if l_need_spool then
284+
p( 'spool '||l_output_file_name);
285+
end if;
286+
p( 'select * from table( ut_output_buffer.get_lines('''||l_reporter_id||''') );');
287+
if l_need_spool then
288+
p('spool off');
289+
end if;
162290
end loop;
163291
end if;
164292
end;
165293
/
166-
167294
spool off
168-
set termout off
295+
296+
297+
/*
298+
* Execute runner script in background process
299+
*/
169300
set define #
170301
--try running on windows
171302
$ start sqlplus ##1 @run_in_backgroung.sql.tmp
172303
--try running on linus/unix
173304
! sqlplus ##1 @run_in_backgroung.sql.tmp &
174305
set define &
175306
set termout on
307+
308+
176309
--make sure we fetch row by row to indicate the progress
177310
set arraysize 1
311+
/*
312+
* Gather outputs from reporters one by one while runner script executes.
313+
*/
178314
@gather_data_from_outputs.sql.tmp
179315

180316
set termout off
181-
--cleanup temporary sql files
317+
/*
318+
* cleanup temporary sql files
319+
*/
182320
--try running on windows
183321
$ del *.sql.tmp
184322
--try running on linus/unix
185323
! rm *.sql.tmp
186-
set termout on
187324

188325
exit

docs/userguide/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The installation user/schema must have the following Oracle system permissions d
2424

2525
In addition it must be granted execute to the following system packages.
2626

27-
- DBMS_PIPE
27+
- DBMS_LOCK
2828

2929
# Installation Procedure
3030

examples/RunExampleTestAnnotationBasedForCurrentSchema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set echo off
66
@@test_pkg2.pck
77

88
begin
9-
ut_runner.run();
9+
ut.run();
1010
end;
1111
/
1212

examples/RunExpectations.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set echo off
1111
@@demo_expectations.pck
1212

1313
begin
14-
ut_runner.run();
14+
ut.run();
1515
end;
1616
/
1717

examples/RunWithDocumentationReporter.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set echo off
55
create or replace package demo_doc_reporter1 is
66
-- %suite
77
-- %displayname(Demo of documentation reporter)
8-
8+
99
-- %test
1010
-- %displayname(A passing test sample)
1111
procedure passing_test;
@@ -50,7 +50,7 @@ end;
5050
create or replace package demo_doc_reporter2 is
5151
-- %suite
5252
-- %displayname(A suite package without body)
53-
53+
5454
-- %test
5555
-- %displayname(A test)
5656
procedure test1;
@@ -61,7 +61,7 @@ end;
6161

6262
create or replace package suite_package_without_name is
6363
-- %suite
64-
64+
6565
-- %test
6666
-- %displayname(A passing test sample)
6767
procedure passing_test1;
@@ -83,7 +83,7 @@ end;
8383
/
8484

8585
begin
86-
ut_runner.run();
86+
ut.run();
8787
end;
8888
/
8989

examples/award_bonus/run_award_bonus_test.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
set serveroutput on size unlimited format truncated
66

7-
exec ut_runner.run(user||'.test_award_bonus');
7+
exec ut.run(user||'.test_award_bonus');
88

99
drop package test_award_bonus;
1010
drop procedure award_bonus;

examples/between_string/run_betwnstr_test.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
set serveroutput on size unlimited format truncated
55

6-
exec ut_runner.run(user||'.test_betwnstr');
6+
exec ut.run(user||'.test_betwnstr');
77

88
drop package test_betwnstr;
99
drop function betwnstr;

examples/demo_of_expectations/run.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set serveroutput on size unlimited format truncated
44

5-
exec ut_runner.run(user||'.demo_equal_matcher');
5+
exec ut.run(user||'.demo_equal_matcher');
66

77
drop package demo_equal_matcher;
88
drop type demo_departments;

0 commit comments

Comments
 (0)