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

Skip to content

Commit 72261e1

Browse files
committed
Fixed return code of data-comparison.
Fixed failing tests fro 11g (record types in SQL) as well as old_test. Refactored the comparison a little bit.
1 parent 9febac9 commit 72261e1

5 files changed

Lines changed: 44 additions & 83 deletions

File tree

old_tests/lib/RunTest.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ begin
2121
end;
2222
/
2323

24+
rollback;
2425
begin
2526
ut_expectation_processor.clear_expectations;
27+
ut_utils.cleanup_temp_tables;
2628
end;
2729
/
2830

old_tests/ut_expectations/ut.expect.to_equal.cursor.ReturnsCursorDataForFailure.sql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROMPT Gives a success when comparing values of different cursors
1+
PROMPT Returns differing rows when compared cursor data is different
22
--Arrange
33
declare
44
l_actual sys_refcursor;
@@ -14,13 +14,11 @@ begin
1414
--Assert
1515
if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success
1616
and l_result.message like q'[Actual:%
17-
<ROW>%</ROW>
18-
<ROW>%</ROW>
17+
(rows: 2, mismatched: 1)
1918
(refcursor)%
2019
was expected to equal:%
21-
<ROW>%</ROW>
22-
<ROW>%</ROW>
23-
<ROW>%</ROW>
20+
(rows: 3, mismatched: 1)
21+
row_no: 3 <ROW>%</ROW>
2422
(refcursor)%]' then
2523
:test_result := ut_utils.tr_success;
2624
else

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ create or replace type body ut_data_value_refcursor as
103103
type t_clob_tab is table of clob;
104104
l_results t_clob_tab;
105105
c_max_rows constant integer := 50;
106+
c_pad_depth constant integer := 5;
106107
l_result clob;
107108
l_result_xml xmltype;
108109
l_result_string varchar2(32767);
@@ -113,16 +114,15 @@ create or replace type body ut_data_value_refcursor as
113114
-- First tell how many rows are different
114115
execute immediate 'select count(*) from ' || l_ut_owner || '.ut_cursor_data_diff' into l_diff_row_count;
115116

116-
ut_utils.append_to_clob(l_result,'Rows: ' || to_char(self.ROW_COUNT)
117-
|| ', different: ' || to_char(l_diff_row_count) || chr(10));
117+
ut_utils.append_to_clob(l_result,'(rows: ' || to_char(self.row_count)|| ', mismatched: ' || to_char(l_diff_row_count) ||')'|| chr(10));
118118

119119
--return rows which were previously marked as different
120-
execute immediate 'select xmlserialize( content ucd.row_data no indent)
121-
from ' || l_ut_owner || '.ut_cursor_data ucd
120+
execute immediate q'[select 'row_no: '||rpad( ucd.row_no, :c_pad_depth )||' '||xmlserialize( content ucd.row_data no indent)
121+
from ]' || l_ut_owner || '.ut_cursor_data ucd
122122
where ucd.cursor_data_guid = :self_guid
123123
and ucd.row_no in (select row_no from ' || l_ut_owner || '.ut_cursor_data_diff ucdc)
124124
and rownum <= :max_rows'
125-
bulk collect into l_results using in self.data_value, c_max_rows;
125+
bulk collect into l_results using c_pad_depth, self.data_value, c_max_rows;
126126

127127
for i in 1 .. l_results.count loop
128128
dbms_lob.append(l_result,l_results(i));
@@ -167,7 +167,7 @@ create or replace type body ut_data_value_refcursor as
167167
if ( sql%rowcount > 0 ) then
168168
l_result := 1;
169169
else
170-
l_result := 1;
170+
l_result := 0;
171171
end if;
172172
else
173173
raise value_error;

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@ create or replace package body test_expectations_cursor is
1717
execute immediate 'drop table gtt_test_table';
1818
end;
1919

20-
/** Just returns a pre-made expected object
21-
*/
22-
function get_expected_obj return t_test_table
23-
as
24-
l_expected_obj t_test_table;
25-
begin
26-
27-
l_expected_obj(1).my_num := 1;
28-
l_expected_obj(1).my_string := 'This is my test string';
29-
l_expected_obj(1).my_clob := 'This is an even longer test clob';
30-
l_expected_obj(1).my_date := to_date('1984-09-05', 'YYYY-MM-DD');
31-
32-
return l_expected_obj;
33-
end;
34-
3520
procedure test_cursor_w_temp_table
3621
as
3722
pragma autonomous_transaction;
@@ -60,18 +45,24 @@ create or replace package body test_expectations_cursor is
6045

6146
procedure test_cursor_success
6247
as
63-
l_expected_obj t_test_table;
64-
l_actual_obj t_test_table;
6548
l_expected sys_refcursor;
6649
l_actual sys_refcursor;
6750
begin
6851

6952
-- Arrange
70-
l_expected_obj := get_expected_obj();
71-
l_actual_obj := get_expected_obj();
72-
73-
open l_expected for select * from table(l_expected_obj);
74-
open l_actual for select * from table(l_actual_obj);
53+
open l_expected for
54+
select 1 as my_num,
55+
'This is my test string' as my_string,
56+
to_clob('This is an even longer test clob') as my_clob,
57+
to_date('1984-09-05', 'YYYY-MM-DD') as my_date
58+
from dual;
59+
60+
open l_actual for
61+
select 1 as my_num,
62+
'This is my test string' as my_string,
63+
to_clob('This is an even longer test clob') as my_clob,
64+
to_date('1984-09-05', 'YYYY-MM-DD') as my_date
65+
from dual;
7566

7667
--Act - execute the expectation on cursor opened on GTT
7768
ut3.ut.expect( l_actual ).to_equal( l_expected );
@@ -84,18 +75,15 @@ create or replace package body test_expectations_cursor is
8475

8576
end;
8677

87-
--%test(Test cursor comparison success when both empty)
8878
procedure test_cursor_success_on_empty
8979
as
90-
l_expected_obj t_test_table;
91-
l_actual_obj t_test_table;
9280
l_expected sys_refcursor;
9381
l_actual sys_refcursor;
9482
begin
9583

9684
-- Arrange
97-
open l_expected for select * from table(l_expected_obj);
98-
open l_actual for select * from table(l_actual_obj);
85+
open l_expected for select * from dual where 1=0;
86+
open l_actual for select * from dual where 1=0;
9987

10088
--Act - execute the expectation on cursor opened on GTT
10189
ut3.ut.expect( l_actual ).to_equal( l_expected );
@@ -111,20 +99,14 @@ create or replace package body test_expectations_cursor is
11199
--%test(Test cursor comparison fails on different content)
112100
procedure test_cursor_fail_on_difference
113101
as
114-
l_expected_obj t_test_table;
115-
l_actual_obj t_test_table;
116102
l_expected sys_refcursor;
117103
l_actual sys_refcursor;
118104
begin
119105

120106
-- Arrange
121-
l_expected_obj := get_expected_obj();
122-
l_actual_obj := get_expected_obj();
123-
l_actual_obj(1).my_clob := 'Another totally different story';
107+
open l_expected for select to_clob('This is an even longer test clob') as my_clob from dual;
108+
open l_actual for select to_clob('Another totally different story') as my_clob from dual;
124109

125-
open l_expected for select * from table(l_expected_obj);
126-
open l_actual for select * from table(l_actual_obj);
127-
128110
--Act - execute the expectation on cursor opened on GTT
129111
ut3.ut.expect( l_actual ).to_equal( l_expected );
130112

@@ -136,22 +118,16 @@ create or replace package body test_expectations_cursor is
136118

137119
end;
138120

139-
procedure test_cursor_fail_on_expected_missing
121+
procedure fail_on_expected_missing
140122
as
141-
l_expected_obj t_test_table;
142-
l_actual_obj t_test_table;
143123
l_expected sys_refcursor;
144124
l_actual sys_refcursor;
145125
begin
146126

147127
-- Arrange
148-
l_expected_obj := get_expected_obj();
149-
l_actual_obj := get_expected_obj();
150-
l_actual_obj(2).my_num := 2;
128+
open l_expected for select 1 as my_num from dual;
129+
open l_actual for select 1 as my_num from dual union all select 1 as my_num from dual;
151130

152-
open l_expected for select * from table(l_expected_obj);
153-
open l_actual for select * from table(l_actual_obj);
154-
155131
--Act - execute the expectation on cursor opened on GTT
156132
ut3.ut.expect( l_actual ).to_equal( l_expected );
157133

@@ -163,22 +139,16 @@ create or replace package body test_expectations_cursor is
163139

164140
end;
165141

166-
procedure test_cursor_fail_on_actual_missing
142+
procedure fail_on_actual_missing
167143
as
168-
l_expected_obj t_test_table;
169-
l_actual_obj t_test_table;
170144
l_expected sys_refcursor;
171145
l_actual sys_refcursor;
172146
begin
173147

174148
-- Arrange
175-
l_expected_obj := get_expected_obj();
176-
l_expected_obj(2).my_num := 2;
177-
l_actual_obj := get_expected_obj();
149+
open l_expected for select 1 as my_num from dual union all select 1 as my_num from dual;
150+
open l_actual for select 1 as my_num from dual;
178151

179-
open l_expected for select * from table(l_expected_obj);
180-
open l_actual for select * from table(l_actual_obj);
181-
182152
--Act - execute the expectation on cursor opened on GTT
183153
ut3.ut.expect( l_actual ).to_equal( l_expected );
184154

test/core/expectations/test_expectations_cursor.pks

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,27 @@ create or replace package test_expectations_cursor is
33
--%suite(expectations - cursor)
44
--%suitepath(utplsql.core.expectations.cursor)
55

6-
type t_test_record is record (
7-
my_num number(9,0),
8-
my_string varchar2(4000),
9-
my_clob clob,
10-
my_date date);
11-
12-
type t_test_table is table of t_test_record index by binary_integer;
13-
14-
156
procedure setup_temp_table_test;
167
procedure cleanup_temp_table_test;
17-
18-
--%test(Test cursor on temporary table)
8+
9+
--%test(Compares data from cursor on temporary table)
1910
--%beforetest(setup_temp_table_test)
2011
--%aftertest(cleanup_temp_table_test)
2112
procedure test_cursor_w_temp_table;
2213

23-
--%test(Test cursor comparison success)
14+
--%test(Returns success for identical data)
2415
procedure test_cursor_success;
2516

26-
--%test(Test cursor comparison success when both empty)
17+
--%test(Returns success when both cursors are empty)
2718
procedure test_cursor_success_on_empty;
2819

29-
--%test(Test cursor comparison fails on different content)
20+
--%test(Returns failure when different data present in one of rows)
3021
procedure test_cursor_fail_on_difference;
3122

32-
--%test(Test cursor comparison fails on missing row in expected cursor)
33-
procedure test_cursor_fail_on_expected_missing;
23+
--%test(Returns failure when more rows exist in actual)
24+
procedure fail_on_expected_missing;
3425

35-
--%test(Test cursor comparison fails on missing row in actual cursor)
36-
procedure test_cursor_fail_on_actual_missing;
26+
--%test(Returns failure when more rows exist in expected)
27+
procedure fail_on_actual_missing;
3728
end;
3829
/

0 commit comments

Comments
 (0)