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

Skip to content

Commit 72430fb

Browse files
committed
1) Updated the ut_run.sql script.
Updated usage comments in script. Simplified the invocation of the script by making almost all parameters optional and providing default behaviors. 2) Removed wrapper procedures `run` from `ut` package. 3) Updated default parameters for `ut_runner.run`. Now it is possible to invoke `ut_runner.run` without parameters. 4) Updated examples to reflect the changes.
1 parent 173d238 commit 72430fb

13 files changed

Lines changed: 140 additions & 272 deletions

File tree

client_source/sqlplus/ut_run.sql

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,54 @@
55
Current limit of script parameters is 39
66
77
Scrip invocation:
8-
ut_run.sql user password database [ut_path|ut_paths] (-f=format [-o=output] [-s] ...)
8+
ut_run.sql user/password@database [-p=(ut_path|ut_paths)] [-f=format [-o=output] [-s] ...]
99
1010
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 - reporter to be used for reporting
17-
-o=output - file name to save the output provided by the reporter.
18-
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
19-
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
20-
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
21-
-s - Forces putting output to to screen for a given -f parameter.
11+
user - username to connect as
12+
password - password of the user
13+
database - database to connect to
14+
-p=ut_path(s)- A path or a comma separated list of paths to unit test to be executed.
15+
The path can be in one of the following formats:
16+
schema[.package[.procedure]]
17+
schema:suitepacakge[.suitepackage[.suitepackage][...]][.procedure]
18+
Both formats can be mixed in the comma separated list.
19+
If only schema is provided, then all suites owner by that schema (user) are executed.
20+
If -p is omitted, the current schema is used.
21+
-f=format - A reporter to be used for reporting.
22+
Available options:
23+
-f=ut_documentation_reporter
24+
A textual pretty-print of unit test results (usually use for console output)
25+
-f=ut_teamcity_reporter
26+
A teamcity Unit Test reporter, that can be used to visualize progress of test execution as the job progresses.
27+
-f=ut_junit_reporter
28+
A junit xml format (as defined at: http://stackoverflow.com/a/9691131 and at https://gist.github.com/kuzuha/232902acab1344d6b578)
29+
Usually used for consumption by Continuous Integration servers like Jenkins/Hudson or Teamcity
30+
If no -f option is provided, the ut_documentation_reporter will be used.
31+
32+
-o=output - file name to save the output provided by the reporter.
33+
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
34+
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
35+
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
36+
-s - Forces putting output to to screen for a given -f parameter.
2237
2338
Parameters -f, -o, -s are correlated. That is parameters -o and -s are defining outputs for -f.
2439
Examples of invocation using sqlplus from command line:
2540
26-
sqlplus /nolog @ut_run hr hr xe hr -f=ut_documentation_reporter -o=run.log -s -f=ut_teamcity_reporter -o=teamcity.xml
41+
sqlplus /nolog @ut_run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_teamcity_reporter -o=teamcity.xml
2742
28-
Unit tests will be be invoked with two reporters:
29-
- ut_documentation_reporter - this one will output to screen and into file "run.log"
30-
- ut_teamcity_reporter - this one will output to file "teamcity.xml"
43+
All Unit tests from schema "hr_test" will be be invoked with two reporters:
44+
- ut_documentation_reporter - will output to screen and save it's output to file "run.log"
45+
- ut_teamcity_reporter - will save it's output to file "teamcity.xml"
3146
32-
sqlplus /nolog @ut_run hr hr xe hr -f=ut_documentation_reporter
47+
sqlplus /nolog @ut_run hr/hr@xe
3348
34-
Unit tests will be be invoked with ut_documentation_reporter as a format and the results will be printed to screen
49+
All Unit tests from schema "hr" will be be invoked with ut_documentation_reporter as a format and the results will be printed to screen
3550
3651
*/
3752

3853
whenever sqlerror exit failure
3954
whenever oserror exit failure
40-
conn &1/&2@&3
55+
conn &1
4156
whenever sqlerror continue
4257
whenever oserror continue
4358

@@ -149,9 +164,9 @@ spool off
149164
set termout off
150165
set define #
151166
--try running on windows
152-
$ start sqlplus ##1/##2@##3 @run_in_backgroung.sql.tmp
167+
$ start sqlplus ##1 @run_in_backgroung.sql.tmp
153168
--try running on linus/unix
154-
! sqlplus ##1/##2@##3 @run_in_backgroung.sql.tmp &
169+
! sqlplus ##1 @run_in_backgroung.sql.tmp &
155170
set define &
156171
set termout on
157172
--make sure we fetch row by row to indicate the progress

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.run(user, ut_documentation_reporter());
9+
ut_runner.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.run(user, ut_documentation_reporter());
14+
ut_runner.run();
1515
end;
1616
/
1717

examples/RunWithDocumentationReporter.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ end;
7272
/
7373

7474
begin
75-
ut.run(user, ut_documentation_reporter());
75+
ut_runner.run();
7676
end;
7777
/
7878

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.run(user||'.test_award_bonus',ut_documentation_reporter());
7+
exec ut_runner.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.run(user||'.test_betwnstr',ut_documentation_reporter());
6+
exec ut_runner.run(user||'.test_betwnstr');
77

88
drop package test_betwnstr;
99
drop function betwnstr;

examples/remove_rooms_by_name/run_remove_rooms_by_name_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.run(user||'.test_remove_rooms_by_name',ut_documentation_reporter());
7+
exec ut_runner.run(user||'.test_remove_rooms_by_name');
88

99
drop package test_remove_rooms_by_name;
1010
drop procedure remove_rooms_by_name;

source/core/ut_runner.pkb

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@ create or replace package body ut_runner is
22

33
g_run_params t_run_params;
44

5-
procedure run(a_paths in ut_varchar2_list, a_reporters in ut_reporters) is
5+
procedure run(a_paths ut_varchar2_list, a_reporters ut_reporters) is
66
l_items_to_run ut_run;
7-
l_listener ut_execution_listener := ut_execution_listener(a_reporters);
7+
l_listener ut_execution_listener;
88
l_current_suite ut_suite;
99
begin
10+
if a_reporters is null or a_reporters.count = 0 then
11+
l_listener := ut_execution_listener(ut_reporters(ut_documentation_reporter()));
12+
else
13+
l_listener := ut_execution_listener(a_reporters);
14+
end if;
1015
l_items_to_run := ut_run( ut_suite_manager.configure_execution_by_path(a_paths) );
1116
l_items_to_run.do_execute(l_listener);
1217
end;
1318

14-
procedure run(a_paths in ut_varchar2_list, a_reporter in ut_reporter) is
19+
procedure run(a_paths ut_varchar2_list, a_reporter ut_reporter := ut_documentation_reporter()) is
1520
begin
16-
run(a_paths, ut_reporters(a_reporter));
21+
run(a_paths, ut_reporters(coalesce(a_reporter,ut_documentation_reporter())));
1722
end;
1823

1924

20-
procedure run(a_path in varchar2, a_reporter in ut_reporter) is
25+
procedure run(a_path in varchar2, a_reporter ut_reporter := ut_documentation_reporter()) is
2126
begin
2227
run(ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))), a_reporter);
2328
end run;
@@ -27,56 +32,80 @@ create or replace package body ut_runner is
2732
run(ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))), a_reporters);
2833
end run;
2934

30-
procedure set_run_params(a_params ut_varchar2_list) is
31-
l_call_param t_call_param;
35+
36+
37+
function parse_reporting_params(a_params ut_varchar2_list) return tt_call_params is
38+
l_default_call_param t_call_param;
3239
l_call_params tt_call_params := tt_call_params();
33-
l_ut_paths varchar2(4000);
3440
l_force_out_to_screen boolean;
3541
begin
36-
for param in
37-
( with
38-
param_vals as(
39-
select regexp_substr(column_value,'-([fos])\=?(.*)',1,1,'c',1) param_type,
40-
regexp_substr(column_value,'-([fos])\=(.*)',1,1,'c',2) param_value
41-
from table(a_params)
42-
where column_value is not null)
43-
select param_type, param_value
44-
from param_vals
45-
where param_type is not null)
46-
loop
47-
if param.param_type = 'f' then
42+
for param in(
43+
with
44+
param_vals as(
45+
select regexp_substr(column_value,'-([fos])\=?(.*)',1,1,'c',1) param_type,
46+
regexp_substr(column_value,'-([fos])\=(.*)',1,1,'c',2) param_value
47+
from table(a_params)
48+
where column_value is not null)
49+
select param_type, param_value
50+
from param_vals
51+
where param_type is not null
52+
) loop
53+
if param.param_type = 'f' or l_call_params.last is null then
4854
l_call_params.extend;
49-
l_call_params(l_call_params.last) := l_call_param;
50-
l_call_params(l_call_params.last).ut_reporter_name := param.param_value;
55+
l_call_params(l_call_params.last) := l_default_call_param;
56+
if param.param_type = 'f' then
57+
l_call_params(l_call_params.last).ut_reporter_name := param.param_value;
58+
end if;
5159
l_force_out_to_screen := false;
52-
elsif l_call_params.last is not null then
53-
if param.param_type = 'o' then
54-
l_call_params(l_call_params.last).output_file_name := param.param_value;
55-
if not l_force_out_to_screen then
56-
l_call_params(l_call_params.last).output_to_screen := 'off';
57-
end if;
58-
elsif param.param_type = 's' then
59-
l_call_params(l_call_params.last).output_to_screen := 'on';
60-
l_force_out_to_screen := true;
60+
end if;
61+
if param.param_type = 'o' then
62+
l_call_params(l_call_params.last).output_file_name := param.param_value;
63+
if not l_force_out_to_screen then
64+
l_call_params(l_call_params.last).output_to_screen := 'off';
6165
end if;
66+
elsif param.param_type = 's' then
67+
l_call_params(l_call_params.last).output_to_screen := 'on';
68+
l_force_out_to_screen := true;
6269
end if;
6370
end loop;
71+
if l_call_params.count = 0 then
72+
l_call_params.extend;
73+
l_call_params(1) := l_default_call_param;
74+
end if;
75+
return l_call_params;
76+
end;
6477

78+
function parse_paths_param(a_params ut_varchar2_list) return varchar2 is
79+
l_paths varchar2(4000);
80+
begin
6581
begin
6682
select ''''||replace(ut_paths,',',''',''')||''''
67-
into g_run_params.ut_paths
83+
into l_paths
6884
from (select regexp_substr(column_value,'-p\=(.*)',1,1,'c',1) as ut_paths from table(a_params) )
6985
where ut_paths is not null;
7086
exception
7187
when no_data_found then
72-
g_run_params.ut_paths := 'user';
88+
l_paths := 'user';
7389
when too_many_rows then
74-
raise_application_error(-20000, 'Parameter "-p=ut_paths" defined more than once. Only one "-p=ut_paths" parameter can be used.');
90+
raise_application_error(-20000, 'Parameter "-p=ut_path(s)" defined more than once. Only one "-p=ut_path(s)" parameter can be used.');
7591
end;
76-
for i in 1 .. cardinality(l_call_params) loop
92+
return l_paths;
93+
end;
94+
95+
procedure setup_reporting_output_ids(a_call_params in out nocopy tt_call_params) is
96+
begin
97+
for i in 1 .. cardinality(a_call_params) loop
7798
execute immediate 'begin :l_output_id := '||get_streamed_output_type_name()||'().generate_output_id(); end;'
78-
using out l_call_params(i).output_id;
99+
using out a_call_params(i).output_id;
79100
end loop;
101+
end;
102+
103+
procedure set_run_params(a_params ut_varchar2_list) is
104+
l_call_params tt_call_params := tt_call_params();
105+
begin
106+
l_call_params := parse_reporting_params(a_params);
107+
g_run_params.ut_paths := parse_paths_param(a_params);
108+
setup_reporting_output_ids(l_call_params);
80109
g_run_params.call_params := l_call_params;
81110
end set_run_params;
82111

@@ -87,12 +116,12 @@ create or replace package body ut_runner is
87116

88117
function get_streamed_output_type_name return varchar2 is
89118
l_result varchar2(255);
90-
begin
91-
select type_name
92-
into l_result
93-
from user_types where supertype_name = 'UT_OUTPUT_STREAM';
94-
return lower(l_result);
95-
end;
119+
begin
120+
select type_name
121+
into l_result
122+
from user_types where supertype_name = 'UT_OUTPUT_STREAM';
123+
return lower(l_result);
124+
end;
96125

97126
end ut_runner;
98127
/

source/core/ut_runner.pks

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
create or replace package ut_runner authid definer is
22

33
type t_call_param is record (
4-
ut_reporter_name varchar2(4000),
4+
ut_reporter_name varchar2(4000) := 'ut_documentation_reporter',
55
output_file_name varchar2(4000),
6-
output_to_screen varchar2(3) := 'on',
6+
output_to_screen varchar2(3) := 'on',
77
output_id varchar2(4000)
88
);
99

@@ -14,15 +14,29 @@ create or replace package ut_runner authid definer is
1414
call_params tt_call_params
1515
);
1616

17-
procedure run(a_path in varchar2, a_reporter in ut_reporter);
17+
/**
18+
* Run suites/tests by path
19+
* Accepts value of the following formats:
20+
* schema - executes all suites in the schema
21+
* schema:suite1[.suite2] - executes all items of suite1 (suite2) in the schema.
22+
* suite1.suite2 is a suitepath variable
23+
* schema:suite1[.suite2][.test1] - executes test1 in suite suite1.suite2
24+
* schema.suite1 - executes the suite package suite1 in the schema "schema"
25+
* all the parent suites in the hiearcy setups/teardown procedures as also executed
26+
* all chile items are executed
27+
* schema.suite1.test2 - executes test2 procedure of suite1 suite with execution of all
28+
* parent setup/teardown procedures
29+
*/
1830

19-
procedure run(a_path in varchar2, a_reporters in ut_reporters);
31+
procedure run(a_path varchar2 := null, a_reporter ut_reporter := ut_documentation_reporter());
32+
33+
procedure run(a_path varchar2, a_reporters ut_reporters);
2034

2135
-- TODO - implementation to be changed
22-
procedure run(a_paths in ut_varchar2_list, a_reporter in ut_reporter);
36+
procedure run(a_paths ut_varchar2_list, a_reporter ut_reporter := ut_documentation_reporter());
2337

2438
-- TODO - implementation to be changed
25-
procedure run(a_paths in ut_varchar2_list, a_reporters in ut_reporters);
39+
procedure run(a_paths ut_varchar2_list, a_reporters ut_reporters);
2640

2741

2842

source/expectations/ut.pkb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
create or replace package body ut is
22

3-
procedure run(a_path in varchar2 := null, a_reporter in ut_reporter) is
4-
begin
5-
ut_runner.run(a_path, a_reporter);
6-
end;
7-
8-
procedure run(a_path in varchar2 := null, a_reporters in ut_reporters) is
9-
begin
10-
ut_runner.run(a_path, a_reporters);
11-
end;
12-
13-
procedure run(a_paths in ut_varchar2_list, a_reporter in ut_reporter) is
14-
begin
15-
ut_runner.run(a_paths, a_reporter);
16-
end;
17-
18-
procedure run(a_paths in ut_varchar2_list, a_reporters in ut_reporters) is
19-
begin
20-
ut_runner.run(a_paths, a_reporters);
21-
end;
22-
233
function expect(a_actual in anydata, a_message varchar2 := null) return ut_expectation_anydata is
244
begin
255
return ut_expectation_anydata(ut_data_value_anydata(a_actual), a_message);

0 commit comments

Comments
 (0)