summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2015-10-30 20:32:16 +1100
committerKevin Pulo <kevin.pulo@mongodb.com>2015-10-30 20:35:28 +1100
commit0c8b0d57c7072788e5f7f20af36214f0f9060099 (patch)
treeaeabaeead9a17e925c0d9e56b85339f54e6aebe2 /jstests/core
parent1ba041ab5d54d361fd04c0957493354caa99097b (diff)
downloadmongo-0c8b0d57c7072788e5f7f20af36214f0f9060099.tar.gz
SERVER-12746: Fix assert() calls with constant-value args
These calls were mostly mistakes that should have been assert.eq(). assert() will now trip if passed a non-string msg, or too many params.
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/apitest_dbcollection.js50
-rw-r--r--jstests/core/bulk_api_ordered.js2
-rw-r--r--jstests/core/bulk_api_unordered.js7
-rw-r--r--jstests/core/distinct4.js17
-rw-r--r--jstests/core/finda.js12
-rw-r--r--jstests/core/or1.js8
-rw-r--r--jstests/core/or2.js6
-rw-r--r--jstests/core/or3.js6
-rw-r--r--jstests/core/uniqueness.js12
9 files changed, 65 insertions, 55 deletions
diff --git a/jstests/core/apitest_dbcollection.js b/jstests/core/apitest_dbcollection.js
index 4142ef8d7dc..d60778363b8 100644
--- a/jstests/core/apitest_dbcollection.js
+++ b/jstests/core/apitest_dbcollection.js
@@ -1,5 +1,5 @@
/**
- * Tests for the db collection
+ * Tests for the db collection
*/
@@ -8,34 +8,34 @@
* test drop
*/
db.getCollection( "test_db" ).drop();
-assert(db.getCollection( "test_db" ).find().length() == 0,1);
+assert.eq(0, db.getCollection( "test_db" ).find().length(), "1");
db.getCollection( "test_db" ).save({a:1});
-assert(db.getCollection( "test_db" ).find().length() == 1,2);
+assert.eq(1, db.getCollection( "test_db" ).find().length(), "2");
db.getCollection( "test_db" ).drop();
-assert(db.getCollection( "test_db" ).find().length() == 0,3);
+assert.eq(0, db.getCollection( "test_db" ).find().length(), "3");
/*
* test count
*/
-
-assert(db.getCollection( "test_db" ).count() == 0,4);
+
+assert.eq(0, db.getCollection( "test_db" ).count(), "4");
db.getCollection( "test_db" ).save({a:1});
-assert(db.getCollection( "test_db" ).count() == 1,5);
+assert.eq(1, db.getCollection( "test_db" ).count(), "5");
for (i = 0; i < 100; i++) {
db.getCollection( "test_db" ).save({a:1});
}
-assert(db.getCollection( "test_db" ).count() == 101,6);
+assert.eq(101, db.getCollection( "test_db" ).count(), "6");
db.getCollection( "test_db" ).drop();
-assert(db.getCollection( "test_db" ).count() == 0,7);
-
+assert.eq(0, db.getCollection( "test_db" ).count(), "7");
+
/*
* test validate
*/
db.getCollection( "test_db" ).drop();
-assert(db.getCollection( "test_db" ).count() == 0,8);
+assert.eq(0, db.getCollection( "test_db" ).count(), "8");
for (i = 0; i < 100; i++) {
db.getCollection( "test_db" ).save({a:1});
@@ -82,59 +82,59 @@ for (i = 0; i < 100; i++) {
/*
* test deleteIndex, deleteIndexes
*/
-
+
db.getCollection( "test_db" ).drop();
-assert(db.getCollection( "test_db" ).count() == 0,12);
+assert.eq(0, db.getCollection( "test_db" ).count(), "12");
db.getCollection( "test_db" ).dropIndexes();
-assert(db.getCollection( "test_db" ).getIndexes().length == 0,13);
+assert.eq(0, db.getCollection( "test_db" ).getIndexes().length, "13");
db.getCollection( "test_db" ).save({a:10});
-assert(db.getCollection( "test_db" ).getIndexes().length == 1,14);
+assert.eq(1, db.getCollection( "test_db" ).getIndexes().length, "14");
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).save({a:10});
print( tojson( db.getCollection( "test_db" ).getIndexes() ) );
-assert.eq(db.getCollection( "test_db" ).getIndexes().length , 2,15);
+assert.eq(2, db.getCollection( "test_db" ).getIndexes().length, "15");
db.getCollection( "test_db" ).dropIndex({a:1});
-assert(db.getCollection( "test_db" ).getIndexes().length == 1,16);
+assert.eq(1, db.getCollection( "test_db" ).getIndexes().length, "16");
db.getCollection( "test_db" ).save({a:10});
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).save({a:10});
-assert(db.getCollection( "test_db" ).getIndexes().length == 2,17);
+assert.eq(2, db.getCollection( "test_db" ).getIndexes().length, "17");
db.getCollection( "test_db" ).dropIndex("a_1");
-assert.eq( db.getCollection( "test_db" ).getIndexes().length , 1,18);
+assert.eq(1, db.getCollection( "test_db" ).getIndexes().length, "18");
db.getCollection( "test_db" ).save({a:10, b:11});
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).ensureIndex({b:1});
db.getCollection( "test_db" ).save({a:10, b:12});
-assert(db.getCollection( "test_db" ).getIndexes().length == 3,19);
+assert.eq(3, db.getCollection( "test_db" ).getIndexes().length, "19");
db.getCollection( "test_db" ).dropIndex({b:1});
-assert(db.getCollection( "test_db" ).getIndexes().length == 2,20);
+assert.eq(2, db.getCollection( "test_db" ).getIndexes().length, "20");
db.getCollection( "test_db" ).dropIndex({a:1});
-assert(db.getCollection( "test_db" ).getIndexes().length == 1,21);
+assert.eq(1, db.getCollection( "test_db" ).getIndexes().length, "21");
db.getCollection( "test_db" ).save({a:10, b:11});
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).ensureIndex({b:1});
db.getCollection( "test_db" ).save({a:10, b:12});
-assert(db.getCollection( "test_db" ).getIndexes().length == 3,22);
+assert.eq(3, db.getCollection( "test_db" ).getIndexes().length, "22");
db.getCollection( "test_db" ).dropIndexes();
-assert(db.getCollection( "test_db" ).getIndexes().length == 1,23);
+assert.eq(1, db.getCollection( "test_db" ).getIndexes().length, "23");
db.getCollection( "test_db" ).find();
db.getCollection( "test_db" ).drop();
-assert(db.getCollection( "test_db" ).getIndexes().length == 0,24);
+assert.eq(0, db.getCollection( "test_db" ).getIndexes().length, "24");
/*
* stats()
diff --git a/jstests/core/bulk_api_ordered.js b/jstests/core/bulk_api_ordered.js
index beef9d24411..6cc032f68fc 100644
--- a/jstests/core/bulk_api_ordered.js
+++ b/jstests/core/bulk_api_ordered.js
@@ -124,7 +124,7 @@ var executeTests = function() {
// Basic properties check
assert.eq(1, result.nInserted);
assert.eq(true, result.hasWriteErrors());
- assert(1, result.getWriteErrorCount());
+ assert.eq(1, result.getWriteErrorCount());
// Individual error checking
var error = result.getWriteErrorAt(0);
diff --git a/jstests/core/bulk_api_unordered.js b/jstests/core/bulk_api_unordered.js
index 1c8607dec37..64893fe011a 100644
--- a/jstests/core/bulk_api_unordered.js
+++ b/jstests/core/bulk_api_unordered.js
@@ -50,7 +50,8 @@ var executeTests = function() {
assert.eq(4, result.nModified);
}
assert.eq(2, result.nRemoved);
- assert(1, result.getWriteErrorCount());
+ assert.eq(false, result.hasWriteErrors());
+ assert.eq(0, result.getWriteErrorCount());
var upserts = result.getUpsertedIds();
assert.eq(2, upserts.length);
assert.eq(3, upserts[0].index);
@@ -88,7 +89,7 @@ var executeTests = function() {
// Basic properties check
assert.eq(2, result.nInserted);
assert.eq(true, result.hasWriteErrors());
- assert(1, result.getWriteErrorCount());
+ assert.eq(1, result.getWriteErrorCount());
// Get the first error
var error = result.getWriteErrorAt(0);
@@ -123,7 +124,7 @@ var executeTests = function() {
assert.eq(2, result.nInserted);
assert.eq(1, result.nUpserted);
assert.eq(true, result.hasWriteErrors());
- assert(3, result.getWriteErrorCount());
+ assert.eq(3, result.getWriteErrorCount());
// Individual error checking
var error = result.getWriteErrorAt(0);
diff --git a/jstests/core/distinct4.js b/jstests/core/distinct4.js
index 5e4a1fd85a2..1fa2763bf40 100644
--- a/jstests/core/distinct4.js
+++ b/jstests/core/distinct4.js
@@ -15,7 +15,7 @@
//first argument should be a string or error
// from shell helper
- assert.throws( t.distinct, [{a:1}] );
+ assert.throws( function () { t.distinct({a:1}); } );
// from command interface
assert.commandFailedWithCode(t.runCommand("distinct", {"key": {a: 1}}),
@@ -25,7 +25,7 @@
//second argument should be a document or error
// from shell helper
- assert.throws( t.distinct, ['a', '1'] );
+ assert.throws( function () { t.distinct('a', '1'); } );
// from command interface
assert.commandFailedWithCode(t.runCommand("distinct", {"key": "a", "query": "a"}),
@@ -34,8 +34,17 @@
// empty query clause should not cause error
- assert( t.runCommand( "distinct", { "key" : "a" } ) );
- assert( t.distinct, ['a'] );
+ // from shell helper
+ var a = assert.doesNotThrow( function () { return t.distinct('a'); } );
+ // [ null, 1, 2, 3 ]
+ assert.eq(4, a.length, tojson(a));
+ assert.contains(null, a);
+ assert.contains(1, a);
+ assert.contains(2, a);
+ assert.contains(3, a);
+
+ // from command interface
+ assert.commandWorked( t.runCommand( "distinct", { "key" : "a" } ) );
})();
diff --git a/jstests/core/finda.js b/jstests/core/finda.js
index 05d87c40972..4017ce91ad5 100644
--- a/jstests/core/finda.js
+++ b/jstests/core/finda.js
@@ -13,15 +13,15 @@ function clearQueryPlanCache() {
function assertAllFound( matches ) {
// printjson( matches );
found = new Array( numDocs );
- for( i = 0; i < numDocs; ++i ) {
+ for( var i = 0; i < numDocs; ++i ) {
found[ i ] = false;
}
- for( i in matches ) {
+ for( var i in matches ) {
m = matches[ i ];
found[ m._id ] = true;
}
- for( i = 0; i < numDocs; ++i ) {
- assert( found[ i ], i );
+ for( var i = 0; i < numDocs; ++i ) {
+ assert( found[ i ], i.toString() );
}
}
@@ -66,7 +66,7 @@ function checkCursorWithBatchSize( query, sort, batchSize, expectedLeftInBatch )
if ( expectedLeftInBatch > 110 ) {
cursor = makeCursor( query, {}, sort, batchSize, true );
lastNonAIndexResult = -1;
- for( i = 0; i < expectedLeftInBatch; ++i ) {
+ for( var i = 0; i < expectedLeftInBatch; ++i ) {
next = cursor.next();
// Identify the query plan used by checking the fields of a returnKey query.
if ( !friendlyEqual( [ 'a', '_id' ], Object.keySet( next ) ) ) {
@@ -80,7 +80,7 @@ function checkCursorWithBatchSize( query, sort, batchSize, expectedLeftInBatch )
function queryWithPlanTypes( withDups ) {
t.drop();
- for( i = 1; i < numDocs; ++i ) {
+ for( var i = 1; i < numDocs; ++i ) {
t.save( { _id:i, a:i, b:0 } );
}
if ( withDups ) {
diff --git a/jstests/core/or1.js b/jstests/core/or1.js
index 66bbd2e6eea..0153afe9115 100644
--- a/jstests/core/or1.js
+++ b/jstests/core/or1.js
@@ -1,14 +1,14 @@
t = db.jstests_or1;
t.drop();
-checkArrs = function( a, b, m ) {
- assert.eq( a.length, b.length, m );
+checkArrs = function( a, b ) {
+ assert.eq( a.length, b.length );
aStr = [];
bStr = [];
a.forEach( function( x ) { aStr.push( tojson( x ) ); } );
b.forEach( function( x ) { bStr.push( tojson( x ) ); } );
for ( i = 0; i < aStr.length; ++i ) {
- assert( -1 != bStr.indexOf( aStr[ i ] ), m );
+ assert.neq( -1, bStr.indexOf( aStr[ i ] ) );
}
}
@@ -54,4 +54,4 @@ doTest();
t.drop();
t.ensureIndex( {a:1,b:1} );
-doTest(); \ No newline at end of file
+doTest();
diff --git a/jstests/core/or2.js b/jstests/core/or2.js
index f8de6c42ef9..cbbf51c0eaf 100644
--- a/jstests/core/or2.js
+++ b/jstests/core/or2.js
@@ -4,14 +4,14 @@ t.drop();
// Include helpers for analyzing explain output.
load("jstests/libs/analyze_plan.js");
-checkArrs = function( a, b, m ) {
- assert.eq( a.length, b.length, m );
+checkArrs = function( a, b ) {
+ assert.eq( a.length, b.length );
aStr = [];
bStr = [];
a.forEach( function( x ) { aStr.push( tojson( x ) ); } );
b.forEach( function( x ) { bStr.push( tojson( x ) ); } );
for ( i = 0; i < aStr.length; ++i ) {
- assert( -1 != bStr.indexOf( aStr[ i ] ), m );
+ assert.neq( -1, bStr.indexOf( aStr[ i ] ) );
}
}
diff --git a/jstests/core/or3.js b/jstests/core/or3.js
index 1dab4d55ecd..293a3f37164 100644
--- a/jstests/core/or3.js
+++ b/jstests/core/or3.js
@@ -4,14 +4,14 @@ t.drop();
// Include helpers for analyzing explain output.
load("jstests/libs/analyze_plan.js");
-checkArrs = function( a, b, m ) {
- assert.eq( a.length, b.length, m );
+checkArrs = function( a, b ) {
+ assert.eq( a.length, b.length );
aStr = [];
bStr = [];
a.forEach( function( x ) { aStr.push( tojson( x ) ); } );
b.forEach( function( x ) { bStr.push( tojson( x ) ); } );
for ( i = 0; i < aStr.length; ++i ) {
- assert( -1 != bStr.indexOf( aStr[ i ] ), m );
+ assert.neq( -1, bStr.indexOf( aStr[ i ] ) );
}
}
diff --git a/jstests/core/uniqueness.js b/jstests/core/uniqueness.js
index 9cde613bbe4..124748a91f4 100644
--- a/jstests/core/uniqueness.js
+++ b/jstests/core/uniqueness.js
@@ -12,7 +12,7 @@ assert.writeOK( res );
// this should yield an error
res = t.insert( { _id : 3 } );
assert.writeError( res );
-assert( t.count() == 1, "hmmm");
+assert.eq( 1, t.count() );
res = t.insert( { _id : 4, x : 99 } );
assert.writeOK( res );
@@ -20,13 +20,13 @@ assert.writeOK( res );
// this should yield an error
res = t.update( { _id : 4 } , { _id : 3, x : 99 } );
assert.writeError( res );
-assert( t.findOne( {_id:4} ), 5 );
+assert( t.findOne( {_id:4} ) );
// Check for an error message when we index and there are dups
db.jstests_uniqueness2.drop();
db.jstests_uniqueness2.insert({a:3});
db.jstests_uniqueness2.insert({a:3});
-assert( db.jstests_uniqueness2.count() == 2 , 6) ;
+assert.eq( 2, db.jstests_uniqueness2.count() );
res = db.jstests_uniqueness2.ensureIndex({a:1}, true);
assert.commandFailed( res );
assert( res.errmsg.match( /E11000/ ) );
@@ -35,7 +35,7 @@ assert( res.errmsg.match( /E11000/ ) );
db.jstests_uniqueness2.drop();
db.jstests_uniqueness2.insert({a:3});
db.jstests_uniqueness2.insert({a:3});
-assert( db.jstests_uniqueness2.count() == 2 , 6) ;
+assert.eq( 2, db.jstests_uniqueness2.count() );
res = db.jstests_uniqueness2.ensureIndex({a:1}, {unique:true,background:true});
assert.commandFailed( res );
assert( res.errmsg.match( /E11000/ ) );
@@ -46,11 +46,11 @@ assert( res.errmsg.match( /E11000/ ) );
t.drop();
t.save( { _id : 'Z' } );
t.update( {}, { k : 2 } );
-assert( t.findOne()._id == 'Z', "uniqueness.js problem with adding back _id" );
+assert.eq( 'Z', t.findOne()._id, "uniqueness.js problem with adding back _id" );
/* - test when doesn't grow */
t.drop();
t.save( { _id : 'Z', k : 3 } );
t.update( {}, { k : 2 } );
-assert( t.findOne()._id == 'Z', "uniqueness.js problem with adding back _id (2)" );
+assert.eq( 'Z', t.findOne()._id, "uniqueness.js problem with adding back _id (2)" );