This repository was archived by the owner on Sep 19, 2018. It is now read-only.
Repository navigation
Make assert_object_equals more accurate and give better error messages - #144
Closed
johnmellor wants to merge 1 commit into
Closed
johnmellor wants to merge 1 commit into
johnmellor wants to merge 1 commit into
Conversation
Consider the following tests:
test(function() {
assert_object_equals(false, true);
}, "1");
test(function() {
assert_object_equals(1, true);
}, "2");
test(function() {
assert_object_equals(false, {});
}, "3");
test(function() {
assert_object_equals({}, false);
}, "4");
test(function() {
assert_object_equals("abc", ["a", "b", "c"]);
}, "5");
test(function() {
assert_object_equals(["a", "b", "c"], "abc");
}, "6");
test(function() {
assert_object_equals({a:{}}, {a:false});
}, "7");
test(function() {
assert_object_equals({b:{}}, {b:null});
}, "8");
test(function() {
assert_object_equals({c:null}, {c:{}});
}, "9");
test(function() {
assert_object_equals({d:false}, {d:{}});
}, "10");
test(function() {
assert_object_equals({x:{y:{z:false}}}, {x:{y:{z:true}}});
}, "11");
Previously, the first 8 would incorrectly pass, and the last 3 would
give confusing error messages:
FAIL 9 assert_object_equals: property "c" expected object "[object Object]" got object "[object Object]"
FAIL 10 assert_object_equals: property "d" expected object "[object Object]" got object "[object Object]"
FAIL 11 assert_object_equals: property "z" expected object "[object Object]" got object "[object Object]"
After this patch, all the cases fail correctly and have clear error messages:
FAIL 1 assert_object_equals: expected true but got false
FAIL 2 assert_object_equals: expected (boolean) true but got (number) 1
FAIL 3 assert_object_equals: expected (object) object "[object Object]" but got (boolean) false
FAIL 4 assert_object_equals: expected (boolean) false but got (object) object "[object Object]"
FAIL 5 assert_object_equals: expected (object) ["a", "b", "c"] but got (string) "abc"
FAIL 6 assert_object_equals: expected (string) "abc" but got (object) ["a", "b", "c"]
FAIL 7 assert_object_equals: property ["a"]: expected (boolean) false but got (object) object "[object Object]"
FAIL 8 assert_object_equals: property ["b"]: expected null but got object "[object Object]"
FAIL 9 assert_object_equals: property ["c"]: expected object "[object Object]" but got null
FAIL 10 assert_object_equals: property ["d"]: expected (object) object "[object Object]" but got (boolean) false
FAIL 11 assert_object_equals: property ["x"]["y"]["z"]: expected true but got false
|
Critic review: https://critic.hoppipolla.co.uk/r/5759 This is an external review system which you may optionally use for the code review of your pull request. In order to help critic track your changes, please do not make in-place history rewrites (e.g. via |
Member
|
Thank you for the patch, but I really really just want this to die. It's too complex to be good for testing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As an alternative to #143, this pull request proposes to fix
assert_object_equals.Consider the following tests:
Previously, the first 8 would incorrectly pass, and the last 3 would
give confusing error messages:
After this patch, all the cases fail correctly and have clear error messages: