Skip to content

Commit 6d77183

Browse files
authored
Merge pull request #1246 from utPLSQL/bug/1245_not_to_contains_fails
Address issue where the not_to(contain) not run correctly
2 parents 33f5485 + 8460a30 commit 6d77183

File tree

6 files changed

+143
-6
lines changed

6 files changed

+143
-6
lines changed

source/expectations/matchers/ut_contain.tpb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ create or replace type body ut_contain as
4747

4848
overriding member function run_matcher_negated(self in out nocopy ut_contain, a_actual ut_data_value) return boolean is
4949
begin
50+
self.negated();
5051
return run_matcher(a_actual);
5152
end;
5253

source/expectations/ut_expectation.tpb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ create or replace type body ut_expectation as
686686

687687
member procedure not_to_contain(self in ut_expectation, a_expected sys_refcursor) is
688688
begin
689-
self.not_to( ut_contain(a_expected).negated() );
689+
self.not_to( ut_contain(a_expected));
690690
end;
691691

692692
member procedure to_contain(self in ut_expectation, a_expected anydata) is
@@ -696,7 +696,7 @@ create or replace type body ut_expectation as
696696

697697
member procedure not_to_contain(self in ut_expectation, a_expected anydata) is
698698
begin
699-
self.not_to( ut_contain(a_expected).negated() );
699+
self.not_to( ut_contain(a_expected));
700700
end;
701701

702702
member function to_be_within(a_dist number) return ut_be_within is

test/ut3_user/expectations/test_expectation_anydata.pkb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,23 @@ Rows: [ 60 differences, showing first 20 ]
957957
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
958958
end;
959959

960+
procedure collection_not_to_contain is
961+
l_actual ut3_tester_helper.test_dummy_object_list;
962+
l_expected ut3_tester_helper.test_dummy_object_list;
963+
begin
964+
--Arrange
965+
select ut3_tester_helper.test_dummy_object( rownum, 'Something2 '||rownum, rownum+100)
966+
bulk collect into l_actual
967+
from dual connect by level <=4;
968+
select ut3_tester_helper.test_dummy_object( rownum, 'Something '||rownum, rownum)
969+
bulk collect into l_expected
970+
from dual connect by level <=2
971+
order by rownum desc;
972+
--Act
973+
ut3_develop.ut.expect(anydata.convertCollection(l_actual)).not_to_contain(anydata.convertCollection(l_expected));
974+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
975+
end;
976+
960977
procedure object_to_contain is
961978
begin
962979
--Arrange
@@ -967,7 +984,7 @@ Rows: [ 60 differences, showing first 20 ]
967984
ut3_develop.ut.expect(g_test_actual).to_contain(g_test_expected);
968985
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
969986
end;
970-
987+
971988
procedure arr_empty_eq_arr_empty_unord is
972989
begin
973990
--Arrange

test/ut3_user/expectations/test_expectation_anydata.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ create or replace package test_expectation_anydata is
195195
--%test( Success when anydata collection contains data from another anydata collection)
196196
procedure collection_to_contain;
197197

198+
--%test( Success when anydata collection not contains data from another anydata collection)
199+
procedure collection_not_to_contain;
200+
198201
--%test( Success when anydata object contains data from another anydata)
199202
procedure object_to_contain;
200203

test/ut3_user/expectations/test_expectations_cursor.pkb

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,23 @@ Diff:%
23292329
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
23302330
end;
23312331

2332+
procedure cursor_not_to_contain2
2333+
as
2334+
l_actual sys_refcursor;
2335+
l_expected sys_refcursor;
2336+
begin
2337+
open l_expected for select 'TEST' username, -600 user_id from dual;
2338+
2339+
open l_actual for select username, user_id from all_users
2340+
union all
2341+
select 'TEST1' username, -601 user_id from dual;
2342+
2343+
--Act
2344+
ut3_develop.ut.expect(l_actual).not_to(ut3_develop.contain(l_expected));
2345+
--Assert
2346+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
2347+
end;
2348+
23322349
procedure cursor_not_to_contain_fail is
23332350
l_actual sys_refcursor;
23342351
l_expected sys_refcursor;
@@ -2359,6 +2376,37 @@ Diff:%
23592376
ut.expect(l_actual_message).to_be_like(l_expected_message);
23602377
end;
23612378

2379+
2380+
procedure cursor_not_to_contain_fail2 is
2381+
l_actual sys_refcursor;
2382+
l_expected sys_refcursor;
2383+
l_expected_message varchar2(32767);
2384+
l_actual_message varchar2(32767);
2385+
begin
2386+
--Arrange
2387+
open l_expected for select 'TEST' username, -600 user_id from dual;
2388+
2389+
open l_actual for select username, user_id from all_users
2390+
union all
2391+
select 'TEST' username, -600 user_id from dual;
2392+
2393+
--Act
2394+
ut3_develop.ut.expect(l_actual).not_to(ut3_develop.contain(l_expected));
2395+
--Assert
2396+
l_expected_message := q'[%Actual: (refcursor [ count = % ])%
2397+
%Data-types:%
2398+
%<USERNAME>VARCHAR2</USERNAME><USER_ID>NUMBER</USER_ID>%
2399+
%Data:%
2400+
%was expected not to contain:(refcursor [ count = 1 ])%
2401+
%Data-types:%
2402+
%<USERNAME>CHAR</USERNAME><USER_ID>NUMBER</USER_ID>%
2403+
%Data:%
2404+
%<ROW><USERNAME>TEST</USERNAME><USER_ID>-600</USER_ID></ROW>%]';
2405+
l_actual_message := ut3_tester_helper.main_helper.get_failed_expectations(1);
2406+
--Assert
2407+
ut.expect(l_actual_message).to_be_like(l_expected_message);
2408+
end;
2409+
23622410
procedure cursor_not_to_contain_joinby is
23632411
l_actual sys_refcursor;
23642412
l_expected sys_refcursor;
@@ -2372,7 +2420,21 @@ Diff:%
23722420
--Assert
23732421
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
23742422
end;
2375-
2423+
2424+
procedure cursor_not_to_contain_joinby2 is
2425+
l_actual sys_refcursor;
2426+
l_expected sys_refcursor;
2427+
begin
2428+
--Arrange
2429+
open l_actual for select username,rownum * 10 user_id from all_users where rownum < 5;
2430+
open l_expected for select username||to_char(rownum) username ,rownum user_id from all_users where rownum < 5;
2431+
2432+
--Act
2433+
ut3_develop.ut.expect(l_actual).not_to(ut3_develop.contain(l_expected).join_by('USER_ID'));
2434+
--Assert
2435+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
2436+
end;
2437+
23762438
procedure not_cont_join_incl_cols_as_lst is
23772439
l_actual sys_refcursor;
23782440
l_expected sys_refcursor;
@@ -2386,6 +2448,19 @@ Diff:%
23862448
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
23872449
end;
23882450

2451+
procedure not_con_join_incl_cols_as_lst2 is
2452+
l_actual sys_refcursor;
2453+
l_expected sys_refcursor;
2454+
begin
2455+
--Arrange
2456+
open l_actual for select rownum as rn, 'b' as "A_Column", 'c' as A_COLUMN, 'x' SOME_COL, 'd' "Some_Col" from dual a connect by level < 10;
2457+
open l_expected for select rownum * 20 rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4;
2458+
--Act
2459+
ut3_develop.ut.expect(l_actual).not_to(ut3_develop.contain(l_expected).include(ut3_develop.ut_varchar2_list('RN','//A_Column','SOME_COL')).join_by('RN'));
2460+
--Assert
2461+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
2462+
end;
2463+
23892464
procedure not_cont_join_excl_cols_as_lst is
23902465
l_actual sys_refcursor;
23912466
l_expected sys_refcursor;
@@ -2399,6 +2474,19 @@ Diff:%
23992474
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
24002475
end;
24012476

2477+
procedure not_con_join_excl_cols_as_lst2 is
2478+
l_actual sys_refcursor;
2479+
l_expected sys_refcursor;
2480+
begin
2481+
--Arrange
2482+
open l_actual for select rownum as rn, 'a' as "A_Column", 'c' as A_COLUMN, 'y' SOME_COL, 'd' "Some_Col" from dual a connect by level < 10;
2483+
open l_expected for select rownum * 20 as rn, 'a' as "A_Column", 'd' as A_COLUMN, 'x' SOME_COL, 'c' "Some_Col" from dual a connect by level < 4;
2484+
--Act
2485+
ut3_develop.ut.expect(l_actual).not_to(ut3_develop.contain(l_expected).exclude(ut3_develop.ut_varchar2_list('//Some_Col','A_COLUMN')).join_by('RN'));
2486+
--Assert
2487+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
2488+
end;
2489+
24022490
procedure to_contain_duplicates is
24032491
l_actual sys_refcursor;
24042492
l_expected sys_refcursor;
@@ -2440,6 +2528,16 @@ Diff:%
24402528
ut.expect(l_actual_message).to_be_like(l_expected_message);
24412529
end;
24422530

2531+
procedure to_not_contain_fails_1245 is
2532+
c1 sys_refcursor;
2533+
c2 sys_refcursor;
2534+
begin
2535+
open c1 for select 'a' as letter from dual union all select 'b' from dual;
2536+
open c2 for select 'c' as letter from dual;
2537+
ut3_develop.ut.expect(c1).not_to(ut3_develop.contain(c2));
2538+
ut.expect(ut3_tester_helper.main_helper.get_failed_expectations_num).to_equal(0);
2539+
end;
2540+
24432541
procedure udt_messg_format_eq is
24442542
l_actual sys_refcursor;
24452543
l_expected sys_refcursor;

test/ut3_user/expectations/test_expectations_cursor.pks

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,42 @@ create or replace package test_expectations_cursor is
376376
--%test( Cursor not to contains data from another cursor)
377377
procedure cursor_not_to_contain;
378378

379+
--%test( Cursor not_to[contain] data from another cursor)
380+
procedure cursor_not_to_contain2;
381+
379382
--%test( Cursor fail not to contains data from another cursor)
380383
procedure cursor_not_to_contain_fail;
381-
384+
385+
--%test( Cursor fail not_to[contain] data from another cursor)
386+
procedure cursor_not_to_contain_fail2;
387+
382388
--%test( Cursor not contains data from another cursor with joinby clause)
383389
procedure cursor_not_to_contain_joinby;
384390

391+
--%test( Cursor not_to[contain] data from another cursor with joinby clause)
392+
procedure cursor_not_to_contain_joinby2;
393+
385394
--%test(Cursor not contains data with of columns to include and join by value)
386395
procedure not_cont_join_incl_cols_as_lst;
387396

397+
--%test(Cursor not_to[contain] data with of columns to include and join by value)
398+
procedure not_con_join_incl_cols_as_lst2;
399+
388400
--%test(Cursor not contains data with of columns to exclude and join by value)
389401
procedure not_cont_join_excl_cols_as_lst;
390402

403+
--%test(Cursor not_to[contain] data with of columns to exclude and join by value)
404+
procedure not_con_join_excl_cols_as_lst2;
405+
391406
--%test(Cursor to contain duplicates)
392407
procedure to_contain_duplicates;
393408

394409
--%test(Cursor to contain duplicates fail)
395410
procedure to_contain_duplicates_fail;
396-
411+
412+
--%test(Cursor using not_to[contain] fails #1245)
413+
procedure to_not_contain_fails_1245;
414+
397415
--%test(Display a message with a uer defined type with only type name not structure on equal)
398416
procedure udt_messg_format_eq;
399417

0 commit comments

Comments
 (0)