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

Skip to content

Commit ff846d1

Browse files
committed
Updated documentation_reporter.
Created ut_run.sql script for execution of scripts in real time.
1 parent 83edcc6 commit ff846d1

5 files changed

Lines changed: 250 additions & 2 deletions

File tree

source/core/ut_output_pipe_helper.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ create or replace package body ut_output_pipe_helper is
137137
procedure buffer_and_send(a_output_id t_output_id, a_message_type integer, a_text t_pipe_item:= null) is
138138
l_is_successful boolean;
139139
begin
140-
buffer(a_output_id, a_message_type, a_text);
141-
l_is_successful := send_from_buffer(a_output_id);
140+
buffer(a_output_id, a_message_type, a_text);
141+
l_is_successful := send_from_buffer(a_output_id);
142142
end;
143143
---public
144144

source/expectations/ut.pkb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ create or replace package body ut is
55
ut_suite_manager.run(a_path, a_reporter);
66
end;
77

8+
procedure run(a_paths in ut_varchar2_list, a_reporter in ut_reporter) is
9+
begin
10+
ut_suite_manager.run(a_paths, a_reporter);
11+
end;
12+
813
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation_anydata is
914
begin
1015
return ut_expectation_anydata(ut_data_value_anydata(a_actual), a_message);

source/expectations/ut.pks

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ create or replace package ut authid current_user as
1515
*/
1616
procedure run(a_path in varchar2, a_reporter in ut_reporter);
1717

18+
procedure run(a_paths in ut_varchar2_list, a_reporter in ut_reporter);
19+
1820
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation_anydata;
1921

2022
function expect(a_actual in blob, a_message varchar2 := null) return ut_expectation_blob;

source/reporters/ut_documentation_reporter.tpb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ create or replace type body ut_documentation_reporter is
148148
end
149149
);
150150
self.print_text(' ');
151+
(self as ut_reporter).after_run(a_suites);
151152
end;
152153

153154
end;

source/ut_run.sql

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
/**
2+
This script is designed to allow invocation of UTPLSQL with multiple reporters.
3+
It allows saving of outcomes into multiple output files.
4+
It also facilitates displaying on screen unit test results while the execution is still ongoing.
5+
Current limit of script parameters is 39
6+
7+
Scrip invocation:
8+
ut_run.sql user password database [ut_path|ut_paths] (-f=format [-o=output] [-s] ...)
9+
10+
Parameters:
11+
user - username to connect as
12+
password - password of the user
13+
database - database to connect to
14+
ut_path - a path(s) ot unit test(s) to be executed: user[.package[.procedure]]
15+
ut_paths - a comma separated list of ut_path (with no spaces in between)
16+
-f=format - a format to be used for reporting
17+
-o=output - a file name to put the outputs into
18+
-s - put output to screen can be used in combination with -o
19+
20+
Parameters -f, -o, -s are correlated. That is parameters -o and -s are defining outputs for -f.
21+
Example:
22+
ut_run hr hr xe hr -f=ut_documentation_reporter -o=run.log -s -f=ut_teamcity_reporter -o=teamcity.xml
23+
Unit tests will be be invoked with two reporters:
24+
- ut_documentation_reporter - this one will output to screen and into file "run.log"
25+
- ut_teamcity_reporter - this one will output to file "teamcity.xml"
26+
*/
27+
28+
def output_stream_type = 'ut_output_dbms_pipe()';
29+
var v_output_ids_cur refcursor;
30+
var v_output_id varchar2(4000);
31+
32+
whenever sqlerror exit failure
33+
whenever oserror exit failure
34+
conn &1/&2@&3
35+
whenever sqlerror continue
36+
whenever oserror continue
37+
38+
set serveroutput on size unlimited format truncated
39+
set trimspool on
40+
set echo off
41+
set feedback off
42+
set pagesize 0
43+
set linesize 30000
44+
set long 30000
45+
set longchunksize 30000
46+
set verify off
47+
set heading off
48+
column 1 new_value 1
49+
column 2 new_value 2
50+
column 3 new_value 3
51+
column 4 new_value 4
52+
column 5 new_value 5
53+
column 6 new_value 6
54+
column 7 new_value 7
55+
column 8 new_value 8
56+
column 9 new_value 9
57+
column 10 new_value 10
58+
column 11 new_value 11
59+
column 12 new_value 12
60+
column 13 new_value 13
61+
column 14 new_value 14
62+
column 15 new_value 15
63+
column 16 new_value 16
64+
column 17 new_value 17
65+
column 18 new_value 18
66+
column 19 new_value 19
67+
column 20 new_value 20
68+
column 21 new_value 21
69+
column 22 new_value 22
70+
column 23 new_value 23
71+
column 24 new_value 24
72+
column 25 new_value 25
73+
column 26 new_value 26
74+
column 27 new_value 27
75+
column 28 new_value 28
76+
column 29 new_value 29
77+
column 30 new_value 30
78+
column 31 new_value 31
79+
column 32 new_value 32
80+
column 33 new_value 33
81+
column 34 new_value 34
82+
column 35 new_value 35
83+
column 36 new_value 36
84+
column 37 new_value 37
85+
column 38 new_value 38
86+
column 39 new_value 39
87+
select '' "1",'' "2",'' "3",'' "4",'' "5",'' "6",'' "7",'' "8",'' "9",
88+
'' "10",'' "11",'' "12",'' "13",'' "14",'' "15",'' "16",'' "17",'' "18",'' "19",
89+
'' "20",'' "21",'' "22",'' "23",'' "24",'' "25",'' "26",'' "27",'' "28",'' "29",
90+
'' "30",'' "31",'' "32",'' "33",'' "34",'' "35",'' "36",'' "37",'' "38",'' "39"
91+
from dual where rownum = 0;
92+
93+
94+
def usr_name='&&1'
95+
def usr_pass='&&2'
96+
def usr_db='&&3'
97+
def ut_paths='&&4'
98+
-- var run_in_background_script varchar2(4000);
99+
-- var get_outputs_script varchar2(4000);
100+
var run_in_background_script clob;
101+
var get_outputs_script clob;
102+
103+
declare
104+
c_output constant ut_output := &&output_stream_type;
105+
c_out_script_template constant varchar2(400) := '
106+
exec dbms_output.put_line(:v_output_id);
107+
set termout {output_to_screen}
108+
exec fetch :v_output_ids_cur into :v_output_id;
109+
spool {l_spool_output}
110+
select * from table( ut_output_dbms_pipe().get_lines(:v_output_id,30) );
111+
spool off
112+
';
113+
l_ut_paths varchar2(32767);
114+
l_background_script varchar2(32767);
115+
l_output_script_part varchar2(32767);
116+
l_outputs_script varchar2(32767);
117+
l_output_id varchar2(128);
118+
l_output_ids ut_varchar2_list := ut_varchar2_list();
119+
begin
120+
if not regexp_like('&&ut_paths','-([fos])\=?(.*)') then
121+
--add quotes around each path
122+
l_ut_paths := ''''||replace('&&ut_paths',',',''',''')||'''';
123+
else
124+
l_ut_paths := 'user';
125+
end if;
126+
l_background_script :=
127+
'conn &&usr_name/&&usr_pass@&&usr_db'||chr(10)||
128+
'set serveroutput on size unlimited format truncated'||chr(10)||
129+
'set pagesize 0'||chr(10)||
130+
'set linesize 4000'||chr(10)||
131+
'spool run_background.log'||chr(10)||
132+
'declare'||chr(10)||
133+
' v_reporter ut_reporter;'||chr(10)||
134+
' v_reporters_list ut_reporters_list := ut_reporters_list();'||chr(10)||
135+
'begin';
136+
for param in (
137+
with
138+
params as (
139+
select '&&4' as param from dual union all
140+
select '&&5' as param from dual union all
141+
select '&&6' as param from dual union all
142+
select '&&7' as param from dual union all
143+
select '&&8' as param from dual union all
144+
select '&&9' as param from dual union all
145+
select '&&10' as param from dual union all
146+
select '&&11' as param from dual union all
147+
select '&&12' as param from dual union all
148+
select '&&13' as param from dual union all
149+
select '&&14' as param from dual union all
150+
select '&&15' as param from dual union all
151+
select '&&16' as param from dual union all
152+
select '&&17' as param from dual union all
153+
select '&&18' as param from dual union all
154+
select '&&19' as param from dual union all
155+
select '&&20' as param from dual union all
156+
select '&&21' as param from dual union all
157+
select '&&22' as param from dual union all
158+
select '&&23' as param from dual union all
159+
select '&&24' as param from dual union all
160+
select '&&25' as param from dual union all
161+
select '&&26' as param from dual union all
162+
select '&&27' as param from dual union all
163+
select '&&28' as param from dual union all
164+
select '&&29' as param from dual union all
165+
select '&&30' as param from dual union all
166+
select '&&31' as param from dual union all
167+
select '&&32' as param from dual union all
168+
select '&&33' as param from dual union all
169+
select '&&34' as param from dual union all
170+
select '&&35' as param from dual union all
171+
select '&&36' as param from dual union all
172+
select '&&37' as param from dual union all
173+
select '&&38' as param from dual union all
174+
select '&&39' as param from dual
175+
),
176+
param_vals as(
177+
select regexp_substr(param,'-([fos])\=?(.*)',1,1,'c',1) param_type,
178+
regexp_substr(param,'-([fos])\=(.*)',1,1,'c',2) param_value
179+
from params
180+
where param is not null)
181+
select param_type, param_value
182+
from param_vals
183+
where param_type is not null)
184+
loop
185+
if param.param_type = 'f' then
186+
l_outputs_script :=
187+
l_outputs_script ||
188+
replace(replace(l_output_script_part,'{output_to_screen}','off'),'{l_spool_output}','off');
189+
190+
l_output_id := c_output.generate_output_id();
191+
l_background_script := l_background_script ||chr(10)||
192+
' v_reporter := '||param.param_value||'('||c_output.output_type||'());'||chr(10)||
193+
' v_reporter.output.output_id := '''||l_output_id||''';'||chr(10)||
194+
' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;';
195+
l_output_ids.extend;
196+
l_output_ids(l_output_ids.last) := l_output_id;
197+
198+
l_output_script_part := c_out_script_template;
199+
elsif param.param_type = 'o' then
200+
l_output_script_part := replace(l_output_script_part,'{l_spool_output}',param.param_value);
201+
elsif param.param_type = 's' then
202+
l_output_script_part := replace(l_output_script_part,'{output_to_screen}','on');
203+
end if;
204+
end loop;
205+
l_outputs_script :=
206+
l_outputs_script ||
207+
replace(replace(l_output_script_part,'{output_to_screen}','off'),'{l_spool_output}','off');
208+
l_background_script := l_background_script||chr(10)||
209+
' ut.run( ut_varchar2_list('||l_ut_paths||'), ut_composite_reporter( v_reporters_list ) );'||chr(10)||
210+
'end;'||chr(10)||
211+
'/'||chr(10)||
212+
'exit';
213+
:run_in_background_script := l_background_script;
214+
:get_outputs_script := l_outputs_script;
215+
open :v_output_ids_cur for select * from table(l_output_ids);
216+
end;
217+
/
218+
set termout off
219+
spool ut_run_in_background.sql
220+
select :run_in_background_script from dual;
221+
spool off
222+
223+
spool ut_get_outputs.sql
224+
select :get_outputs_script from dual;
225+
spool off
226+
227+
set define #
228+
--try running on windows
229+
$ start sqlplus /nolog @ut_run_in_background.sql
230+
--try running on linus/unix
231+
! sqlplus /nolog @run_background.sql &
232+
set define &
233+
234+
--make sure we fetch row by row to indicate the progress
235+
set arraysize 1
236+
@@ut_get_outputs.sql
237+
238+
exec close :v_output_ids_cur;
239+
240+
exit

0 commit comments

Comments
 (0)