Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d932f75

Browse filesBrowse files
committed
- Fixed minor typos, formatting and issues with expectation results.
- Changed how stack trace is reported on expectations to provide more information to the user. - Fixed expectation messages for successful results - moved `to_be_empty` / `not_to_be_empty` to base `ut_expectation` type as it's available for `clob`/`blob` types too. - added-back grant on `ut_matcher` to allow for passing various matchers by users. - fixed issue with misleading message: `All rows are different as the columns position is not matching` when comparing a null collection/cursor {WIP] Updates to documentation for expectations.
1 parent 99bae42 commit d932f75
Copy full SHA for d932f75
Expand file treeCollapse file tree

30 files changed

+920
-606
lines changed

‎docs/userguide/expectations.md

Copy file name to clipboardExpand all lines: docs/userguide/expectations.md
+741-490Lines changed: 741 additions & 490 deletions
Large diffs are not rendered by default.

‎source/core/types/ut_expectation_result.tpb

Copy file name to clipboardExpand all lines: source/core/types/ut_expectation_result.tpb
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ create or replace type body ut_expectation_result is
2424
self.self_type := $$plsql_unit;
2525
self.status := a_status;
2626
self.description := a_description;
27-
self.message := a_message;
27+
self.message := a_message;
2828
if self.status = ut_utils.gc_failure and a_include_caller_info then
2929
self.caller_info := ut_expectation_processor.who_called_expectation(dbms_utility.format_call_stack());
3030
end if;

‎source/core/ut_expectation_processor.pkb

Copy file name to clipboardExpand all lines: source/core/ut_expectation_processor.pkb
+43-13Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ create or replace package body ut_expectation_processor as
9090
for i in 1 .. l_results.count loop
9191
dbms_output.put_line( ' ' || l_results(i) );
9292
end loop;
93+
if a_expectation_result.caller_info is not null then
94+
dbms_output.put_line( ut_utils.indent_lines( a_expectation_result.caller_info, 2, true) );
95+
end if;
9396
end if;
9497
end;
9598

@@ -147,28 +150,55 @@ create or replace package body ut_expectation_processor as
147150

148151
function who_called_expectation(a_call_stack varchar2) return varchar2 is
149152
l_caller_stack_line varchar2(4000);
153+
l_call_stack varchar2(4000);
150154
l_line_no integer;
151155
l_owner varchar2(1000);
152156
l_object_name varchar2(1000);
153-
l_object_full_name varchar2(1000);
154157
l_result varchar2(4000);
155158
-- in 12.2 format_call_stack reportes not only package name, but also the procedure name
156159
-- when 11g and 12c reports only package name
157-
c_expectation_search_pattern constant varchar2(500) :=
158-
'(.*\.(UT_EXPECTATION[A-Z0-9#_$]*|UT|UTASSERT2?)(\.[A-Z0-9#_$]+)?\s+)+(.*)';
160+
function cut_header_and_expectations( a_stack varchar2 ) return varchar2 is
161+
begin
162+
return regexp_substr( a_stack, '(.*\.(UT_EXPECTATION[A-Z0-9#_$]*|UT|UTASSERT2?)(\.[A-Z0-9#_$]+)?\s+)+((.|\s)*)', 1, 1, 'm', 4);
163+
end;
164+
function cut_address_columns( a_stack varchar2 ) return varchar2 is
165+
begin
166+
return regexp_replace( a_stack, '^(0x)?[0-9a-f]+\s+', '', 1, 0, 'm' );
167+
end;
168+
function cut_framework_stack( a_stack varchar2 ) return varchar2 is
169+
begin
170+
return regexp_replace(
171+
a_stack,
172+
'[0-9]+\s+anonymous\s+block\s+[0-9]+\s+package\s+body\s+sys\.dbms_sql(\.execute)?\s+[0-9]+\s+[0-9_$#a-z ]+\.ut_executable.*',
173+
'',
174+
1, 1, 'mni'
175+
);
176+
end;
177+
function format_stack( a_stack varchar2 ) return varchar2 is
178+
begin
179+
return regexp_replace(
180+
a_stack,
181+
'([0-9]+)\s+(.* )?((anonymous block)|(([0-9_$#a-z]+\.[0-9_$#a-z]+(\.([0-9_$#a-z])+)?)))',
182+
'at "\3", line \1', 1, 0, 'i'
183+
);
184+
end;
159185
begin
160-
l_caller_stack_line := regexp_substr( a_call_stack, c_expectation_search_pattern, 1, 1, 'm', 4);
186+
l_call_stack := cut_header_and_expectations( a_call_stack );
187+
l_call_stack := cut_address_columns( l_call_stack );
188+
l_call_stack := cut_framework_stack( l_call_stack );
189+
l_call_stack := format_stack( l_call_stack );
190+
l_caller_stack_line := regexp_substr(l_call_stack,'^(.*)');
161191
if l_caller_stack_line like '%.%' then
162-
l_line_no := to_number( regexp_substr(l_caller_stack_line,'(0x)?[0-9a-f]+\s+(\d+)',subexpression => 2) );
163-
l_owner := regexp_substr(l_caller_stack_line,'([A-Za-z0-9$#_]+)\.([A-Za-z0-9$#_]|\.)+',subexpression => 1);
164-
l_object_name := regexp_substr(l_caller_stack_line,'([A-Za-z0-9$#_]+)\.([A-Za-z0-9$#_]+)',subexpression => 2);
165-
l_object_full_name := regexp_substr(l_caller_stack_line,'([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]|\.)+)',subexpression => 2);
166-
if l_owner is not null and l_object_name is not null and l_line_no is not null then
167-
l_result := 'at "' || l_owner || '.' || l_object_full_name || '", line '|| l_line_no || ' '
168-
|| ut_metadata.get_source_definition_line(l_owner, l_object_name, l_line_no);
169-
end if;
192+
l_line_no := to_number( regexp_substr( l_caller_stack_line, ', line (\d+)', subexpression => 1 ) );
193+
l_owner := regexp_substr( l_caller_stack_line, 'at "([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_]+))?)", line (\d+)', subexpression => 1 );
194+
l_object_name := regexp_substr( l_caller_stack_line, 'at "([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_]+))?)", line (\d+)', subexpression => 3 );
195+
l_result :=
196+
l_caller_stack_line || ' ' || rtrim(ut_metadata.get_source_definition_line(l_owner, l_object_name, l_line_no),chr(10))
197+
|| replace( l_call_stack, l_caller_stack_line );
198+
else
199+
l_result := l_call_stack;
170200
end if;
171-
return l_result;
201+
return rtrim(l_result,chr(10));
172202
end;
173203

174204
procedure add_warning(a_messsage varchar2) is

‎source/create_grants.sql

Copy file name to clipboardExpand all lines: source/create_grants.sql
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ grant execute on &&ut3_owner..ut_expectation_compound to &ut3_user;
7575
grant execute on &&ut3_owner..ut_expectation_json to &ut3_user;
7676

7777
--matchers
78+
grant execute on &&ut3_owner..ut_matcher to &ut3_user;
7879
grant execute on &&ut3_owner..ut_be_between to &ut3_user;
7980
grant execute on &&ut3_owner..ut_be_empty to &ut3_user;
8081
grant execute on &&ut3_owner..ut_be_false to &ut3_user;

‎source/create_synonyms.sql

Copy file name to clipboardExpand all lines: source/create_synonyms.sql
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ create &action_type. synonym &ut3_user.ut_expectation_compound for &&ut3_owner..
9191
create &action_type. synonym &ut3_user.ut_expectation_json for &&ut3_owner..ut_expectation_json;
9292

9393
--matchers
94+
create &action_type. synonym &ut3_user.ut_matcher for &&ut3_owner..ut_matcher;
9495
create &action_type. synonym &ut3_user.be_between for &&ut3_owner..be_between;
9596
create &action_type. synonym &ut3_user.be_empty for &&ut3_owner..be_empty;
9697
create &action_type. synonym &ut3_user.be_false for &&ut3_owner..be_false;

‎source/expectations/data_values/ut_compound_data_helper.pkb

Copy file name to clipboardExpand all lines: source/expectations/data_values/ut_compound_data_helper.pkb
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ create or replace package body ut_compound_data_helper is
608608
begin
609609
return 'SQL exception thrown when fetching data from cursor:'||
610610
ut_utils.remove_error_from_stack(sqlerrm,ut_utils.gc_xml_processing)||chr(10)||
611-
ut_expectation_processor.who_called_expectation(a_error_stack)||
611+
ut_expectation_processor.who_called_expectation(a_error_stack)||chr(10)||
612612
'Check the query and data for errors.';
613613
end;
614614

‎source/expectations/data_values/ut_compound_data_value.tpb

Copy file name to clipboardExpand all lines: source/expectations/data_values/ut_compound_data_value.tpb
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ create or replace type body ut_compound_data_value as
1616
limitations under the License.
1717
*/
1818

19+
member function get_elements_count_info return varchar2 is
20+
begin
21+
return case when elements_count is null then ' [ null ]' else ' [ count = '||elements_count||' ]' end;
22+
end;
23+
1924
overriding member function get_object_info return varchar2 is
2025
begin
21-
return self.data_type||' [ count = '||self.elements_count||' ]';
26+
return self.data_type||get_elements_count_info();
2227
end;
2328

2429
overriding member function is_null return boolean is
@@ -37,7 +42,6 @@ create or replace type body ut_compound_data_value as
3742
end;
3843

3944
overriding member function to_string return varchar2 is
40-
l_results ut_utils.t_clob_tab;
4145
l_result clob;
4246
l_result_string varchar2(32767);
4347
begin

‎source/expectations/data_values/ut_compound_data_value.tps

Copy file name to clipboardExpand all lines: source/expectations/data_values/ut_compound_data_value.tps
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ create or replace type ut_compound_data_value force under ut_data_value(
3939
* Holds name for the type of compound
4040
*/
4141
compound_type varchar2(50),
42-
42+
43+
member function get_elements_count_info return varchar2,
4344
overriding member function get_object_info return varchar2,
4445
overriding member function is_null return boolean,
4546
overriding member function is_diffable return boolean,

‎source/expectations/data_values/ut_data_value.tpb

Copy file name to clipboardExpand all lines: source/expectations/data_values/ut_data_value.tpb
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ create or replace type body ut_data_value as
5959
l_result := l_result || chr(10);
6060
end if;
6161
else
62-
l_result := self.to_string() || ' ' || l_info || ' ';
62+
l_result := self.to_string() || ' ' || l_info;
6363
end if;
6464
return l_result;
6565
end;

‎source/expectations/data_values/ut_data_value_anydata.tpb

Copy file name to clipboardExpand all lines: source/expectations/data_values/ut_data_value_anydata.tpb
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ create or replace type body ut_data_value_anydata as
1818

1919
overriding member function get_object_info return varchar2 is
2020
begin
21-
return self.data_type || case when self.compound_type = 'collection' then ' [ count = '||self.elements_count||' ]' else null end;
21+
return self.data_type || case when self.compound_type = 'collection' then self.get_elements_count_info() end;
2222
end;
2323

2424
member function get_extract_path(a_data_value anydata) return varchar2 is

‎source/expectations/data_values/ut_data_value_json.tpb

Copy file name to clipboardExpand all lines: source/expectations/data_values/ut_data_value_json.tpb
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ create or replace type body ut_data_value_json as
113113
ut_utils.append_to_clob(l_result, l_results);
114114

115115
end if;
116-
117-
118-
l_result_string := ut_utils.to_string(l_result,null);
116+
117+
if l_result != empty_clob() then
118+
l_result_string := chr(10) || 'Diff:' || ut_utils.to_string(l_result,null);
119+
end if;
119120
dbms_lob.freetemporary(l_result);
120121
return l_result_string;
121122
end;

‎source/expectations/data_values/ut_data_value_refcursor.tpb

Copy file name to clipboardExpand all lines: source/expectations/data_values/ut_data_value_refcursor.tpb
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ create or replace type body ut_data_value_refcursor as
220220
a_match_options.ordered_columns()
221221
);
222222

223-
if l_column_diffs.count > 0 then
223+
if l_column_diffs is not empty then
224224
ut_utils.append_to_clob(l_result,chr(10) || 'Columns:' || chr(10));
225225
l_other_cols := remove_incomparable_cols( l_other_cols, l_column_diffs );
226226
l_self_cols := remove_incomparable_cols( l_self_cols, l_column_diffs );
@@ -267,8 +267,8 @@ create or replace type body ut_data_value_refcursor as
267267
l_results(l_results.last) := get_diff_message(l_row_diffs(i),a_match_options.unordered);
268268
end loop;
269269
ut_utils.append_to_clob(l_result,l_results);
270-
else
271-
l_message:= chr(10)||'Rows: [ all different ]'||chr(10)||' All rows are different as the columns position is not matching.';
270+
elsif l_column_diffs is not empty then
271+
l_message:= chr(10)||'Rows: [ all different ]'||chr(10)||' All rows are different as the columns position is not matching.';
272272
ut_utils.append_to_clob( l_result, l_message );
273273
end if;
274274
else
@@ -287,8 +287,9 @@ create or replace type body ut_data_value_refcursor as
287287
end if;
288288

289289
end if;
290-
291-
l_result_string := ut_utils.to_string(l_result,null);
290+
if l_result != empty_clob() then
291+
l_result_string := chr(10) || 'Diff:' || ut_utils.to_string(l_result,null);
292+
end if;
292293
dbms_lob.freetemporary(l_result);
293294
return l_result_string;
294295
end;

‎source/expectations/matchers/ut_contain.tpb

Copy file name to clipboardExpand all lines: source/expectations/matchers/ut_contain.tpb
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ create or replace type body ut_contain as
5555
begin
5656
if self.expected.data_type = a_actual.data_type and self.expected.is_diffable then
5757
l_result :=
58-
'Actual: '||a_actual.get_object_info()||' '||self.description()||': '||self.expected.get_object_info()
59-
|| chr(10) || 'Diff:'
58+
'Actual: '||a_actual.get_object_info()||self.description()||': '||self.expected.get_object_info()
6059
|| treat(expected as ut_data_value_refcursor).diff( a_actual, self.options );
6160
else
6261
l_result := (self as ut_matcher).failure_message(a_actual) || ': '|| self.expected.to_string_report();

‎source/expectations/matchers/ut_equal.tpb

Copy file name to clipboardExpand all lines: source/expectations/matchers/ut_equal.tpb
+9-10Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,15 @@ create or replace type body ut_equal as
244244
begin
245245
if self.expected.data_type = a_actual.data_type and self.expected.is_diffable then
246246
l_result :=
247-
'Actual: '||a_actual.get_object_info()||' '||self.description()||': '||self.expected.get_object_info()
248-
|| chr(10) || 'Diff:' ||
249-
case
250-
when self.expected is of (ut_data_value_refcursor) then
251-
treat(expected as ut_data_value_refcursor).diff( a_actual, options )
252-
when self.expected is of (ut_data_value_json) then
253-
treat(expected as ut_data_value_json).diff( a_actual, options )
254-
else
255-
expected.diff( a_actual, options )
256-
end;
247+
'Actual: '||a_actual.get_object_info()||self.description()||': '||self.expected.get_object_info()
248+
||case
249+
when self.expected is of (ut_data_value_refcursor) then
250+
treat(expected as ut_data_value_refcursor).diff( a_actual, options )
251+
when self.expected is of (ut_data_value_json) then
252+
treat(expected as ut_data_value_json).diff( a_actual, options )
253+
else
254+
expected.diff( a_actual, options )
255+
end;
257256
else
258257
l_result := (self as ut_matcher).failure_message(a_actual) || ': '|| self.expected.to_string_report();
259258
end if;

‎source/expectations/matchers/ut_matcher.tpb

Copy file name to clipboardExpand all lines: source/expectations/matchers/ut_matcher.tpb
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ create or replace type body ut_matcher as
4040

4141
member function description return varchar2 is
4242
begin
43-
return 'was expected to '||name();
43+
return ' was expected to '||name();
4444
end;
4545

4646
member function description_when_negated return varchar2 is
4747
begin
48-
return 'was expected not to '||name();
48+
return ' was expected not to '||name();
4949
end;
5050

5151
member function error_message(a_actual ut_data_value) return varchar2 is

‎source/expectations/ut_expectation.tpb

Copy file name to clipboardExpand all lines: source/expectations/ut_expectation.tpb
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ create or replace type body ut_expectation as
8181
self.not_to( ut_be_false() );
8282
end;
8383

84+
member procedure to_be_empty(self in ut_expectation) is
85+
begin
86+
self.to_( ut_be_empty() );
87+
end;
88+
89+
member procedure not_to_be_empty(self in ut_expectation) is
90+
begin
91+
self.not_to( ut_be_empty() );
92+
end;
93+
8494
member procedure to_equal(self in ut_expectation, a_expected anydata, a_nulls_are_equal boolean := null) is
8595
begin
8696
self.to_( ut_equal(a_expected, a_nulls_are_equal) );

‎source/expectations/ut_expectation.tps

Copy file name to clipboardExpand all lines: source/expectations/ut_expectation.tps
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ create or replace type ut_expectation authid current_user as object(
3333
member procedure not_to_be_true(self in ut_expectation),
3434
member procedure not_to_be_false(self in ut_expectation),
3535

36+
member procedure to_be_empty(self in ut_expectation),
37+
member procedure not_to_be_empty(self in ut_expectation),
38+
3639
-- this is done to provide strong type comparison. other comporators should be implemented in the type-specific classes
3740
member procedure to_equal(self in ut_expectation, a_expected anydata, a_nulls_are_equal boolean := null),
3841
member procedure to_equal(self in ut_expectation, a_expected anydata, a_exclude varchar2, a_nulls_are_equal boolean := null),

‎source/expectations/ut_expectation_compound.tpb

Copy file name to clipboardExpand all lines: source/expectations/ut_expectation_compound.tpb
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ create or replace type body ut_expectation_compound as
2323
return;
2424
end;
2525

26-
member procedure to_be_empty(self in ut_expectation_compound) is
27-
begin
28-
self.to_( ut_be_empty() );
29-
end;
30-
31-
member procedure not_to_be_empty(self in ut_expectation_compound) is
32-
begin
33-
self.not_to( ut_be_empty() );
34-
end;
35-
3626
member procedure to_have_count(self in ut_expectation_compound, a_expected integer) is
3727
begin
3828
self.to_( ut_have_count(a_expected) );

‎source/expectations/ut_expectation_compound.tps

Copy file name to clipboardExpand all lines: source/expectations/ut_expectation_compound.tps
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ create or replace type ut_expectation_compound force under ut_expectation(
1919

2020
constructor function ut_expectation_compound(self in out nocopy ut_expectation_compound, a_actual_data ut_data_value, a_description varchar2) return self as result,
2121

22-
member procedure to_be_empty(self in ut_expectation_compound),
23-
member procedure not_to_be_empty(self in ut_expectation_compound),
2422
member procedure to_have_count(self in ut_expectation_compound, a_expected integer),
2523
member procedure not_to_have_count(self in ut_expectation_compound, a_expected integer),
2624

‎source/expectations/ut_expectation_json.tpb

Copy file name to clipboardExpand all lines: source/expectations/ut_expectation_json.tpb
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ create or replace type body ut_expectation_json as
2323
return;
2424
end;
2525

26-
member procedure to_be_empty(self in ut_expectation_json) is
27-
begin
28-
self.to_( ut_be_empty() );
29-
end;
30-
31-
member procedure not_to_be_empty(self in ut_expectation_json) is
32-
begin
33-
self.not_to( ut_be_empty() );
34-
end;
35-
3626
member function to_equal(a_expected json_element_t, a_nulls_are_equal boolean := null) return ut_expectation_json is
3727
l_result ut_expectation_json := self;
3828
begin

‎source/expectations/ut_expectation_json.tps

Copy file name to clipboardExpand all lines: source/expectations/ut_expectation_json.tps
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ create or replace type ut_expectation_json under ut_expectation(
1919

2020
constructor function ut_expectation_json(self in out nocopy ut_expectation_json, a_actual_data ut_data_value, a_description varchar2) return self as result,
2121

22-
member procedure to_be_empty(self in ut_expectation_json),
23-
member procedure not_to_be_empty(self in ut_expectation_json),
2422
member function to_equal(a_expected json_element_t , a_nulls_are_equal boolean := null) return ut_expectation_json,
2523
member function not_to_equal(a_expected json_element_t , a_nulls_are_equal boolean := null) return ut_expectation_json,
2624
member procedure to_have_count(self in ut_expectation_json, a_expected integer),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.