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

Skip to content

Commit a6699b6

Browse files
committed
adde new shortcuts
fixed docs/userguide/expectations.md fixed examples fixed tests
1 parent 930efe1 commit a6699b6

28 files changed

Lines changed: 178 additions & 65 deletions

docs/userguide/expectations.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ To do that we use concept of expectation and a matcher to perform the check on t
66
Example of unit test procedure body with a single expectation.
77
```sql
88
begin
9-
ut.expect( 'the tested value' ).to_( equal('the expected value') );
9+
ut.expect( 'the tested value' ).to_equal('the expected value');
1010
end;
1111
```
1212

@@ -19,6 +19,12 @@ Pseudo-code:
1919
ut.expect( a_actual {data-type} ).not_to( {matcher} );
2020
```
2121

22+
Most of the matchers have shortcuts like:
23+
```sql
24+
ut.expect( a_actual {data-type} ).to_{matcher};
25+
ut.expect( a_actual {data-type} ).not_to{matcher};
26+
```
27+
2228

2329
# Matchers
2430
utPLSQL provides following matchers to perform checks on the expected and actual values.
@@ -42,8 +48,8 @@ Validates that the actual value is between the lower and upper bound.
4248
Example:
4349
```sql
4450
begin
45-
ut.expect( a_actual => 3 ).to_( be_between( a_lower_bound => 1, a_upper_bound => 3 ) );
46-
ut.expect( 3 ).to_( be_between( 1, 3 ) );
51+
ut.expect( a_actual => 3 ).to_be_between( a_lower_bound => 1, a_upper_bound => 3 );
52+
ut.expect( 3 ).to_be_between( 1, 3 );
4753
end;
4854
```
4955

@@ -56,7 +62,7 @@ procedure test_if_cursor_is_empty is
5662
l_cursor sys_refcursor;
5763
begin
5864
open l_cursor for select * from dual where 1 = 0;
59-
ut.expect( l_cursor ).to_( be_empty() );
65+
ut.expect( l_cursor ).to_be_empty();
6066
end;
6167
```
6268

@@ -68,7 +74,7 @@ Unary matcher that validates if the provided value is false.
6874
Usage:
6975
```sql
7076
begin
71-
ut.expect( ( 1 = 0 ) ).to_( be_false() );
77+
ut.expect( ( 1 = 0 ) ).to_be_false();
7278
end;
7379
```
7480

@@ -78,7 +84,7 @@ Allows to check if the actual value is greater or equal than the expected.
7884
Usage:
7985
```sql
8086
begin
81-
ut.expect( sysdate ).to_( be_greater_or_equal( sysdate - 1 ) );
87+
ut.expect( sysdate ).to_be_greater_or_equal( sysdate - 1 );
8288
end;
8389
```
8490

@@ -88,7 +94,7 @@ Allows to check if the actual value is greater than the expected.
8894
Usage:
8995
```sql
9096
begin
91-
ut.expect( 2 ).to_( be_greater_than( 1 ) );
97+
ut.expect( 2 ).to_be_greater_than( 1 );
9298
end;
9399
```
94100

@@ -98,7 +104,7 @@ Allows to check if the actual value is less or equal than the expected.
98104
Usage:
99105
```sql
100106
begin
101-
ut.expect( 3 ).to_( be_less_or_equal( 3 ) );
107+
ut.expect( 3 ).to_be_less_or_equal( 3 );
102108
end;
103109
```
104110

@@ -108,7 +114,7 @@ Allows to check if the actual value is less than the expected.
108114
Usage:
109115
```sql
110116
begin
111-
ut.expect( 3 ).to_( be_less_than( 2 ) );
117+
ut.expect( 3 ).to_be_less_than( 2 );
112118
end;
113119
```
114120

@@ -119,8 +125,8 @@ Validates that the actual value is like the expected expression.
119125
Usage:
120126
```sql
121127
begin
122-
ut.expect( 'Lorem_impsum' ).to_( be_like( a_mask => '%rem\_%', a_escape_char => '\' ) );
123-
ut.expect( 'Lorem_impsum' ).to_( be_like( '%rem\_%', '\' ) );
128+
ut.expect( 'Lorem_impsum' ).to_be_like( a_mask => '%rem\_%', a_escape_char => '\' );
129+
ut.expect( 'Lorem_impsum' ).to_be_like( '%rem\_%', '\' );
124130
end;
125131
```
126132
@@ -133,7 +139,7 @@ Unary matcher that validates if the actual value is not null.
133139
Usage:
134140
```sql
135141
begin
136-
ut.expect( to_clob('ABC') ).to_( be_not_null() );
142+
ut.expect( to_clob('ABC') ).to_be_not_null();
137143
end;
138144
```
139145
@@ -143,7 +149,7 @@ Unary matcher that validates if the actual value is null.
143149
Usage:
144150
```sql
145151
begin
146-
ut.expect( cast(null as varchar2(100)) ).to_( be_null() );
152+
ut.expect( cast(null as varchar2(100)) ).to_be_null();
147153
end;
148154
```
149155
@@ -154,7 +160,7 @@ Unary matcher that validates if the provided value is false.
154160
Usage:
155161
```sql
156162
begin
157-
ut.expect( ( 1 = 1 ) ).to_( be_true() );
163+
ut.expect( ( 1 = 1 ) ).to_be_true();
158164
end;
159165
```
160166
@@ -171,12 +177,14 @@ procedure check_if_cursors_are_equal is
171177
x sys_refcursor;
172178
y sys_refcursor;
173179
begin
174-
ut.expect( 'a dog' ).to_( equal( 'a dog' ) );
175-
ut.expect( a_actual => y ).to_( equal( a_expected => x, a_nulls_are_equal => true ) );
180+
ut.expect( 'a dog' ).to_equal( 'a dog' );
181+
ut.expect( a_actual => y ).to_equal( a_expected => x, a_nulls_are_equal => true );
176182
end;
177183
```
178184
The `a_nulls_are_equal` parameter decides on the behavior of `null=null` comparison (**this comparison by default is true!**)
179185
186+
There are no shortcuts for `not_to_equal`, so use `not_to (equal(...))`
187+
180188
### Comparing cursors
181189
182190
The `equal` matcher accepts additional parameter `a_exclude varchar2` or `a_exclude ut_varchar2_list`, when used to compare `cursor` data.
@@ -193,7 +201,7 @@ procedure test_cursors_skip_columns is
193201
begin
194202
open x for select 'text' ignore_me, d.* from user_tables d;
195203
open y for select sysdate "ADate", d.* from user_tables d;
196-
ut.expect( a_actual => y ).to_( equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' ) );
204+
ut.expect( a_actual => y ).to_equal( a_expected => x, a_exclude => 'IGNORE_ME,ADate' );
197205
end;
198206
```
199207

@@ -261,7 +269,7 @@ create or replace package body test_get_events is
261269
l_actual := get_events(gc_event_date-1, gc_event_date+1);
262270
ut.reset_nls();
263271
264-
ut.expect(l_actual).to_( equal(l_expected) );
272+
ut.expect(l_actual).to_equal(l_expected);
265273
ut.expect(l_actual).not_to( equal(l_expected_bad_date) );
266274
end;
267275
@@ -309,7 +317,7 @@ create or replace package body demo_dept as
309317
begin
310318
v_expected := department('HR');
311319
v_actual := department('IT');
312-
ut.expect( anydata.convertObject(v_expected) ).to_( equal( anydata.convertObject(v_actual) ) );
320+
ut.expect( anydata.convertObject(v_expected) ).to_equal( anydata.convertObject(v_actual) );
313321
end;
314322
315323
procedure test_department is
@@ -318,7 +326,7 @@ create or replace package body demo_dept as
318326
begin
319327
v_expected := departments(department('HR'));
320328
v_actual := departments(department('IT'));
321-
ut.expect( anydata.convertCollection(v_expected) ).to_( equal( anydata.convertCollection(v_actual) ) );
329+
ut.expect( anydata.convertCollection(v_expected) ).to_equal( anydata.convertCollection(v_actual) );
322330
end;
323331
324332
end;
@@ -333,8 +341,8 @@ Validates that the actual value is matching the expected regular expression.
333341
Usage:
334342
```sql
335343
begin
336-
ut.expect( a_actual => '123-456-ABcd' ).to_( match( a_pattern => '\d{3}-\d{3}-[a-z]', a_modifiers => 'i' ) );
337-
ut.expect( 'some value' ).to_( match( '^some.*' ) );
344+
ut.expect( a_actual => '123-456-ABcd' ).to_match( a_pattern => '\d{3}-\d{3}-[a-z]', a_modifiers => 'i' );
345+
ut.expect( 'some value' ).to_match( '^some.*' );
338346
end;
339347
```
340348

@@ -370,14 +378,16 @@ Expectations provide a very convenient way to check for a negative of the expect
370378
Syntax of check for matcher evaluating to true:
371379
```sql
372380
begin
373-
ut.expect( a_actual {data-type} ).to_( {matcher} );
381+
ut.expect( a_actual {data-type} ).to_{matcher};
382+
ut.expect( a_actual {data-type} ).to_{ (matcher} );
374383
end;
375384
```
376385

377386
Syntax of check for matcher evaluating to false:
378387
```sql
379388
begin
380389
ut.expect( a_actual {data-type} ).not_to( {matcher} );
390+
ut.expect( a_actual {data-type} ).not_to_{matcher};
381391
end;
382392
```
383393

@@ -386,7 +396,7 @@ If a matcher evaluated to NULL, then both `to_` and `not_to` will cause the expe
386396
Example:
387397
```sql
388398
begin
389-
ut.expect( null ).to_( be_true() );
399+
ut.expect( null ).to_be_true();
390400
ut.expect( null ).not_to( be_true() );
391401
end;
392402
```

examples/RunWithDocumentationReporter.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ create or replace package body demo_doc_reporter1 is
2828

2929
procedure test_without_name is
3030
begin
31-
ut.expect(1).to_(equal(1));
31+
ut.expect(1).to_equal(1);
3232
end;
3333

3434
procedure failing_test is
3535
begin
36-
ut.expect(1).to_(equal(2));
36+
ut.expect(1).to_equal(2);
3737
end;
3838
procedure failing_no_name is
3939
begin
40-
ut.expect(sysdate).to_(equal(to_char(sysdate)));
40+
ut.expect(sysdate).to_equal(to_char(sysdate));
4141
end;
4242
procedure failing_exception_raised is
4343
l_date date;
@@ -77,7 +77,7 @@ create or replace package body suite_package_without_name is
7777

7878
procedure passing_test2 is
7979
begin
80-
ut.expect(1).to_(equal(1));
80+
ut.expect(1).to_equal(1);
8181
end;
8282
end;
8383
/

examples/award_bonus/test_award_bonus.pkg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ create or replace package body test_award_bonus as
4747
select salary as new_salary
4848
from employees_test where employee_id = gc_test_employee;
4949

50-
ut.expect( results ).to_( equal( expected ) );
50+
ut.expect( results ).to_equal( expected );
5151

5252
open results for
5353
select * from employees_test where employee_id != gc_test_employee;
5454

55-
ut.expect( results ).to_( equal( not_affected ) );
55+
ut.expect( results ).to_equal( not_affected );
5656
end;
5757

5858
procedure fail_on_null_bonus is

examples/between_string/test_betwnstr.pkg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ create or replace package body test_betwnstr as
2929

3030
procedure zero_start_position is
3131
begin
32-
ut.expect( betwnstr( '1234567', 0, 5 ) ).to_( equal('12345') );
32+
ut.expect( betwnstr( '1234567', 0, 5 ) ).to_equal('12345');
3333
end;
3434

3535
procedure big_end_position is
3636
begin
37-
ut.expect( betwnstr( '1234567', 0, 500 ) ).to_( equal('1234567') );
37+
ut.expect( betwnstr( '1234567', 0, 500 ) ).to_equal('1234567');
3838
end;
3939

4040
procedure null_string is
4141
begin
42-
ut.expect( betwnstr( null, 2, 5 ) ).to_( be_null );
42+
ut.expect( betwnstr( null, 2, 5 ) ).to_be_null;
4343
end;
4444

4545
procedure disabled_test is
4646
begin
47-
ut.expect( betwnstr( null, null, null) ).not_to( be_null );
47+
ut.expect( betwnstr( null, null, null) ).not_to_be_null;
4848
end;
4949

5050
end;

examples/demo_of_expectations/demo_equal_matcher.sql

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ create or replace package body demo_equal_matcher as
6363
l_expected := demo_department('Sales');
6464
--get the actual data
6565
l_actual := demo_department('Sales');
66-
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
66+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected)
6767
);
6868
end;
6969

@@ -75,7 +75,7 @@ create or replace package body demo_equal_matcher as
7575
l_expected := demo_department('Sales');
7676
--get the actual data
7777
-- nothing done
78-
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
78+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected)
7979
);
8080
end;
8181

@@ -84,24 +84,21 @@ create or replace package body demo_equal_matcher as
8484
l_actual demo_department;
8585
begin
8686
l_actual := demo_department('Sales');
87-
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
88-
);
87+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
8988
end;
9089

9190
procedure object_compare_null_both_ok is
9291
l_expected demo_department;
9392
l_actual demo_department;
9493
begin
95-
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
96-
);
94+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
9795
end;
9896

9997
procedure object_compare_null_both_fail is
10098
l_expected demo_department;
10199
l_actual demo_department;
102100
begin
103-
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected),false)
104-
);
101+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected),false);
105102
end;
106103

107104

@@ -113,8 +110,7 @@ create or replace package body demo_equal_matcher as
113110
l_expected := demo_department('Sales');
114111
--get the actual data
115112
l_actual := demo_department('HR');
116-
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
117-
);
113+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
118114
end;
119115

120116
procedure object_compare_different_type is
@@ -125,8 +121,7 @@ create or replace package body demo_equal_matcher as
125121
l_expected := demo_department('Sales');
126122
--get the actual data
127123
l_actual := demo_department_new('Sales');
128-
ut.expect(anydata.convertObject(l_actual)).to_(equal(anydata.convertObject(l_expected))
129-
);
124+
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
130125
end;
131126

132127
end;

examples/remove_rooms_by_name/test_remove_rooms_by_name.pkg

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ create or replace package body test_remove_rooms_by_name as
5454
remove_rooms_by_name('B%');
5555

5656
open l_remaining_rooms for select * from rooms;
57-
ut.expect( l_remaining_rooms ).to_(equal(l_rooms_not_named_b));
57+
ut.expect( l_remaining_rooms ).to_equal(l_rooms_not_named_b);
5858
end;
5959

6060
procedure room_with_content is
@@ -65,15 +65,15 @@ create or replace package body test_remove_rooms_by_name as
6565

6666
begin
6767
remove_rooms_by_name('Living Room');
68-
ut.expect( sqlcode ).to_( equal(-2292) );
68+
ut.expect( sqlcode ).to_equal(-2292);
6969
exception
7070
when others then
71-
ut.expect( sqlcode ).to_( equal(-2292) );
71+
ut.expect( sqlcode ).to_equal(-2292);
7272
end;
7373

7474
open l_remaining_rooms for select * from rooms;
7575

76-
ut.expect( l_remaining_rooms ).to_( equal( l_rooms ) );
76+
ut.expect( l_remaining_rooms ).to_equal( l_rooms );
7777
end;
7878

7979
procedure null_room_name is
@@ -84,15 +84,15 @@ create or replace package body test_remove_rooms_by_name as
8484

8585
begin
8686
remove_rooms_by_name(NULL);
87-
ut.expect( sqlcode ).to_( equal(-6501) );
87+
ut.expect( sqlcode ).to_equal(-6501);
8888
exception
8989
when others then
90-
ut.expect( sqlcode ).to_( equal(-6501) );
90+
ut.expect( sqlcode ).to_equal(-6501);
9191
end;
9292

9393
open l_remaining_rooms for select * from rooms;
9494

95-
ut.expect( l_remaining_rooms ).to_( equal( l_rooms ) );
95+
ut.expect( l_remaining_rooms ).to_equal( l_rooms );
9696
end;
9797

9898
end;

0 commit comments

Comments
 (0)