From b317d8dc0c44ee9323f33b52381509c3c137338a Mon Sep 17 00:00:00 2001 From: Jacek Date: Thu, 8 Jun 2017 00:59:04 +0100 Subject: [PATCH 1/3] Improved failure message when comparing incomparable data-types. Fixes #334 --- .../matchers/ut_be_greater_or_equal.tps | 3 +- .../matchers/ut_be_greater_than.tps | 3 +- .../matchers/ut_be_less_or_equal.tps | 3 +- .../expectations/matchers/ut_be_less_than.tps | 3 +- source/expectations/matchers/ut_equal.tps | 3 +- .../matchers/ut_matcher_bi_operand.tpb | 29 +++++++++++++++++++ .../matchers/ut_matcher_bi_operand.tps | 22 ++++++++++++++ source/install.sql | 2 ++ source/uninstall.sql | 2 ++ ...pect.to_equal.different_scalars.common.sql | 5 +++- 10 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 source/expectations/matchers/ut_matcher_bi_operand.tpb create mode 100644 source/expectations/matchers/ut_matcher_bi_operand.tps diff --git a/source/expectations/matchers/ut_be_greater_or_equal.tps b/source/expectations/matchers/ut_be_greater_or_equal.tps index e047b5086..7bf055bfa 100644 --- a/source/expectations/matchers/ut_be_greater_or_equal.tps +++ b/source/expectations/matchers/ut_be_greater_or_equal.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_greater_or_equal under ut_matcher( +create or replace type ut_be_greater_or_equal under ut_matcher_bi_operand( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project @@ -15,7 +15,6 @@ create or replace type ut_be_greater_or_equal under ut_matcher( See the License for the specific language governing permissions and limitations under the License. */ - expected ut_data_value, member procedure init(self in out nocopy ut_be_greater_or_equal, a_expected ut_data_value), constructor function ut_be_greater_or_equal(self in out nocopy ut_be_greater_or_equal, a_expected date) return self as result, constructor function ut_be_greater_or_equal(self in out nocopy ut_be_greater_or_equal, a_expected number) return self as result, diff --git a/source/expectations/matchers/ut_be_greater_than.tps b/source/expectations/matchers/ut_be_greater_than.tps index c5e1f5981..1e278a303 100644 --- a/source/expectations/matchers/ut_be_greater_than.tps +++ b/source/expectations/matchers/ut_be_greater_than.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_greater_than under ut_matcher( +create or replace type ut_be_greater_than under ut_matcher_bi_operand( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project @@ -15,7 +15,6 @@ create or replace type ut_be_greater_than under ut_matcher( See the License for the specific language governing permissions and limitations under the License. */ - expected ut_data_value, member procedure init(self in out nocopy ut_be_greater_than, a_expected ut_data_value), constructor function ut_be_greater_than(self in out nocopy ut_be_greater_than, a_expected date) return self as result, constructor function ut_be_greater_than(self in out nocopy ut_be_greater_than, a_expected number) return self as result, diff --git a/source/expectations/matchers/ut_be_less_or_equal.tps b/source/expectations/matchers/ut_be_less_or_equal.tps index e74cda21d..3c5027508 100644 --- a/source/expectations/matchers/ut_be_less_or_equal.tps +++ b/source/expectations/matchers/ut_be_less_or_equal.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_less_or_equal under ut_matcher( +create or replace type ut_be_less_or_equal under ut_matcher_bi_operand( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project @@ -15,7 +15,6 @@ create or replace type ut_be_less_or_equal under ut_matcher( See the License for the specific language governing permissions and limitations under the License. */ - expected ut_data_value, member procedure init(self in out nocopy ut_be_less_or_equal, a_expected ut_data_value), constructor function ut_be_less_or_equal(self in out nocopy ut_be_less_or_equal, a_expected date) return self as result, constructor function ut_be_less_or_equal(self in out nocopy ut_be_less_or_equal, a_expected number) return self as result, diff --git a/source/expectations/matchers/ut_be_less_than.tps b/source/expectations/matchers/ut_be_less_than.tps index 916c9600c..a479da0e2 100644 --- a/source/expectations/matchers/ut_be_less_than.tps +++ b/source/expectations/matchers/ut_be_less_than.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_less_than under ut_matcher( +create or replace type ut_be_less_than under ut_matcher_bi_operand( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project @@ -15,7 +15,6 @@ create or replace type ut_be_less_than under ut_matcher( See the License for the specific language governing permissions and limitations under the License. */ - expected ut_data_value, member procedure init(self in out nocopy ut_be_less_than, a_expected ut_data_value), constructor function ut_be_less_than(self in out nocopy ut_be_less_than, a_expected date) return self as result, constructor function ut_be_less_than(self in out nocopy ut_be_less_than, a_expected number) return self as result, diff --git a/source/expectations/matchers/ut_equal.tps b/source/expectations/matchers/ut_equal.tps index c9786c46b..843785aab 100644 --- a/source/expectations/matchers/ut_equal.tps +++ b/source/expectations/matchers/ut_equal.tps @@ -1,4 +1,4 @@ -create or replace type ut_equal under ut_matcher( +create or replace type ut_equal under ut_matcher_bi_operand( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project @@ -15,7 +15,6 @@ create or replace type ut_equal under ut_matcher( See the License for the specific language governing permissions and limitations under the License. */ - expected ut_data_value, nulls_are_equal_flag number(1,0), member procedure init(self in out nocopy ut_equal, a_expected ut_data_value, a_nulls_are_equal boolean), member function equal_with_nulls( self in ut_equal, a_assert_result boolean, a_actual ut_data_value) return boolean, diff --git a/source/expectations/matchers/ut_matcher_bi_operand.tpb b/source/expectations/matchers/ut_matcher_bi_operand.tpb new file mode 100644 index 000000000..5948d333c --- /dev/null +++ b/source/expectations/matchers/ut_matcher_bi_operand.tpb @@ -0,0 +1,29 @@ +create or replace type body ut_matcher_bi_operand as + /* + utPLSQL - Version X.X.X.X + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + overriding member function error_message(a_actual ut_data_value) return varchar2 is + l_result varchar2(32767); + begin + if ut_utils.int_to_boolean(self.is_errored) then + l_result := 'Actual ('||a_actual.data_type||') cannot be compared to Expected ('||expected.data_type||') using matcher '''||self.name()||'''.'; + end if; + return l_result; + end; + +end; +/ diff --git a/source/expectations/matchers/ut_matcher_bi_operand.tps b/source/expectations/matchers/ut_matcher_bi_operand.tps new file mode 100644 index 000000000..20218b99e --- /dev/null +++ b/source/expectations/matchers/ut_matcher_bi_operand.tps @@ -0,0 +1,22 @@ +create or replace type ut_matcher_bi_operand under ut_matcher( + /* + utPLSQL - Version X.X.X.X + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + expected ut_data_value, + overriding member function error_message(a_actual ut_data_value) return varchar2 +) not final not instantiable +/ diff --git a/source/install.sql b/source/install.sql index de4755654..5a43137a4 100644 --- a/source/install.sql +++ b/source/install.sql @@ -139,6 +139,7 @@ whenever sqlerror exit failure rollback @@expectations/data_values/ut_data_value_varchar2.tps @@expectations/data_values/ut_data_value_yminterval.tps @@expectations/matchers/ut_matcher.tps +@@expectations/matchers/ut_matcher_bi_operand.tps @@expectations/matchers/ut_be_false.tps @@expectations/matchers/ut_be_greater_or_equal.tps @@expectations/matchers/ut_be_greater_than.tps @@ -183,6 +184,7 @@ whenever sqlerror exit failure rollback @@expectations/data_values/ut_data_value_varchar2.tpb @@expectations/data_values/ut_data_value_yminterval.tpb @@expectations/matchers/ut_matcher.tpb +@@expectations/matchers/ut_matcher_bi_operand.tpb @@expectations/matchers/ut_be_false.tpb @@expectations/matchers/ut_be_greater_or_equal.tpb @@expectations/matchers/ut_be_greater_than.tpb diff --git a/source/uninstall.sql b/source/uninstall.sql index fe577d844..dec23646b 100644 --- a/source/uninstall.sql +++ b/source/uninstall.sql @@ -133,6 +133,8 @@ drop type ut_be_less_than; drop type ut_be_false; +drop type ut_matcher_bi_operand; + drop type ut_matcher; drop type ut_data_value_yminterval; diff --git a/tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql b/tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql index c9b11bdab..07a2ae730 100644 --- a/tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql +++ b/tests/ut_expectations/common/ut.expect.to_equal.different_scalars.common.sql @@ -3,12 +3,15 @@ declare l_actual &&1 := &&3; l_expected &&2 := &&4; l_result integer; + l_message varchar2(32767); begin --Act ut.expect(l_actual).&&5.to_equal(l_expected); l_result := ut_expectation_processor.get_status(); + l_message := ut_expectation_processor.get_expectations_results()(1).get_result_clob; --Assert - if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success and l_result = ut_utils.tr_failure then + if nvl(:test_result, ut_utils.tr_success) = ut_utils.tr_success and l_result = ut_utils.tr_failure + and l_message like 'Actual (%) cannot be compared to Expected (%) using matcher%' then :test_result := ut_utils.tr_success; else dbms_output.put_line('expected: '''||ut_utils.tr_failure||''', got: '''||l_result||'''' ); From 24090bd6ffaf318c478803b79744273e2d408c45 Mon Sep 17 00:00:00 2001 From: Jacek Date: Thu, 8 Jun 2017 23:23:33 +0100 Subject: [PATCH 2/3] Added new type to coverage reporting from tests. --- tests/RunAll.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/RunAll.sql b/tests/RunAll.sql index 340403b5b..e9b6b03c6 100644 --- a/tests/RunAll.sql +++ b/tests/RunAll.sql @@ -458,6 +458,8 @@ begin 'source/expectations/matchers/ut_match.tps', 'source/expectations/matchers/ut_matcher.tpb', 'source/expectations/matchers/ut_matcher.tps', + 'source/expectations/matchers/ut_matcher_bi_operand.tpb', + 'source/expectations/matchers/ut_matcher_bi_operand.tps', 'source/reporters/ut_ansiconsole_helper.pkb', 'source/reporters/ut_ansiconsole_helper.pks', 'source/reporters/ut_coverage_html_reporter.tpb', From 12d933ca0c141b1e3ee639a80afc1f125758d6cd Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 12 Jun 2017 21:06:39 +0100 Subject: [PATCH 3/3] Renamed base object from `ut_matcher_bi_operand` to `ut_comparison_matcher` --- source/expectations/matchers/ut_be_greater_or_equal.tps | 2 +- source/expectations/matchers/ut_be_greater_than.tps | 2 +- source/expectations/matchers/ut_be_less_or_equal.tps | 2 +- source/expectations/matchers/ut_be_less_than.tps | 2 +- .../{ut_matcher_bi_operand.tpb => ut_comparison_matcher.tpb} | 2 +- .../{ut_matcher_bi_operand.tps => ut_comparison_matcher.tps} | 2 +- source/expectations/matchers/ut_equal.tps | 2 +- source/install.sql | 4 ++-- source/uninstall.sql | 2 +- tests/RunAll.sql | 4 ++-- 10 files changed, 12 insertions(+), 12 deletions(-) rename source/expectations/matchers/{ut_matcher_bi_operand.tpb => ut_comparison_matcher.tpb} (94%) rename source/expectations/matchers/{ut_matcher_bi_operand.tps => ut_comparison_matcher.tps} (92%) diff --git a/source/expectations/matchers/ut_be_greater_or_equal.tps b/source/expectations/matchers/ut_be_greater_or_equal.tps index 7bf055bfa..6d5ac44c0 100644 --- a/source/expectations/matchers/ut_be_greater_or_equal.tps +++ b/source/expectations/matchers/ut_be_greater_or_equal.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_greater_or_equal under ut_matcher_bi_operand( +create or replace type ut_be_greater_or_equal under ut_comparison_matcher( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project diff --git a/source/expectations/matchers/ut_be_greater_than.tps b/source/expectations/matchers/ut_be_greater_than.tps index 1e278a303..c3c23f8d4 100644 --- a/source/expectations/matchers/ut_be_greater_than.tps +++ b/source/expectations/matchers/ut_be_greater_than.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_greater_than under ut_matcher_bi_operand( +create or replace type ut_be_greater_than under ut_comparison_matcher( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project diff --git a/source/expectations/matchers/ut_be_less_or_equal.tps b/source/expectations/matchers/ut_be_less_or_equal.tps index 3c5027508..2875c4d32 100644 --- a/source/expectations/matchers/ut_be_less_or_equal.tps +++ b/source/expectations/matchers/ut_be_less_or_equal.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_less_or_equal under ut_matcher_bi_operand( +create or replace type ut_be_less_or_equal under ut_comparison_matcher( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project diff --git a/source/expectations/matchers/ut_be_less_than.tps b/source/expectations/matchers/ut_be_less_than.tps index a479da0e2..cb881c468 100644 --- a/source/expectations/matchers/ut_be_less_than.tps +++ b/source/expectations/matchers/ut_be_less_than.tps @@ -1,4 +1,4 @@ -create or replace type ut_be_less_than under ut_matcher_bi_operand( +create or replace type ut_be_less_than under ut_comparison_matcher( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project diff --git a/source/expectations/matchers/ut_matcher_bi_operand.tpb b/source/expectations/matchers/ut_comparison_matcher.tpb similarity index 94% rename from source/expectations/matchers/ut_matcher_bi_operand.tpb rename to source/expectations/matchers/ut_comparison_matcher.tpb index 5948d333c..3493a1d5f 100644 --- a/source/expectations/matchers/ut_matcher_bi_operand.tpb +++ b/source/expectations/matchers/ut_comparison_matcher.tpb @@ -1,4 +1,4 @@ -create or replace type body ut_matcher_bi_operand as +create or replace type body ut_comparison_matcher as /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project diff --git a/source/expectations/matchers/ut_matcher_bi_operand.tps b/source/expectations/matchers/ut_comparison_matcher.tps similarity index 92% rename from source/expectations/matchers/ut_matcher_bi_operand.tps rename to source/expectations/matchers/ut_comparison_matcher.tps index 20218b99e..1a6835372 100644 --- a/source/expectations/matchers/ut_matcher_bi_operand.tps +++ b/source/expectations/matchers/ut_comparison_matcher.tps @@ -1,4 +1,4 @@ -create or replace type ut_matcher_bi_operand under ut_matcher( +create or replace type ut_comparison_matcher under ut_matcher( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project diff --git a/source/expectations/matchers/ut_equal.tps b/source/expectations/matchers/ut_equal.tps index 843785aab..74603f997 100644 --- a/source/expectations/matchers/ut_equal.tps +++ b/source/expectations/matchers/ut_equal.tps @@ -1,4 +1,4 @@ -create or replace type ut_equal under ut_matcher_bi_operand( +create or replace type ut_equal under ut_comparison_matcher( /* utPLSQL - Version X.X.X.X Copyright 2016 - 2017 utPLSQL Project diff --git a/source/install.sql b/source/install.sql index 5a43137a4..9bc514d08 100644 --- a/source/install.sql +++ b/source/install.sql @@ -139,7 +139,7 @@ whenever sqlerror exit failure rollback @@expectations/data_values/ut_data_value_varchar2.tps @@expectations/data_values/ut_data_value_yminterval.tps @@expectations/matchers/ut_matcher.tps -@@expectations/matchers/ut_matcher_bi_operand.tps +@@expectations/matchers/ut_comparison_matcher.tps @@expectations/matchers/ut_be_false.tps @@expectations/matchers/ut_be_greater_or_equal.tps @@expectations/matchers/ut_be_greater_than.tps @@ -184,7 +184,7 @@ whenever sqlerror exit failure rollback @@expectations/data_values/ut_data_value_varchar2.tpb @@expectations/data_values/ut_data_value_yminterval.tpb @@expectations/matchers/ut_matcher.tpb -@@expectations/matchers/ut_matcher_bi_operand.tpb +@@expectations/matchers/ut_comparison_matcher.tpb @@expectations/matchers/ut_be_false.tpb @@expectations/matchers/ut_be_greater_or_equal.tpb @@expectations/matchers/ut_be_greater_than.tpb diff --git a/source/uninstall.sql b/source/uninstall.sql index dec23646b..e8203d9bb 100644 --- a/source/uninstall.sql +++ b/source/uninstall.sql @@ -133,7 +133,7 @@ drop type ut_be_less_than; drop type ut_be_false; -drop type ut_matcher_bi_operand; +drop type ut_comparison_matcher; drop type ut_matcher; diff --git a/tests/RunAll.sql b/tests/RunAll.sql index 8f3942421..70a3480a6 100644 --- a/tests/RunAll.sql +++ b/tests/RunAll.sql @@ -463,8 +463,8 @@ begin 'source/expectations/matchers/ut_match.tps', 'source/expectations/matchers/ut_matcher.tpb', 'source/expectations/matchers/ut_matcher.tps', - 'source/expectations/matchers/ut_matcher_bi_operand.tpb', - 'source/expectations/matchers/ut_matcher_bi_operand.tps', + 'source/expectations/matchers/ut_comparison_matcher.tpb', + 'source/expectations/matchers/ut_comparison_matcher.tps', 'source/reporters/ut_ansiconsole_helper.pkb', 'source/reporters/ut_ansiconsole_helper.pks', 'source/reporters/ut_coverage_html_reporter.tpb',