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

Skip to content

Commit 94c3588

Browse files
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into new_throws_annotation
2 parents 06dcf9f + d8c75f2 commit 94c3588

143 files changed

Lines changed: 6245 additions & 3337 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis/coveralls_uploader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (process.env.COVERALLS_URL_BASE) {
99
url = 'https://coveralls.io/api/v1/jobs';
1010
}
1111

12-
fs.readFile('../old_tests/coverage.json',function (err,data) {
12+
fs.readFile('../coverage.json',function (err,data) {
1313
if (err) {
1414
return console.log(err);
1515
}

.travis/install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -ev
77
set feedback off
88
set verify off
99
10+
alter session set plsql_warnings = 'ENABLE:ALL', 'DISABLE:(5004,5018,6000,6001,6003,6009,6010,7206)';
1011
@install_headless.sql $UT3_OWNER $UT3_OWNER_PASSWORD
1112
SQL
1213

.travis/install_utplsql_release.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ end;
3636
/
3737
SQL
3838

39-
"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA @install_headless.sql ${UT3_RELEASE_VERSION_SCHEMA}
39+
"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<SQL
40+
alter session set plsql_warnings = 'ENABLE:ALL', 'DISABLE:(5004,5018,6000,6001,6003,6009,6010,7206)';
41+
@install_headless.sql ${UT3_RELEASE_VERSION_SCHEMA}
42+
exit
43+
SQL
4044

4145
"$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<SQL
4246
grant select any dictionary to ${UT3_RELEASE_VERSION_SCHEMA};

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The framework follows industry standards and best patterns of modern Unit Testin
88
- [Getting Started](userguide/getting-started.md)
99
- [Annotations](userguide/annotations.md)
1010
- [Expectations](userguide/expectations.md)
11+
- [Advanced data comparison](userguide/advanced_data_comparison.md)
1112
- [Running unit tests](userguide/running-unit-tests.md)
1213
- [Testing best pracitces](userguide/best-practices.md)
1314
- [Upgrade utPLSQL](userguide/upgrade.md)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Advanced data comparison
2+
3+
utPLSQL expectations incorporates advanced data comparison options when comparing compound data-types:
4+
5+
- refcursor
6+
- object type
7+
- nested table and varray
8+
9+
Advanced data-comparison options are available for the [`equal`](expectations.md#equal) matcher.
10+
11+
## Syntax
12+
13+
```
14+
ut.expect( a_actual {data-type} ).to_( equal( a_expected {data-type})[.extendend_option()[.extendend_option()[...]]]);
15+
ut.expect( a_actual {data-type} ).not_to( equal( a_expected {data-type})[.extendend_option()[.extendend_option()[...]]]) );
16+
ut.expect( a_actual {data-type} ).to_equal( a_expected {data-type})[.extendend_option()[.extendend_option()[...]]]);
17+
ut.expect( a_actual {data-type} ).not_to_equal( a_expected {data-type})[.extendend_option()[.extendend_option()[...]]] );
18+
```
19+
20+
`extended_option` can be one of:
21+
22+
- `include(a_items varchar2)` - item or comma separated list of items to include
23+
- `exclude(a_items varchar2)` - item or comma separated list of items to exclude
24+
- `include(a_items ut_varchar2_list)` - table of items to include
25+
- `exclude(a_items ut_varchar2_list)` - table of items to exclude
26+
27+
Each item in the comma separated list can be:
28+
- a column name of cursor to be compared
29+
- an attribute name of object type to be compared
30+
- an attribute name of object type within a table of objects to be compared
31+
- an [XPath](http://zvon.org/xxl/XPathTutorial/Output/example1.html) expression representing column/attribute
32+
33+
Each element in `ut_varchar2_list` nested table can be an item or a comma separated list of items.
34+
35+
When specifying column/attribute names, keep in mind that the names are **case sensitive**.
36+
37+
**XPath expressions with comma are not supported.**
38+
39+
## Excluding elements from data comparison
40+
41+
Consider the following example
42+
```sql
43+
procedure test_cursors_skip_columns is
44+
l_expected sys_refcursor;
45+
l_actual sys_refcursor;
46+
begin
47+
open l_expected for select 'text' ignore_me, d.* from user_tables d;
48+
open l_actual for select sysdate "ADate", d.* from user_tables d;
49+
ut.expect( l_actual ).to_equal( l_expected ).exclude( 'IGNORE_ME,ADate' );
50+
end;
51+
```
52+
53+
Columns 'ignore_me' and "ADate" will get excluded from cursor comparison.
54+
The cursor data is equal, when those columns are excluded.
55+
56+
This option is useful in scenarios, when you need to exclude incomparable/unpredictable column data like CREATE_DATE of a record that is maintained by default value on a table column.
57+
58+
## Selecting columns for data comparison
59+
60+
Consider the following example
61+
```sql
62+
procedure include_columns_as_csv is
63+
l_actual sys_refcursor;
64+
l_expected sys_refcursor;
65+
begin
66+
open l_expected for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL from dual a connect by level < 4;
67+
open l_actual for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL, a.* from all_objects a where rownum < 4;
68+
ut.expect( l_actual ).to_equal( l_expected ).include( 'RN,A_Column,SOME_COL' );
69+
end;
70+
```
71+
72+
## Combining include/exclude options
73+
You can chain the advanced options in an expectation and mix the `varchar2` with `ut_varchar2_list` arguments.
74+
When doing so, the fianl list of items to include/exclude will be a concatenation of all items.
75+
76+
```sql
77+
procedure include_columns_as_csv is
78+
l_actual sys_refcursor;
79+
l_expected sys_refcursor;
80+
begin
81+
open l_expected for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL from dual a connect by level < 4;
82+
open l_actual for select rownum as rn, 'a' as "A_Column", 'Y' SOME_COL, a.* from all_objects a where rownum < 4;
83+
ut.expect( l_actual ).to_equal( l_expected )
84+
.include( 'RN')
85+
.include( ut_varchar2_list( 'A_Column', 'SOME_COL' ) )
86+
.exclude( 'SOME_COL' );
87+
end;
88+
```
89+
90+
Only the columns 'RN', "A_Column" will be compared. Column 'SOME_COL' is excluded.
91+
92+
This option can be useful in scenarios where you need to narrow-down the scope of test so that the test is only focused on very specific data.
93+
94+
## Defining item as XPath
95+
When using XPath expression, keep in mind the following:
96+
97+
- cursor columns are nested under `<ROW>` element
98+
- object type attributes are nested under `<OBJECTY_TYPE>` element
99+
- nested table and varray items type attributes are nested under `<ARRAY><OBJECTY_TYPE>` elements
100+
101+
```sql
102+
procedure include_columns_as_xpath is
103+
l_actual sys_refcursor;
104+
l_expected sys_refcursor;
105+
begin
106+
open l_expected for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL from dual a connect by level < 4;
107+
open l_actual for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL, a.* from all_objects a where rownum < 4;
108+
ut.expect( l_actual ).to_equal( l_expected ).include( '/ROW/RN|/ROW/A_Column|/ROW/SOME_COL' );
109+
end;
110+
```

docs/userguide/annotations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ The annotation cache is checked for staleness and refreshed automatically on eve
224224

225225
If you are in a situation where your database is controlled via CI/CD server and is refreshed/wiped before each run of your tests, consider building the annotation cache upfront and taking a snapshot of the database after the cache has been refreshed.
226226

227-
To build the annotation cache without actually invoking any tests, call `ut_runner.rebuild_annotation_cache(a_object_owner, a_object_type)` for every unit test owner for which you want to have the annotation cache prebuilt.
227+
To build the annotation cache without actually invoking any tests, call `ut_runner.rebuild_annotation_cache(a_object_owner)` for every unit test owner for which you want to have the annotation cache prebuilt.
228228
Example:
229229
```sql
230-
exec ut_runner.rebuild_annotation_cache('HR', 'PACKAGE');
230+
exec ut_runner.rebuild_annotation_cache('HR');
231231
```
232232

233-
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner, a_object_type)`.
233+
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner)`.
234234
Example:
235235
```sql
236236
exec ut_runner.purge_cache('HR', 'PACKAGE');

0 commit comments

Comments
 (0)