Skip to content

Commit 4c0a9e5

Browse files
committed
Added colors to the documentation reporter.
Added option to ut_run to enable colors. Added colors to Travis build.
1 parent f087328 commit 4c0a9e5

14 files changed

Lines changed: 163 additions & 20 deletions

client_source/sqlplus/ut_run.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Current limit of script parameters is 39
66
77
Scrip invocation:
8-
ut_run.sql user/password@database [-p=(ut_path|ut_paths)] [-f=format [-o=output] [-s] ...]
8+
ut_run.sql user/password@database [-p=(ut_path|ut_paths)] [-c] [-f=format [-o=output] [-s] ...]
99
1010
Parameters:
1111
user - username to connect as
@@ -34,6 +34,7 @@ Parameters:
3434
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
3535
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
3636
-s - Forces putting output to to screen for a given -f parameter.
37+
-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards
3738
3839
Parameters -f, -o, -s are correlated. That is parameters -o and -s are defining outputs for -f.
3940
Examples of invocation using sqlplus from command line:
@@ -129,6 +130,11 @@ begin
129130
p(' v_reporter.output.output_id := '''||l_run_params.call_params(i).output_id||''';');
130131
p(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;');
131132
end loop;
133+
if l_run_params.color_enabled then
134+
p(' ut_reporter_base.set_color_enabled(true);');
135+
else
136+
p(' ut_reporter_base.set_color_enabled(false);');
137+
end if;
132138
p( ' ut_runner.run( ut_varchar2_list('||l_run_params.ut_paths||'), v_reporters_list );');
133139
p( 'end;');
134140
p( '/');

examples/RunDeveloperExamples.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set echo off
44
set feedback off
55
set linesize 1000
66

7+
exec ut_documentation_reporter.set_color_enabled(true);
78
--developer examples
89
prompt RunExampleComplexSuiteWithCustomReporter
910
@@developer_examples/RunExampleComplexSuiteWithCustomReporter.sql

examples/RunUserExamples.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set linesize 1000
66

77
prompt Common examples from web
88

9+
exec ut_documentation_reporter.set_color_enabled(true);
910
@@award_bonus/run_award_bonus_test.sql
1011

1112
@@between_string/run_betwnstr_test.sql

source/api/ut_runner.pkb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,22 @@ create or replace package body ut_runner is
111111
end loop;
112112
end;
113113

114+
function is_color_enabled(a_params ut_varchar2_list) return boolean is
115+
begin
116+
for i in 1 .. cardinality(a_params) loop
117+
if a_params(i) = '-c' then
118+
return true;
119+
end if;
120+
end loop;
121+
return false;
122+
end;
123+
114124
procedure set_run_params(a_params ut_varchar2_list) is
115125
l_call_params tt_call_params := tt_call_params();
116126
begin
117127
l_call_params := parse_reporting_params(a_params);
118128
g_run_params.ut_paths := parse_paths_param(a_params);
129+
g_run_params.color_enabled := is_color_enabled(a_params);
119130
setup_reporting_output_ids(l_call_params);
120131
g_run_params.call_params := l_call_params;
121132
end set_run_params;

source/api/ut_runner.pks

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ create or replace package ut_runner authid current_user is
1010
type tt_call_params is table of t_call_param;
1111

1212
type t_run_params is record(
13-
ut_paths varchar2(4000),
14-
call_params tt_call_params
13+
ut_paths varchar2(4000),
14+
color_enabled boolean,
15+
call_params tt_call_params
1516
);
1617

1718
/**

source/core/types/ut_assert_result.tpb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ create or replace type body ut_assert_result is
8282
add_text_line(l_result, ' error: '||ut_utils.indent_lines( self.error_message, length(' error: ') ) );
8383
end if;
8484

85-
if l_result is not null and self.caller_info is not null then
86-
add_text_line(l_result, self.caller_info);
87-
end if;
88-
if length(l_result) > 0 then
89-
add_text_line(l_result,' '||chr(10));
90-
end if;
9185
return l_result;
9286
end;
9387

source/core/types/ut_reporter_base.tpb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@ create or replace type body ut_reporter_base is
1212
self.output.send_line(a_text);
1313
end;
1414

15+
static procedure set_color_enabled(a_flag boolean) is
16+
begin
17+
ut_color_helper.color_enabled(a_flag);
18+
end;
19+
20+
member procedure print_ignore_text(self in out nocopy ut_reporter_base, a_text varchar2) is
21+
begin
22+
self.print_text(ut_color_helper.yellow(a_text));
23+
end;
24+
25+
member procedure print_success_text(self in out nocopy ut_reporter_base, a_text varchar2) is
26+
begin
27+
self.print_text(ut_color_helper.green(a_text));
28+
end;
29+
30+
member procedure print_failure_text(self in out nocopy ut_reporter_base, a_text varchar2) is
31+
begin
32+
self.print_text(ut_color_helper.red(a_text));
33+
end;
34+
35+
member procedure print_error_text(self in out nocopy ut_reporter_base, a_text varchar2) is
36+
begin
37+
self.print_text(ut_color_helper.red(a_text));
38+
end;
39+
40+
member procedure print_info_text(self in out nocopy ut_reporter_base, a_text varchar2) is
41+
begin
42+
self.print_text(ut_color_helper.cyan(a_text));
43+
end;
44+
45+
1546
member procedure print_clob(self in out nocopy ut_reporter_base, a_text clob) is
1647
begin
1748
self.output.send_clob(a_text);

source/core/types/ut_reporter_base.tps

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ create or replace type ut_reporter_base force authid current_user as object
55
constructor function ut_reporter_base(self in out nocopy ut_reporter_base, a_output ut_output default ut_output_dbms_output()) return self as result,
66

77
member procedure print_text(self in out nocopy ut_reporter_base, a_text varchar2),
8+
9+
static procedure set_color_enabled(a_flag boolean),
10+
11+
member procedure print_ignore_text(self in out nocopy ut_reporter_base, a_text varchar2),
12+
13+
member procedure print_success_text(self in out nocopy ut_reporter_base, a_text varchar2),
14+
15+
member procedure print_failure_text(self in out nocopy ut_reporter_base, a_text varchar2),
16+
17+
member procedure print_error_text(self in out nocopy ut_reporter_base, a_text varchar2),
18+
19+
member procedure print_info_text(self in out nocopy ut_reporter_base, a_text varchar2),
20+
821
member procedure print_clob(self in out nocopy ut_reporter_base, a_text clob),
922

1023
-- run hooks

source/core/ut_color_helper.pkb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
create or replace package body ut_color_helper as
2+
c_red constant varchar2(7) := chr(27) || '[31m';
3+
c_green constant varchar2(7) := chr(27) || '[32m';
4+
c_yellow constant varchar2(7) := chr(27) || '[33m';
5+
c_blue constant varchar2(7) := chr(27) || '[34m';
6+
c_magenta constant varchar2(7) := chr(27) || '[35m';
7+
c_cyan constant varchar2(7) := chr(27) || '[36m';
8+
c_reset constant varchar2(7) := chr(27) || '[0m';
9+
g_enabled boolean := false;
10+
11+
procedure color_enabled(a_enabled boolean) is
12+
begin
13+
g_enabled := a_enabled;
14+
end;
15+
16+
function color_enabled return boolean is
17+
begin
18+
return g_enabled;
19+
end;
20+
21+
function add_color(a_text varchar2, a_color varchar2 := c_reset) return varchar2 is
22+
begin
23+
if g_enabled then
24+
return a_color||a_text||c_reset;
25+
else
26+
return a_text;
27+
end if;
28+
end;
29+
30+
function red(a_text varchar2) return varchar2 is
31+
begin
32+
return add_color(a_text, c_red);
33+
end;
34+
35+
function green(a_text varchar2) return varchar2 is
36+
begin
37+
return add_color(a_text, c_green);
38+
end;
39+
40+
function yellow(a_text varchar2) return varchar2 is
41+
begin
42+
return add_color(a_text, c_yellow);
43+
end;
44+
45+
function blue(a_text varchar2) return varchar2 is
46+
begin
47+
return add_color(a_text, c_blue);
48+
end;
49+
50+
function magenta(a_text varchar2) return varchar2 is
51+
begin
52+
return add_color(a_text, c_magenta);
53+
end;
54+
55+
function cyan(a_text varchar2) return varchar2 is
56+
begin
57+
return add_color(a_text, c_cyan);
58+
end;
59+
60+
end;
61+
/

source/core/ut_color_helper.pks

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
create or replace package ut_color_helper as
2+
procedure color_enabled(a_enabled boolean);
3+
function color_enabled return boolean;
4+
function red(a_text varchar2) return varchar2;
5+
function green(a_text varchar2) return varchar2;
6+
function yellow(a_text varchar2) return varchar2;
7+
function blue(a_text varchar2) return varchar2;
8+
function magenta(a_text varchar2) return varchar2;
9+
function cyan(a_text varchar2) return varchar2;
10+
end;
11+
/

0 commit comments

Comments
 (0)