0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

assert msg shell

This commit is contained in:
Dwight 2010-06-16 15:23:03 -04:00
parent d48e363d6b
commit c15eb9182a
2 changed files with 78 additions and 58 deletions

View File

@ -10,14 +10,17 @@ const char * jsconcatcode =
"if ( tojson( a ) == tojson( b ) )\n"
"return true;\n"
"return false;}\n"
"doassert = function( msg ){\n"
"print( \"assert: \" + msg );\n"
"doassert = function (msg) {\n"
"if (msg.indexOf(\"assert\") == 0)\n"
"print(msg);\n"
"else\n"
"print(\"assert: \" + msg);\n"
"throw msg;}\n"
"assert = function( b , msg ){\n"
"if ( assert._debug && msg ) print( \"in assert for: \" + msg );\n"
"if ( b )\n"
"return;\n"
"doassert( \"assert failed : \" + msg );}\n"
"doassert( msg == undefined ? \"assert failed\" : \"assert failed : \" + msg );}\n"
"assert.automsg = function( b ) {\n"
"assert( eval( b ), b );}\n"
"assert._debug = false;\n"
@ -215,6 +218,8 @@ const char * jsconcatcode =
"ObjectId.prototype.tojson = function(){\n"
"return \"ObjectId(\\\"\" + this.str + \"\\\")\";}\n"
"ObjectId.prototype.isObjectId = true;\n"
"ObjectId.prototype.getTimestamp = function(){\n"
"return new Date(parseInt(this.toString().slice(0,8), 16)*1000);}\n"
"if ( typeof( DBPointer ) != \"undefined\" ){\n"
"DBPointer.prototype.fetch = function(){\n"
"assert( this.ns , \"need a ns\" );\n"
@ -317,6 +322,7 @@ const char * jsconcatcode =
"\"jstests/indexb.js\",\n"
"\"jstests/profile1.js\",\n"
"\"jstests/mr3.js\",\n"
"\"jstests/indexh.js\",\n"
"\"jstests/apitest_db.js\"] );\n"
"var serialTestsArr = [ \"jstests/fsync.js\",\n"
"\"jstests/fsync2.js\" ];\n"
@ -505,8 +511,9 @@ const char * jsconcatcode =
"print(\"\\thostname() returns name of this host\");\n"
"print(\"\\tremoveFile(f) delete a file\");\n"
"print(\"\\tload(jsfilename) load and execute a .js file\");\n"
"print(\"\\trun(program[, args...]) spawn a program and wait for its completion\");\n"
"print(\"\\tsleep(m) sleep m milliseconds\");\n"
"return;}\n"
"print(\"\\tgetMemInfo() diagnostic\");}\n"
"if (x == \"test\") {\n"
"print(\"\\tstartMongodEmpty(args) DELETES DATA DIR and then starts mongod\");\n"
"print(\"\\t returns a connection to the new server\");\n"
@ -521,7 +528,7 @@ const char * jsconcatcode =
"print(\"\\t\" + \"show collections show collections in current database\");\n"
"print(\"\\t\" + \"show users show users in current database\");\n"
"print(\"\\t\" + \"show profile show most recent system.profile entries with time >= 1ms\");\n"
"print(\"\\t\" + \"use <db name> set curent database to <db name>\");\n"
"print(\"\\t\" + \"use <db name> set current database to <db name>\");\n"
"print(\"\\t\" + \"db.help() help on DB methods\");\n"
"print(\"\\t\" + \"db.foo.help() help on collection methods\");\n"
"print(\"\\t\" + \"db.foo.find() list objects in collection foo\");\n"
@ -1118,18 +1125,22 @@ const char * jsconcatcode =
"this._special = false;\n"
"this._prettyShell = false;}\n"
"print( \"DBQuery probably won't have array access \" );}\n"
"DBQuery.prototype.help = function(){\n"
"print( \"DBQuery help\" );\n"
"print( \"\\t.sort( {...} )\" )\n"
"print( \"\\t.limit( n )\" )\n"
"print( \"\\t.skip( n )\" )\n"
"print( \"\\t.count() - total # of objects matching query, ignores skip,limit\" )\n"
"print( \"\\t.size() - total # of objects cursor would return skip,limit effect this\" )\n"
"print( \"\\t.explain()\" )\n"
"print( \"\\t.forEach( func )\" )\n"
"print( \"\\t.print() - output to console in full pretty format\" )\n"
"print( \"\\t.map( func )\" )\n"
"print( \"\\t.showDiskLoc() - adds a $diskLoc field to each returned object\" )}\n"
"DBQuery.prototype.help = function () {\n"
"print(\"find() modifiers\")\n"
"print(\"\\t.sort( {...} )\")\n"
"print(\"\\t.limit( n )\")\n"
"print(\"\\t.skip( n )\")\n"
"print(\"\\t.count() - total # of objects matching query, ignores skip,limit\")\n"
"print(\"\\t.size() - total # of objects cursor would return, honors skip,limit\")\n"
"print(\"\\t.explain([verbose])\")\n"
"print(\"\\t.hint(...)\")\n"
"print(\"\\t.showDiskLoc() - adds a $diskLoc field to each returned object\")\n"
"print(\"\\nCursor methods\");\n"
"print(\"\\t.forEach( func )\")\n"
"print(\"\\t.print() - output to console in full pretty format\")\n"
"print(\"\\t.map( func )\")\n"
"print(\"\\t.hasNext()\")\n"
"print(\"\\t.next()\")}\n"
"DBQuery.prototype.clone = function(){\n"
"var q = new DBQuery( this._mongo , this._db , this._collection , this._ns ,\n"
"this._query , this._fields ,\n"
@ -1247,12 +1258,17 @@ const char * jsconcatcode =
"return a;}\n"
"DBQuery.prototype.arrayAccess = function( idx ){\n"
"return this.toArray()[idx];}\n"
"DBQuery.prototype.explain = function(){\n"
"DBQuery.prototype.explain = function (verbose) {\n"
"/* verbose=true --> include allPlans, oldPlan fields */\n"
"var n = this.clone();\n"
"n._ensureSpecial();\n"
"n._query.$explain = true;\n"
"n._limit = n._limit * -1;\n"
"return n.next();}\n"
"var e = n.next();\n"
"if (!verbose) {\n"
"delete e.allPlans;\n"
"delete e.oldPlan;}\n"
"return e;}\n"
"DBQuery.prototype.snapshot = function(){\n"
"this._ensureSpecial();\n"
"this._query.$snapshot = true;\n"
@ -1292,40 +1308,41 @@ const char * jsconcatcode =
"assert( this._mongo , \"no mongo in DBCollection\" );}\n"
"DBCollection.prototype.getName = function(){\n"
"return this._shortName;}\n"
"DBCollection.prototype.help = function() {\n"
"DBCollection.prototype.help = function () {\n"
"var shortName = this.getName();\n"
"print(\"DBCollection help\");\n"
"print(\"\\tdb.\"+shortName+\".count()\");\n"
"print(\"\\tdb.\"+shortName+\".dataSize()\");\n"
"print(\"\\tdb.\"+shortName+\".distinct( key ) - eg. db.\"+shortName+\".distinct( 'x' )\");\n"
"print(\"\\tdb.\"+shortName+\".drop() drop the collection\");\n"
"print(\"\\tdb.\"+shortName+\".dropIndex(name)\");\n"
"print(\"\\tdb.\"+shortName+\".dropIndexes()\");\n"
"print(\"\\tdb.\"+shortName+\".ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups\");\n"
"print(\"\\tdb.\"+shortName+\".reIndex()\");\n"
"print(\"\\tdb.\"+shortName+\".find( [query] , [fields]) - first parameter is an optional query filter. second parameter is optional set of fields to return.\");\n"
"print(\"\\t e.g. db.\"+shortName+\".find( { x : 77 } , { name : 1 , x : 1 } )\");\n"
"print(\"\\tdb.\"+shortName+\".find(...).count()\");\n"
"print(\"\\tdb.\"+shortName+\".find(...).limit(n)\");\n"
"print(\"\\tdb.\"+shortName+\".find(...).skip(n)\");\n"
"print(\"\\tdb.\"+shortName+\".find(...).sort(...)\");\n"
"print(\"\\tdb.\"+shortName+\".findOne([query])\");\n"
"print(\"\\tdb.\"+shortName+\".findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )\");\n"
"print(\"\\tdb.\"+shortName+\".getDB() get DB object associated with collection\");\n"
"print(\"\\tdb.\"+shortName+\".getIndexes()\");\n"
"print(\"\\tdb.\"+shortName+\".group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )\");\n"
"print(\"\\tdb.\"+shortName+\".mapReduce( mapFunction , reduceFunction , <optional params> )\");\n"
"print(\"\\tdb.\"+shortName+\".remove(query)\");\n"
"print(\"\\tdb.\"+shortName+\".renameCollection( newName , <dropTarget> ) renames the collection.\");\n"
"print(\"\\tdb.\"+shortName+\".runCommand( name , <options> ) runs a db command with the given name where the 1st param is the colleciton name\" );\n"
"print(\"\\tdb.\"+shortName+\".save(obj)\");\n"
"print(\"\\tdb.\"+shortName+\".stats()\");\n"
"print(\"\\tdb.\"+shortName+\".storageSize() - includes free space allocated to this collection\");\n"
"print(\"\\tdb.\"+shortName+\".totalIndexSize() - size in bytes of all the indexes\");\n"
"print(\"\\tdb.\"+shortName+\".totalSize() - storage allocated for all data and indexes\");\n"
"print(\"\\tdb.\"+shortName+\".update(query, object[, upsert_bool, multi_bool])\");\n"
"print(\"\\tdb.\"+shortName+\".validate() - SLOW\");\n"
"print(\"\\tdb.\"+shortName+\".getShardVersion() - only for use with sharding\");\n"
"print(\"\\tdb.\" + shortName + \".find().help() - show DBCursor help\");\n"
"print(\"\\tdb.\" + shortName + \".count()\");\n"
"print(\"\\tdb.\" + shortName + \".dataSize()\");\n"
"print(\"\\tdb.\" + shortName + \".distinct( key ) - eg. db.\" + shortName + \".distinct( 'x' )\");\n"
"print(\"\\tdb.\" + shortName + \".drop() drop the collection\");\n"
"print(\"\\tdb.\" + shortName + \".dropIndex(name)\");\n"
"print(\"\\tdb.\" + shortName + \".dropIndexes()\");\n"
"print(\"\\tdb.\" + shortName + \".ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups\");\n"
"print(\"\\tdb.\" + shortName + \".reIndex()\");\n"
"print(\"\\tdb.\" + shortName + \".find( [query] , [fields]) - first parameter is an optional query filter. second parameter is optional set of fields to return.\");\n"
"print(\"\\t e.g. db.\" + shortName + \".find( { x : 77 } , { name : 1 , x : 1 } )\");\n"
"print(\"\\tdb.\" + shortName + \".find(...).count()\");\n"
"print(\"\\tdb.\" + shortName + \".find(...).limit(n)\");\n"
"print(\"\\tdb.\" + shortName + \".find(...).skip(n)\");\n"
"print(\"\\tdb.\" + shortName + \".find(...).sort(...)\");\n"
"print(\"\\tdb.\" + shortName + \".findOne([query])\");\n"
"print(\"\\tdb.\" + shortName + \".findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )\");\n"
"print(\"\\tdb.\" + shortName + \".getDB() get DB object associated with collection\");\n"
"print(\"\\tdb.\" + shortName + \".getIndexes()\");\n"
"print(\"\\tdb.\" + shortName + \".group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )\");\n"
"print(\"\\tdb.\" + shortName + \".mapReduce( mapFunction , reduceFunction , <optional params> )\");\n"
"print(\"\\tdb.\" + shortName + \".remove(query)\");\n"
"print(\"\\tdb.\" + shortName + \".renameCollection( newName , <dropTarget> ) renames the collection.\");\n"
"print(\"\\tdb.\" + shortName + \".runCommand( name , <options> ) runs a db command with the given name where the 1st param is the colleciton name\");\n"
"print(\"\\tdb.\" + shortName + \".save(obj)\");\n"
"print(\"\\tdb.\" + shortName + \".stats()\");\n"
"print(\"\\tdb.\" + shortName + \".storageSize() - includes free space allocated to this collection\");\n"
"print(\"\\tdb.\" + shortName + \".totalIndexSize() - size in bytes of all the indexes\");\n"
"print(\"\\tdb.\" + shortName + \".totalSize() - storage allocated for all data and indexes\");\n"
"print(\"\\tdb.\" + shortName + \".update(query, object[, upsert_bool, multi_bool])\");\n"
"print(\"\\tdb.\" + shortName + \".validate() - SLOW\");\n"
"print(\"\\tdb.\" + shortName + \".getShardVersion() - only for use with sharding\");\n"
"return __magicNoPrint;}\n"
"DBCollection.prototype.getFullName = function(){\n"
"return this._fullName;}\n"

View File

@ -15,12 +15,15 @@ friendlyEqual = function( a , b ){
return true;
return false;
}
doassert = function( msg ){
print( "assert: " + msg );
throw msg;
}
doassert = function (msg) {
if (msg.indexOf("assert") == 0)
print(msg);
else
print("assert: " + msg);
throw msg;
}
assert = function( b , msg ){
@ -29,7 +32,7 @@ assert = function( b , msg ){
if ( b )
return;
doassert( "assert failed : " + msg );
doassert( msg == undefined ? "assert failed" : "assert failed : " + msg );
}
assert.automsg = function( b ) {