diff options
author | David Bradford <david.bradford@mongodb.com> | 2018-02-20 10:59:52 -0500 |
---|---|---|
committer | David Bradford <david.bradford@mongodb.com> | 2018-02-20 10:59:52 -0500 |
commit | 13b35bc5cfb20be89eb46dc50208d344caf305bb (patch) | |
tree | de3c630a8c4b50032a0bccea517a226e23400708 | |
parent | f159e5bae15513c24a2e9dbc953ce4988ea4be53 (diff) | |
download | mongo-13b35bc5cfb20be89eb46dc50208d344caf305bb.tar.gz |
SERVER-32393 Use same comparison for eq and neq assertions
-rw-r--r-- | jstests/multiVersion/upgrade_cluster.js | 2 | ||||
-rw-r--r-- | jstests/noPassthrough/shell_assertions.js | 18 | ||||
-rw-r--r-- | src/mongo/shell/assert.js | 18 |
3 files changed, 32 insertions, 6 deletions
diff --git a/jstests/multiVersion/upgrade_cluster.js b/jstests/multiVersion/upgrade_cluster.js index 4f861ed7860..5769bed44ec 100644 --- a/jstests/multiVersion/upgrade_cluster.js +++ b/jstests/multiVersion/upgrade_cluster.js @@ -99,7 +99,7 @@ TestData.skipCheckingUUIDsConsistentAcrossCluster = true; version = st.s.getCollection('config.version').findOne(); assert.eq(version.minCompatibleVersion, 5); assert.eq(version.currentVersion, 6); - assert.neq(clusterID, version.clusterId); + assert.eq(clusterID, version.clusterId); assert.eq(version.excluding, undefined); st.stop(); diff --git a/jstests/noPassthrough/shell_assertions.js b/jstests/noPassthrough/shell_assertions.js index 299dbc00d53..75a0a7ee47e 100644 --- a/jstests/noPassthrough/shell_assertions.js +++ b/jstests/noPassthrough/shell_assertions.js @@ -182,6 +182,15 @@ assert.eq(true, called, 'msg function should have been called'); }); + tests.push(function eqShouldPassOnObjectsWithSameContent() { + const a = {'foo': true}; + const b = {'foo': true}; + + assert.doesNotThrow(() => { + assert.eq(a, b); + }, [], 'eq should not throw exception on two objects with the same content'); + }); + /* assert.eq.automsg tests */ tests.push(function eqAutomsgShouldCreateMessage() { @@ -207,6 +216,15 @@ }); }); + tests.push(function neqShouldFailOnObjectsWithSameContent() { + const a = {'foo': true}; + const b = {'foo': true}; + + assert.throws(() => { + assert.neq(a, b); + }, [], 'neq should throw exception on two objects with the same content'); + }); + /* assert.hasFields tests */ tests.push(function hasFieldsRequiresAnArrayOfFields() { diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js index da3f8fdc147..4f8d25d9eb6 100644 --- a/src/mongo/shell/assert.js +++ b/src/mongo/shell/assert.js @@ -152,14 +152,22 @@ assert = (function() { assert._debug = false; - assert.eq = function(a, b, msg) { - _validateAssertionMessage(msg); - + function _isEq(a, b) { if (a == b) { - return; + return true; } if ((a != null && b != null) && friendlyEqual(a, b)) { + return true; + } + + return false; + } + + assert.eq = function(a, b, msg) { + _validateAssertionMessage(msg); + + if (_isEq(a, b)) { return; } @@ -192,7 +200,7 @@ assert = (function() { assert.neq = function(a, b, msg) { _validateAssertionMessage(msg); - if (a != b) { + if (!_isEq(a, b)) { return; } |