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

Skip to content

Commit b317d8d

Browse files
committed
Improved failure message when comparing incomparable data-types.
Fixes #334
1 parent f439b3d commit b317d8d

10 files changed

Lines changed: 64 additions & 11 deletions

source/expectations/matchers/ut_be_greater_or_equal.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_be_greater_or_equal under ut_matcher(
1+
create or replace type ut_be_greater_or_equal under ut_matcher_bi_operand(
22
/*
33
utPLSQL - Version X.X.X.X
44
Copyright 2016 - 2017 utPLSQL Project
@@ -15,7 +15,6 @@ create or replace type ut_be_greater_or_equal under ut_matcher(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18-
expected ut_data_value,
1918
member procedure init(self in out nocopy ut_be_greater_or_equal, a_expected ut_data_value),
2019
constructor function ut_be_greater_or_equal(self in out nocopy ut_be_greater_or_equal, a_expected date) return self as result,
2120
constructor function ut_be_greater_or_equal(self in out nocopy ut_be_greater_or_equal, a_expected number) return self as result,

source/expectations/matchers/ut_be_greater_than.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_be_greater_than under ut_matcher(
1+
create or replace type ut_be_greater_than under ut_matcher_bi_operand(
22
/*
33
utPLSQL - Version X.X.X.X
44
Copyright 2016 - 2017 utPLSQL Project
@@ -15,7 +15,6 @@ create or replace type ut_be_greater_than under ut_matcher(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18-
expected ut_data_value,
1918
member procedure init(self in out nocopy ut_be_greater_than, a_expected ut_data_value),
2019
constructor function ut_be_greater_than(self in out nocopy ut_be_greater_than, a_expected date) return self as result,
2120
constructor function ut_be_greater_than(self in out nocopy ut_be_greater_than, a_expected number) return self as result,

source/expectations/matchers/ut_be_less_or_equal.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_be_less_or_equal under ut_matcher(
1+
create or replace type ut_be_less_or_equal under ut_matcher_bi_operand(
22
/*
33
utPLSQL - Version X.X.X.X
44
Copyright 2016 - 2017 utPLSQL Project
@@ -15,7 +15,6 @@ create or replace type ut_be_less_or_equal under ut_matcher(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18-
expected ut_data_value,
1918
member procedure init(self in out nocopy ut_be_less_or_equal, a_expected ut_data_value),
2019
constructor function ut_be_less_or_equal(self in out nocopy ut_be_less_or_equal, a_expected date) return self as result,
2120
constructor function ut_be_less_or_equal(self in out nocopy ut_be_less_or_equal, a_expected number) return self as result,

source/expectations/matchers/ut_be_less_than.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_be_less_than under ut_matcher(
1+
create or replace type ut_be_less_than under ut_matcher_bi_operand(
22
/*
33
utPLSQL - Version X.X.X.X
44
Copyright 2016 - 2017 utPLSQL Project
@@ -15,7 +15,6 @@ create or replace type ut_be_less_than under ut_matcher(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18-
expected ut_data_value,
1918
member procedure init(self in out nocopy ut_be_less_than, a_expected ut_data_value),
2019
constructor function ut_be_less_than(self in out nocopy ut_be_less_than, a_expected date) return self as result,
2120
constructor function ut_be_less_than(self in out nocopy ut_be_less_than, a_expected number) return self as result,

source/expectations/matchers/ut_equal.tps

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
create or replace type ut_equal under ut_matcher(
1+
create or replace type ut_equal under ut_matcher_bi_operand(
22
/*
33
utPLSQL - Version X.X.X.X
44
Copyright 2016 - 2017 utPLSQL Project
@@ -15,7 +15,6 @@ create or replace type ut_equal under ut_matcher(
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
18-
expected ut_data_value,
1918
nulls_are_equal_flag number(1,0),
2019
member procedure init(self in out nocopy ut_equal, a_expected ut_data_value, a_nulls_are_equal boolean),
2120
member function equal_with_nulls( self in ut_equal, a_assert_result boolean, a_actual ut_data_value) return boolean,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
create or replace type body ut_matcher_bi_operand as
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
overriding member function error_message(a_actual ut_data_value) return varchar2 is
20+
l_result varchar2(32767);
21+
begin
22+
if ut_utils.int_to_boolean(self.is_errored) then
23+
l_result := 'Actual ('||a_actual.data_type||') cannot be compared to Expected ('||expected.data_type||') using matcher '''||self.name()||'''.';
24+
end if;
25+
return l_result;
26+
end;
27+
28+
end;
29+
/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
create or replace type ut_matcher_bi_operand under ut_matcher(
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
expected ut_data_value,
20+
overriding member function error_message(a_actual ut_data_value) return varchar2
21+
) not final not instantiable
22+
/

source/install.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ whenever sqlerror exit failure rollback
139139
@@expectations/data_values/ut_data_value_varchar2.tps
140140
@@expectations/data_values/ut_data_value_yminterval.tps
141141
@@expectations/matchers/ut_matcher.tps
142+
@@expectations/matchers/ut_matcher_bi_operand.tps
142143
@@expectations/matchers/ut_be_false.tps
143144
@@expectations/matchers/ut_be_greater_or_equal.tps
144145
@@expectations/matchers/ut_be_greater_than.tps
@@ -183,6 +184,7 @@ whenever sqlerror exit failure rollback
183184
@@expectations/data_values/ut_data_value_varchar2.tpb
184185
@@expectations/data_values/ut_data_value_yminterval.tpb
185186
@@expectations/matchers/ut_matcher.tpb
187+
@@expectations/matchers/ut_matcher_bi_operand.tpb
186188
@@expectations/matchers/ut_be_false.tpb
187189
@@expectations/matchers/ut_be_greater_or_equal.tpb
188190
@@expectations/matchers/ut_be_greater_than.tpb

source/uninstall.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ drop type ut_be_less_than;
133133

134134
drop type ut_be_false;
135135

136+
drop type ut_matcher_bi_operand;
137+
136138
drop type ut_matcher;
137139

138140
drop type ut_data_value_yminterval;

tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ declare
33
l_actual &&1 := &&3;
44
l_expected &&2 := &&4;
55
l_result integer;
6+
l_message varchar2(32767);
67
begin
78
--Act
89
ut.expect(l_actual).&&5.to_equal(l_expected);
910
l_result := ut_expectation_processor.get_status();
11+
l_message := ut_expectation_processor.get_expectations_results()(1).get_result_clob;
1012
--Assert
11-
if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success and l_result = ut_utils.tr_failure then
13+
if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success and l_result = ut_utils.tr_failure
14+
and l_message like 'Actual (%) cannot be compared to Expected (%) using matcher%' then
1215
:test_result := ut_utils.tr_success;
1316
else
1417
dbms_output.put_line('expected: '''||ut_utils.tr_failure||''', got: '''||l_result||'''' );

0 commit comments

Comments
 (0)