Skip to content

Improved failure message when comparing incomparable data-types. #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions source/expectations/matchers/ut_be_greater_or_equal.tps
Original file line number Diff line number Diff line change
@@ -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_comparison_matcher(
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions source/expectations/matchers/ut_be_greater_than.tps
Original file line number Diff line number Diff line change
@@ -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_comparison_matcher(
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions source/expectations/matchers/ut_be_less_or_equal.tps
Original file line number Diff line number Diff line change
@@ -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_comparison_matcher(
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions source/expectations/matchers/ut_be_less_than.tps
Original file line number Diff line number Diff line change
@@ -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_comparison_matcher(
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project
Expand All @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions source/expectations/matchers/ut_comparison_matcher.tpb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
create or replace type body ut_comparison_matcher 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;
/
22 changes: 22 additions & 0 deletions source/expectations/matchers/ut_comparison_matcher.tps
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
create or replace type ut_comparison_matcher 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
/
3 changes: 1 addition & 2 deletions source/expectations/matchers/ut_equal.tps
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create or replace type ut_equal under ut_matcher(
create or replace type ut_equal under ut_comparison_matcher(
/*
utPLSQL - Version X.X.X.X
Copyright 2016 - 2017 utPLSQL Project
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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_comparison_matcher.tps
@@expectations/matchers/ut_be_false.tps
@@expectations/matchers/ut_be_greater_or_equal.tps
@@expectations/matchers/ut_be_greater_than.tps
Expand Down Expand Up @@ -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_comparison_matcher.tpb
@@expectations/matchers/ut_be_false.tpb
@@expectations/matchers/ut_be_greater_or_equal.tpb
@@expectations/matchers/ut_be_greater_than.tpb
Expand Down
2 changes: 2 additions & 0 deletions source/uninstall.sql
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ drop type ut_be_less_than;

drop type ut_be_false;

drop type ut_comparison_matcher;

drop type ut_matcher;

drop type ut_data_value_yminterval;
Expand Down
2 changes: 2 additions & 0 deletions tests/RunAll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +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_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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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||'''' );
Expand Down