| 1 |
define("doh/runner", ["dojo/_base/lang"], function(lang){ |
| 2 |
|
| 3 |
var doh = { |
| 4 |
|
| 5 |
|
| 6 |
}; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
tests = doh; |
| 11 |
this.doh = doh; |
| 12 |
|
| 13 |
doh._line = "------------------------------------------------------------"; |
| 14 |
|
| 15 |
doh.debug = function(){ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
}; |
| 22 |
|
| 23 |
doh.error = function(){ |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
}; |
| 31 |
|
| 32 |
doh._AssertFailure = function(msg, hint){ |
| 33 |
if (doh.breakOnError) { |
| 34 |
|
| 35 |
debugger; |
| 36 |
|
| 37 |
} |
| 38 |
if(!(this instanceof doh._AssertFailure)){ |
| 39 |
return new doh._AssertFailure(msg, hint); |
| 40 |
} |
| 41 |
if(hint){ |
| 42 |
msg = (new String(msg||""))+" with hint: \n\t\t"+(new String(hint)+"\n"); |
| 43 |
} |
| 44 |
this.message = new String(msg||""); |
| 45 |
return this; |
| 46 |
}; |
| 47 |
doh._AssertFailure.prototype = new Error(); |
| 48 |
doh._AssertFailure.prototype.constructor = doh._AssertFailure; |
| 49 |
doh._AssertFailure.prototype.name = "doh._AssertFailure"; |
| 50 |
|
| 51 |
doh.Deferred = function(canceller){ |
| 52 |
this.chain = []; |
| 53 |
this.id = this._nextId(); |
| 54 |
this.fired = -1; |
| 55 |
this.paused = 0; |
| 56 |
this.results = [null, null]; |
| 57 |
this.canceller = canceller; |
| 58 |
this.silentlyCancelled = false; |
| 59 |
}; |
| 60 |
|
| 61 |
lang.extend(doh.Deferred, { |
| 62 |
getTestErrback: function(cb, scope){ |
| 63 |
|
| 64 |
|
| 65 |
var _this = this; |
| 66 |
return function(){ |
| 67 |
try{ |
| 68 |
cb.apply(scope||doh.global||_this, arguments); |
| 69 |
}catch(e){ |
| 70 |
_this.reject(e); |
| 71 |
} |
| 72 |
}; |
| 73 |
}, |
| 74 |
|
| 75 |
getTestCallback: function(cb, scope){ |
| 76 |
var _this = this; |
| 77 |
return function(){ |
| 78 |
try{ |
| 79 |
cb.apply(scope||doh.global||_this, arguments); |
| 80 |
}catch(e){ |
| 81 |
_this.reject(e); |
| 82 |
return; |
| 83 |
} |
| 84 |
_this.resolve(true); |
| 85 |
}; |
| 86 |
}, |
| 87 |
|
| 88 |
_nextId: (function(){ |
| 89 |
var n = 1; |
| 90 |
return function(){ return n++; }; |
| 91 |
})(), |
| 92 |
|
| 93 |
cancel: function(){ |
| 94 |
if(this.fired == -1){ |
| 95 |
if (this.canceller){ |
| 96 |
this.canceller(this); |
| 97 |
}else{ |
| 98 |
this.silentlyCancelled = true; |
| 99 |
} |
| 100 |
if(this.fired == -1){ |
| 101 |
this.reject(new Error("Deferred(unfired)")); |
| 102 |
} |
| 103 |
}else if(this.fired == 0 && this.results[0] && this.results[0].cancel){ |
| 104 |
this.results[0].cancel(); |
| 105 |
} |
| 106 |
}, |
| 107 |
|
| 108 |
_pause: function(){ |
| 109 |
this.paused++; |
| 110 |
}, |
| 111 |
|
| 112 |
_unpause: function(){ |
| 113 |
this.paused--; |
| 114 |
if ((this.paused == 0) && (this.fired >= 0)) { |
| 115 |
this._fire(); |
| 116 |
} |
| 117 |
}, |
| 118 |
|
| 119 |
_continue: function(res){ |
| 120 |
this._resback(res); |
| 121 |
this._unpause(); |
| 122 |
}, |
| 123 |
|
| 124 |
_resback: function(res){ |
| 125 |
this.fired = ((res instanceof Error) ? 1 : 0); |
| 126 |
this.results[this.fired] = res; |
| 127 |
this._fire(); |
| 128 |
}, |
| 129 |
|
| 130 |
_check: function(){ |
| 131 |
if(this.fired != -1){ |
| 132 |
if(!this.silentlyCancelled){ |
| 133 |
throw new Error("already called!"); |
| 134 |
} |
| 135 |
this.silentlyCancelled = false; |
| 136 |
} |
| 137 |
}, |
| 138 |
|
| 139 |
resolve: function(res){ |
| 140 |
this._check(); |
| 141 |
this._resback(res); |
| 142 |
}, |
| 143 |
|
| 144 |
reject: function(res){ |
| 145 |
this._check(); |
| 146 |
if(!(res instanceof Error)){ |
| 147 |
res = new Error(res); |
| 148 |
} |
| 149 |
this._resback(res); |
| 150 |
}, |
| 151 |
|
| 152 |
then: function(cb, eb){ |
| 153 |
this.chain.push([cb, eb]); |
| 154 |
if(this.fired >= 0){ |
| 155 |
this._fire(); |
| 156 |
} |
| 157 |
return this; |
| 158 |
}, |
| 159 |
|
| 160 |
always: function(cb){ |
| 161 |
this.then(cb, cb); |
| 162 |
}, |
| 163 |
|
| 164 |
otherwise: function(eb){ |
| 165 |
this.then(null, eb); |
| 166 |
}, |
| 167 |
|
| 168 |
isFulfilled: function(){ |
| 169 |
return this.fired >= 0; |
| 170 |
}, |
| 171 |
|
| 172 |
isResolved: function(){ |
| 173 |
return this.fired == 0; |
| 174 |
}, |
| 175 |
|
| 176 |
isRejected: function(){ |
| 177 |
return this.fired == 1; |
| 178 |
}, |
| 179 |
|
| 180 |
_fire: function(){ |
| 181 |
var chain = this.chain; |
| 182 |
var fired = this.fired; |
| 183 |
var res = this.results[fired]; |
| 184 |
var self = this; |
| 185 |
var cb = null; |
| 186 |
while(chain.length > 0 && this.paused == 0){ |
| 187 |
|
| 188 |
var pair = chain.shift(); |
| 189 |
var f = pair[fired]; |
| 190 |
if(f == null){ |
| 191 |
continue; |
| 192 |
} |
| 193 |
try { |
| 194 |
res = f(res); |
| 195 |
fired = ((res instanceof Error) ? 1 : 0); |
| 196 |
if(res && res.then){ |
| 197 |
cb = function(res){ |
| 198 |
self._continue(res); |
| 199 |
}; |
| 200 |
this._pause(); |
| 201 |
} |
| 202 |
}catch(err){ |
| 203 |
fired = 1; |
| 204 |
res = err; |
| 205 |
} |
| 206 |
} |
| 207 |
this.fired = fired; |
| 208 |
this.results[fired] = res; |
| 209 |
if((cb)&&(this.paused)){ |
| 210 |
res.always(cb); |
| 211 |
} |
| 212 |
} |
| 213 |
}); |
| 214 |
|
| 215 |
lang.extend(doh.Deferred, { |
| 216 |
|
| 217 |
|
| 218 |
getFunctionFromArgs: function(){ |
| 219 |
|
| 220 |
var a = arguments; |
| 221 |
if((a[0])&&(!a[1])){ |
| 222 |
if(typeof a[0] == "function"){ |
| 223 |
return a[0]; |
| 224 |
}else if(typeof a[0] == "string"){ |
| 225 |
return doh.global[a[0]]; |
| 226 |
} |
| 227 |
}else if((a[0])&&(a[1])){ |
| 228 |
return lang.hitch(a[0], a[1]); |
| 229 |
} |
| 230 |
return null; |
| 231 |
}, |
| 232 |
|
| 233 |
addCallbacks: function(cb, eb){ |
| 234 |
this.then(cb, eb); |
| 235 |
}, |
| 236 |
|
| 237 |
addCallback: function(cb, cbfn){ |
| 238 |
var enclosed = this.getFunctionFromArgs(cb, cbfn); |
| 239 |
if(arguments.length > 2){ |
| 240 |
enclosed = lang.hitch(null, enclosed, arguments, 2); |
| 241 |
} |
| 242 |
return this.then(enclosed); |
| 243 |
}, |
| 244 |
|
| 245 |
addErrback: function(cb, cbfn){ |
| 246 |
var enclosed = this.getFunctionFromArgs(cb, cbfn); |
| 247 |
if(arguments.length > 2){ |
| 248 |
enclosed = lang.hitch(null, enclosed, arguments, 2); |
| 249 |
} |
| 250 |
return this.otherwise(enclosed); |
| 251 |
}, |
| 252 |
|
| 253 |
addBoth: function(cb, cbfn){ |
| 254 |
var enclosed = this.getFunctionFromArgs(cb, cbfn); |
| 255 |
if(arguments.length > 2){ |
| 256 |
enclosed = lang.hitch(null, enclosed, arguments, 2); |
| 257 |
} |
| 258 |
return this.always(enclosed); |
| 259 |
}, |
| 260 |
|
| 261 |
callback: function(val){ |
| 262 |
this.resolve(val); |
| 263 |
}, |
| 264 |
|
| 265 |
errback: function(val){ |
| 266 |
this.reject(val); |
| 267 |
} |
| 268 |
}); |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
doh._testCount = 0; |
| 275 |
doh._groupCount = 0; |
| 276 |
doh._errorCount = 0; |
| 277 |
doh._failureCount = 0; |
| 278 |
doh._currentGroup = null; |
| 279 |
doh._currentTest = null; |
| 280 |
doh._paused = true; |
| 281 |
|
| 282 |
doh._init = function(){ |
| 283 |
this._currentGroup = null; |
| 284 |
this._currentTest = null; |
| 285 |
this._errorCount = 0; |
| 286 |
this._failureCount = 0; |
| 287 |
this.debug(this._testCount, "tests to run in", this._groupCount, "groups"); |
| 288 |
}; |
| 289 |
|
| 290 |
doh._groups = {}; |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
doh._testTypes= {}; |
| 296 |
|
| 297 |
doh.registerTestType= function(name, initProc){ |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
doh._testTypes[name]= initProc; |
| 305 |
}; |
| 306 |
|
| 307 |
doh.registerTestType("perf", function(group, tObj, type){ |
| 308 |
|
| 309 |
|
| 310 |
if(type === "perf" || tObj.testType === "perf"){ |
| 311 |
tObj.testType = "perf"; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
if(!doh.perfTestResults){ |
| 316 |
doh.perfTestResults = {}; |
| 317 |
doh.perfTestResults[group] = {}; |
| 318 |
} |
| 319 |
if(!doh.perfTestResults[group]){ |
| 320 |
doh.perfTestResults[group] = {}; |
| 321 |
} |
| 322 |
if(!doh.perfTestResults[group][tObj.name]){ |
| 323 |
doh.perfTestResults[group][tObj.name] = {}; |
| 324 |
} |
| 325 |
tObj.results = doh.perfTestResults[group][tObj.name]; |
| 326 |
|
| 327 |
|
| 328 |
if(!("trialDuration" in tObj)){ |
| 329 |
tObj.trialDuration = 100; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
if(!("trialDelay" in tObj)){ |
| 335 |
tObj.trialDelay = 100; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
if(!("trialIterations" in tObj)){ |
| 340 |
tObj.trialIterations = 10; |
| 341 |
} |
| 342 |
} |
| 343 |
}); |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
var |
| 350 |
createFixture= function(group, test, type){ |
| 351 |
|
| 352 |
var tObj = test; |
| 353 |
if(lang.isString(test)){ |
| 354 |
tObj = { |
| 355 |
name: test.replace("/\s/g", "_"), |
| 356 |
runTest: new Function("t", test) |
| 357 |
}; |
| 358 |
}else if(lang.isFunction(test)){ |
| 359 |
|
| 360 |
tObj = { "runTest": test }; |
| 361 |
if(test["name"]){ |
| 362 |
tObj.name = test.name; |
| 363 |
}else{ |
| 364 |
try{ |
| 365 |
var fStr = "function "; |
| 366 |
var ts = tObj.runTest+""; |
| 367 |
if(0 <= ts.indexOf(fStr)){ |
| 368 |
tObj.name = ts.split(fStr)[1].split("(", 1)[0]; |
| 369 |
} |
| 370 |
|
| 371 |
}catch(e){ |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
}else if(lang.isString(tObj.runTest)){ |
| 376 |
tObj.runTest= new Function("t", tObj.runTest); |
| 377 |
} |
| 378 |
if(!tObj.runTest){ |
| 379 |
return 0; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
var testType= doh._testTypes[type] || doh._testTypes[tObj.testType]; |
| 384 |
if(testType){ |
| 385 |
testType(group, tObj); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
doh._groups[group].push(tObj); |
| 390 |
doh._testCount++; |
| 391 |
doh._testRegistered(group, tObj); |
| 392 |
|
| 393 |
return tObj; |
| 394 |
}, |
| 395 |
|
| 396 |
dumpArg= function(arg){ |
| 397 |
if(lang.isString(arg)){ |
| 398 |
return "string(" + arg + ")"; |
| 399 |
} else { |
| 400 |
return typeof arg; |
| 401 |
} |
| 402 |
}, |
| 403 |
|
| 404 |
illegalRegister= function(args, testArgPosition){ |
| 405 |
var hint= "\targuments: "; |
| 406 |
for(var i= 0; i<5; i++){ |
| 407 |
hint+= dumpArg(args[i]); |
| 408 |
} |
| 409 |
doh.debug("ERROR:"); |
| 410 |
if(testArgPosition){ |
| 411 |
doh.debug("\tillegal arguments provided to doh.register; the test at argument " + testArgPosition + " wasn't a test."); |
| 412 |
}else{ |
| 413 |
doh.debug("\tillegal arguments provided to doh.register"); |
| 414 |
} |
| 415 |
doh.debug(hint); |
| 416 |
}; |
| 417 |
|
| 418 |
doh._testRegistered = function(group, fixture){ |
| 419 |
|
| 420 |
}; |
| 421 |
|
| 422 |
doh._groupStarted = function(group){ |
| 423 |
|
| 424 |
}; |
| 425 |
|
| 426 |
doh._groupFinished = function(group, success){ |
| 427 |
|
| 428 |
}; |
| 429 |
|
| 430 |
doh._testStarted = function(group, fixture){ |
| 431 |
|
| 432 |
}; |
| 433 |
|
| 434 |
doh._testFinished = function(group, fixture, success){ |
| 435 |
|
| 436 |
}; |
| 437 |
|
| 438 |
doh._registerTest = function(group, test, type){ |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
var groupObj = this._groups[group]; |
| 453 |
if(!groupObj){ |
| 454 |
this._groupCount++; |
| 455 |
groupObj = this._groups[group] = []; |
| 456 |
groupObj.inFlight = 0; |
| 457 |
} |
| 458 |
if(!test){ |
| 459 |
return groupObj; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
var tObj; |
| 464 |
if(lang.isFunction(test) || lang.isString(test) || "runTest" in test){ |
| 465 |
return createFixture(group, test, type) ? groupObj : 0; |
| 466 |
}else if(lang.isArray(test)){ |
| 467 |
|
| 468 |
for(var i=0; i<test.length; i++){ |
| 469 |
tObj = createFixture(group, test[i], type); |
| 470 |
if(!tObj){ |
| 471 |
this.debug("ERROR:"); |
| 472 |
this.debug("\tillegal test is test array; more information follows..."); |
| 473 |
return null; |
| 474 |
} |
| 475 |
} |
| 476 |
return groupObj; |
| 477 |
}else{ |
| 478 |
|
| 479 |
for(var testName in test){ |
| 480 |
var theTest = test[testName]; |
| 481 |
if(lang.isFunction(theTest) || lang.isString(theTest)){ |
| 482 |
tObj = createFixture(group, {name: testName, runTest: theTest}, type); |
| 483 |
}else{ |
| 484 |
|
| 485 |
theTest.name = theTest.name || testName; |
| 486 |
tObj = createFixture(group, theTest, type); |
| 487 |
} |
| 488 |
if(!tObj){ |
| 489 |
this.debug("ERROR:"); |
| 490 |
this.debug("\tillegal test is test hash; more information follows..."); |
| 491 |
return null; |
| 492 |
} |
| 493 |
} |
| 494 |
return groupObj; |
| 495 |
} |
| 496 |
}; |
| 497 |
|
| 498 |
doh._registerTestAndCheck = function(groupId, test, type, testArgPosition, args, setUp, tearDown){ |
| 499 |
var amdMid = 0; |
| 500 |
if(groupId){ |
| 501 |
if(type){ |
| 502 |
|
| 503 |
var match = groupId.match(/([^\!]+)\!(.+)/); |
| 504 |
if(match){ |
| 505 |
amdMid = match[1]; |
| 506 |
groupId = match[2]; |
| 507 |
} |
| 508 |
}else{ |
| 509 |
var parts = groupId && groupId.split("!"); |
| 510 |
if(parts.length == 3){ |
| 511 |
amdMid = parts[0]; |
| 512 |
groupId = parts[1]; |
| 513 |
type = parts[2]; |
| 514 |
}else if(parts.length == 2){ |
| 515 |
|
| 516 |
if(parts[1] in doh._testTypes){ |
| 517 |
groupId = parts[0]; |
| 518 |
type = parts[1]; |
| 519 |
}else{ |
| 520 |
amdMid = parts[0]; |
| 521 |
groupId = parts[1]; |
| 522 |
} |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
var group = doh._registerTest(groupId, test, type); |
| 528 |
if(group){ |
| 529 |
if(amdMid){ |
| 530 |
group.amdMid = amdMid; |
| 531 |
} |
| 532 |
if(setUp){ |
| 533 |
group.setUp = setUp; |
| 534 |
} |
| 535 |
if(tearDown){ |
| 536 |
group.tearDown = tearDown; |
| 537 |
} |
| 538 |
}else{ |
| 539 |
illegalRegister(arguments, testArgPosition); |
| 540 |
} |
| 541 |
}; |
| 542 |
|
| 543 |
doh._registerUrl = function( group, url, timeout, type, dohArgs){ |
| 544 |
|
| 545 |
this.debug("ERROR:"); |
| 546 |
this.debug("\tNO registerUrl() METHOD AVAILABLE."); |
| 547 |
}; |
| 548 |
|
| 549 |
var typeSigs = (function(){ |
| 550 |
|
| 551 |
|
| 552 |
var sigs = [ |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
"test", function(args, a1){doh._registerTestAndCheck("ungrouped", a1, 0, 0, args, 0, 0);}, |
| 557 |
"url", function(args, a1){doh._registerUrl("ungrouped", a1);}, |
| 558 |
|
| 559 |
|
| 560 |
"group-test", function(args, a1, a2){doh._registerTestAndCheck(a1, a2, 0, 0, args, 0, 0);}, |
| 561 |
"test-type", function(args, a1, a2){doh._registerTestAndCheck("ungrouped", a1, a2, 1, args, 0, 0);}, |
| 562 |
"test-up", function(args, a1, a2){doh._registerTestAndCheck("ungrouped", a1, 0, 0, args, a2, 0);}, |
| 563 |
"group-url", function(args, a1, a2){doh._registerUrl(a1, a2);}, |
| 564 |
"url-to", function(args, a1, a2){doh._registerUrl("ungrouped", a1, a2);}, |
| 565 |
"url-type", function(args, a1, a2){doh._registerUrl("ungrouped", a1, undefined, a2);}, |
| 566 |
"url-args", function(args, a1, a2){doh._registerUrl("ungrouped", a1, undefined, 0, a2);}, |
| 567 |
|
| 568 |
|
| 569 |
"group-test-type", function(args, a1, a2, a3){doh._registerTestAndCheck(a1, a2, a3, 2, args, 0, 0);}, |
| 570 |
"group-test-up", function(args, a1, a2, a3){doh._registerTestAndCheck(a1, a2, 0, 2, args, a3, 0);}, |
| 571 |
"test-type-up", function(args, a1, a2, a3){doh._registerTestAndCheck("ungrouped", a1, a2, 0, args, a3, 0);}, |
| 572 |
"test-up-down", function(args, a1, a2, a3){doh._registerTestAndCheck("ungrouped", a1, 0, 0, args, a2, a3);}, |
| 573 |
"group-url-to", function(args, a1, a2, a3){doh._registerUrl(a1, a2, a3);}, |
| 574 |
"group-url-type", function(args, a1, a2, a3){doh._registerUrl(a1, a2, undefined, a3);}, |
| 575 |
"group-url-args", function(args, a1, a2, a3){doh._registerUrl(a1, a2, undefined, 0, a3);}, |
| 576 |
"url-to-type", function(args, a1, a2, a3){doh._registerUrl("ungrouped", a1, a2, a3);}, |
| 577 |
"url-to-args", function(args, a1, a2, a3){doh._registerUrl("ungrouped", a1, a2, 0, a3);}, |
| 578 |
"url-type-args", function(args, a1, a2, a3){doh._registerUrl("ungrouped", a1, undefined, a2, a3);}, |
| 579 |
|
| 580 |
|
| 581 |
"group-test-type-up", function(args, a1, a2, a3, a4){doh._registerTestAndCheck(a1, a2, a3, 2, args, a4, 0);}, |
| 582 |
"group-test-up-down", function(args, a1, a2, a3, a4){doh._registerTestAndCheck(a1, a2, 0, 2, args, a3, a4);}, |
| 583 |
"test-type-up-down", function(args, a1, a2, a3, a4){doh._registerTestAndCheck("ungrouped", a1, 2, 0, args, a3, a4);}, |
| 584 |
"group-url-to-type", function(args, a1, a2, a3, a4){doh._registerUrl(a1, a2, a3, a4);}, |
| 585 |
"group-url-to-args", function(args, a1, a2, a3, a4){doh._registerUrl(a1, a2, a3, 0, a4);}, |
| 586 |
"group-url-type-args", function(args, a1, a2, a3, a4){doh._registerUrl(a1, a2, undefined, a3, a4);}, |
| 587 |
"url-to-type-args", function(args, a1, a2, a3, a4){doh._registerUrl("ungrouped", a1, a2, a3, a4);}, |
| 588 |
|
| 589 |
|
| 590 |
"group-test-type-up-down", function(args, a1, a2, a3, a4, a5){doh._registerTestAndCheck(a1, a2, a3, 2, args, a4, a5);}, |
| 591 |
"group-url-to-type-args", function(args, a1, a2, a3, a4, a5){doh._registerUrl(a1, a2, a3, a4, a5);} |
| 592 |
]; |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
var argTypes = { |
| 604 |
group:"st.sf.s", |
| 605 |
test:"a.sf.o.f", |
| 606 |
type:"st", |
| 607 |
up:"f", |
| 608 |
down:"f", |
| 609 |
url:"s", |
| 610 |
to:"n", |
| 611 |
args:"o" |
| 612 |
}; |
| 613 |
for(var p in argTypes){ |
| 614 |
argTypes[p]= argTypes[p].split("."); |
| 615 |
} |
| 616 |
|
| 617 |
function generateTypeSignature(sig, pattern, dest, func){ |
| 618 |
for(var nextPattern, reducedSig= sig.slice(1), typeList= argTypes[sig[0]], i=0; i<typeList.length; i++){ |
| 619 |
nextPattern = pattern + (pattern ? "-" : "") + typeList[i]; |
| 620 |
if(reducedSig.length){ |
| 621 |
generateTypeSignature(reducedSig, nextPattern, dest, func); |
| 622 |
}else{ |
| 623 |
dest.push(nextPattern, func); |
| 624 |
} |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
var typeSigs = []; |
| 629 |
for(var sig, func, dest, i = 0; i<sigs.length; i++){ |
| 630 |
sig = sigs[i++].split("-"); |
| 631 |
func = sigs[i]; |
| 632 |
dest = typeSigs[sig.length-1] || (typeSigs[sig.length-1]= []); |
| 633 |
generateTypeSignature(sig, "", dest, func); |
| 634 |
} |
| 635 |
return typeSigs; |
| 636 |
})(); |
| 637 |
|
| 638 |
|
| 639 |
doh.register = function(a1, a2, a3, a4, a5){ |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
function getTypeId(a){ |
| 779 |
if(a instanceof Array){ |
| 780 |
return "a"; |
| 781 |
}else if(typeof a == "function"){ |
| 782 |
return "f"; |
| 783 |
}else if(typeof a == "number"){ |
| 784 |
return "n"; |
| 785 |
}else if(typeof a == "string"){ |
| 786 |
if(a in doh._testTypes){ |
| 787 |
return "st"; |
| 788 |
}else if(/\(/.test(a)){ |
| 789 |
return "sf"; |
| 790 |
}else{ |
| 791 |
return "s"; |
| 792 |
} |
| 793 |
}else{ |
| 794 |
return "o"; |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
var |
| 799 |
arity = arguments.length, |
| 800 |
search = typeSigs[arity-1], |
| 801 |
sig = [], |
| 802 |
i; |
| 803 |
for(i =0; i<arity; i++){ |
| 804 |
sig.push(getTypeId(arguments[i])); |
| 805 |
} |
| 806 |
sig = sig.join("-"); |
| 807 |
for(i=0; i<search.length; i+= 2){ |
| 808 |
if(search[i]==sig){ |
| 809 |
search[i+1](arguments, a1, a2, a3, a4, a5); |
| 810 |
return; |
| 811 |
} |
| 812 |
} |
| 813 |
illegalRegister(arguments); |
| 814 |
}; |
| 815 |
|
| 816 |
doh.registerDocTests = function(module){ |
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
var docTest = new dojox.testing.DocTest(); |
| 822 |
var docTests = docTest.getTests(module); |
| 823 |
var len = docTests.length; |
| 824 |
var tests = []; |
| 825 |
for (var i=0; i<len; i++){ |
| 826 |
var test = docTests[i]; |
| 827 |
|
| 828 |
var comment = ""; |
| 829 |
if (test.commands.length && test.commands[0].indexOf("//")!=-1) { |
| 830 |
var parts = test.commands[0].split("//"); |
| 831 |
comment = ", "+parts[parts.length-1]; |
| 832 |
} |
| 833 |
tests.push({ |
| 834 |
runTest: (function(test){ |
| 835 |
return function(t){ |
| 836 |
var r = docTest.runTest(test.commands, test.expectedResult); |
| 837 |
t.assertTrue(r.success); |
| 838 |
}; |
| 839 |
})(test), |
| 840 |
name:"Line "+test.line+comment |
| 841 |
} |
| 842 |
); |
| 843 |
} |
| 844 |
this.register("DocTests: "+module, tests); |
| 845 |
}; |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
doh.registerTest = function( group, test, type){ |
| 852 |
|
| 853 |
|
| 854 |
doh.register(group + (type ? "!" + type : ""), test); |
| 855 |
}; |
| 856 |
|
| 857 |
doh.registerGroup = function( group, tests, setUp, tearDown, type){ |
| 858 |
|
| 859 |
|
| 860 |
var args = [(group ? group : "") + (type ? "!" + type : ""), tests]; |
| 861 |
setUp && args.push(setUp); |
| 862 |
tearDown && args.push(tearDown); |
| 863 |
doh.register.apply(doh, args); |
| 864 |
}; |
| 865 |
|
| 866 |
doh.registerTestNs = function( group, ns){ |
| 867 |
|
| 868 |
|
| 869 |
doh.register(group, ns); |
| 870 |
}; |
| 871 |
|
| 872 |
doh.registerTests = function( group, testArr, type){ |
| 873 |
|
| 874 |
|
| 875 |
doh.register(group + (type ? "!" + type : ""), testArr); |
| 876 |
}; |
| 877 |
|
| 878 |
doh.registerUrl = function( group, url, timeout, type, args){ |
| 879 |
|
| 880 |
|
| 881 |
doh.register(group + (type ? "!" + type : ""), url+"", timeout || 10000, args || {}); |
| 882 |
}; |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
doh.t = doh.assertTrue = function( condition, hint){ |
| 888 |
|
| 889 |
|
| 890 |
if(arguments.length < 1){ |
| 891 |
throw new doh._AssertFailure("assertTrue failed because it was not passed at least 1 argument"); |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
if(!eval(condition)){ |
| 897 |
throw new doh._AssertFailure("assertTrue('" + condition + "') failed", hint); |
| 898 |
} |
| 899 |
}; |
| 900 |
|
| 901 |
doh.f = doh.assertFalse = function( condition, hint){ |
| 902 |
|
| 903 |
|
| 904 |
if(arguments.length < 1){ |
| 905 |
throw new doh._AssertFailure("assertFalse failed because it was not passed at least 1 argument"); |
| 906 |
} |
| 907 |
if(eval(condition)){ |
| 908 |
throw new doh._AssertFailure("assertFalse('" + condition + "') failed", hint); |
| 909 |
} |
| 910 |
}; |
| 911 |
|
| 912 |
doh.e = doh.assertError = function(expectedError, scope, functionName, args, hint){ |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
try{ |
| 919 |
scope[functionName].apply(scope, args); |
| 920 |
}catch (e){ |
| 921 |
if(e instanceof expectedError){ |
| 922 |
|
| 923 |
return true; |
| 924 |
}else{ |
| 925 |
throw new doh._AssertFailure("assertError() failed:\n\texpected error\n\t\t"+expectedError+"\n\tbut got\n\t\t"+e+"\n\n", hint); |
| 926 |
} |
| 927 |
} |
| 928 |
throw new doh._AssertFailure("assertError() failed:\n\texpected error\n\t\t"+expectedError+"\n\tbut no error caught\n\n", hint); |
| 929 |
}; |
| 930 |
|
| 931 |
doh.is = doh.assertEqual = function( expected, actual, hint, doNotThrow){ |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
if((expected === undefined)&&(actual === undefined)){ |
| 939 |
return true; |
| 940 |
} |
| 941 |
if(arguments.length < 2){ |
| 942 |
throw doh._AssertFailure("assertEqual failed because it was not passed 2 arguments"); |
| 943 |
} |
| 944 |
if((expected === actual)||(expected == actual)|| |
| 945 |
( typeof expected == "number" && typeof actual == "number" && isNaN(expected) && isNaN(actual) )){ |
| 946 |
|
| 947 |
return true; |
| 948 |
} |
| 949 |
if( (lang.isArray(expected) && lang.isArray(actual))&& |
| 950 |
(this._arrayEq(expected, actual)) ){ |
| 951 |
return true; |
| 952 |
} |
| 953 |
if( ((typeof expected == "object")&&((typeof actual == "object")))&& |
| 954 |
(this._objPropEq(expected, actual)) ){ |
| 955 |
return true; |
| 956 |
} |
| 957 |
if (doNotThrow) { |
| 958 |
return false; |
| 959 |
} |
| 960 |
throw new doh._AssertFailure("assertEqual() failed:\n\texpected\n\t\t"+expected+"\n\tbut got\n\t\t"+actual+"\n\n", hint); |
| 961 |
}; |
| 962 |
|
| 963 |
doh.isNot = doh.assertNotEqual = function( notExpected, actual, hint){ |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
if((notExpected === undefined)&&(actual === undefined)){ |
| 971 |
throw new doh._AssertFailure("assertNotEqual() failed: not expected |"+notExpected+"| but got |"+actual+"|", hint); |
| 972 |
} |
| 973 |
if(arguments.length < 2){ |
| 974 |
throw doh._AssertFailure("assertEqual failed because it was not passed 2 arguments"); |
| 975 |
} |
| 976 |
if((notExpected === actual)||(notExpected == actual)){ |
| 977 |
throw new doh._AssertFailure("assertNotEqual() failed: not expected |"+notExpected+"| but got |"+actual+"|", hint); |
| 978 |
} |
| 979 |
if( (lang.isArray(notExpected) && lang.isArray(actual))&& |
| 980 |
(this._arrayEq(notExpected, actual)) ){ |
| 981 |
throw new doh._AssertFailure("assertNotEqual() failed: not expected |"+notExpected+"| but got |"+actual+"|", hint); |
| 982 |
} |
| 983 |
if( ((typeof notExpected == "object")&&((typeof actual == "object"))) ){ |
| 984 |
var isequal = false; |
| 985 |
try{ |
| 986 |
isequal = this._objPropEq(notExpected, actual); |
| 987 |
}catch(e){ |
| 988 |
if(!(e instanceof doh._AssertFailure)){ |
| 989 |
throw e; |
| 990 |
} |
| 991 |
} |
| 992 |
if(isequal){ |
| 993 |
throw new doh._AssertFailure("assertNotEqual() failed: not expected |"+notExpected+"| but got |"+actual+"|", hint); |
| 994 |
} |
| 995 |
} |
| 996 |
return true; |
| 997 |
}; |
| 998 |
|
| 999 |
doh._arrayEq = function(expected, actual){ |
| 1000 |
if(expected.length != actual.length){ return false; } |
| 1001 |
|
| 1002 |
for(var x=0; x<expected.length; x++){ |
| 1003 |
if(!doh.assertEqual(expected[x], actual[x], 0, true)){ return false; } |
| 1004 |
} |
| 1005 |
return true; |
| 1006 |
}; |
| 1007 |
|
| 1008 |
doh._objPropEq = function(expected, actual){ |
| 1009 |
|
| 1010 |
if(expected === null && actual === null){ |
| 1011 |
return true; |
| 1012 |
} |
| 1013 |
|
| 1014 |
if(expected === null || actual === null){ |
| 1015 |
return false; |
| 1016 |
} |
| 1017 |
if(expected instanceof Date){ |
| 1018 |
return actual instanceof Date && expected.getTime()==actual.getTime(); |
| 1019 |
} |
| 1020 |
var x; |
| 1021 |
|
| 1022 |
for(x in actual){ |
| 1023 |
if(!(x in expected)){ |
| 1024 |
return false; |
| 1025 |
} |
| 1026 |
} |
| 1027 |
|
| 1028 |
for(x in expected){ |
| 1029 |
if(!(x in actual)){ |
| 1030 |
return false; |
| 1031 |
} |
| 1032 |
if(!doh.assertEqual(expected[x], actual[x], 0, true)){ |
| 1033 |
return false; |
| 1034 |
} |
| 1035 |
} |
| 1036 |
return true; |
| 1037 |
}; |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
doh._setupGroupForRun = function( groupName){ |
| 1044 |
var tg = this._groups[groupName]; |
| 1045 |
this.debug(this._line); |
| 1046 |
this.debug("GROUP", "\""+groupName+"\"", "has", tg.length, "test"+((tg.length > 1) ? "s" : "")+" to run"); |
| 1047 |
doh._groupStarted(groupName); |
| 1048 |
}; |
| 1049 |
|
| 1050 |
doh._handleFailure = function(groupName, fixture, e){ |
| 1051 |
|
| 1052 |
|
| 1053 |
this._groups[groupName].failures++; |
| 1054 |
var out = ""; |
| 1055 |
if(e instanceof this._AssertFailure){ |
| 1056 |
this._failureCount++; |
| 1057 |
if(e["fileName"]){ out += e.fileName + ':'; } |
| 1058 |
if(e["lineNumber"]){ out += e.lineNumber + ' '; } |
| 1059 |
out += e.message; |
| 1060 |
this.error("\t_AssertFailure:", out); |
| 1061 |
}else{ |
| 1062 |
this._errorCount++; |
| 1063 |
this.error("\tError:", e.message || e); |
| 1064 |
} |
| 1065 |
if(fixture.runTest["toSource"]){ |
| 1066 |
var ss = fixture.runTest.toSource(); |
| 1067 |
this.debug("\tERROR IN:\n\t\t", ss); |
| 1068 |
}else{ |
| 1069 |
this.debug("\tERROR IN:\n\t\t", fixture.runTest); |
| 1070 |
} |
| 1071 |
if(e.rhinoException){ |
| 1072 |
e.rhinoException.printStackTrace(); |
| 1073 |
}else if(e.javaException){ |
| 1074 |
e.javaException.printStackTrace(); |
| 1075 |
} |
| 1076 |
}; |
| 1077 |
|
| 1078 |
doh._runPerfFixture = function( groupName, fixture){ |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
var tg = this._groups[groupName]; |
| 1092 |
fixture.startTime = new Date(); |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
var def = new doh.Deferred(); |
| 1097 |
tg.inFlight++; |
| 1098 |
def.groupName = groupName; |
| 1099 |
def.fixture = fixture; |
| 1100 |
|
| 1101 |
var threw = false; |
| 1102 |
def.otherwise(function(err){ |
| 1103 |
doh._handleFailure(groupName, fixture, err); |
| 1104 |
threw = true; |
| 1105 |
}); |
| 1106 |
|
| 1107 |
|
| 1108 |
var fulfilled; |
| 1109 |
var retEnd = function(){ |
| 1110 |
fulfilled = true; |
| 1111 |
if(fixture["tearDown"]){ fixture.tearDown(doh); } |
| 1112 |
tg.inFlight--; |
| 1113 |
if((!tg.inFlight)&&(tg.iterated)){ |
| 1114 |
doh._groupFinished(groupName, !tg.failures); |
| 1115 |
} |
| 1116 |
doh._testFinished(groupName, fixture, !threw); |
| 1117 |
if(doh._paused){ |
| 1118 |
doh.run(); |
| 1119 |
} |
| 1120 |
}; |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
var timer; |
| 1125 |
var to = fixture.timeout; |
| 1126 |
if(to > 0) { |
| 1127 |
timer = setTimeout(function(){ |
| 1128 |
def.reject(new Error("test timeout in "+fixture.name.toString())); |
| 1129 |
}, to); |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
def.always(function(){ |
| 1134 |
if(timer){ |
| 1135 |
clearTimeout(timer); |
| 1136 |
} |
| 1137 |
retEnd(); |
| 1138 |
}); |
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
var res = fixture.results; |
| 1145 |
res.trials = []; |
| 1146 |
|
| 1147 |
|
| 1148 |
var itrDef = doh._calcTrialIterations(groupName, fixture); |
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
itrDef.then( |
| 1153 |
function(iterations){ |
| 1154 |
if(iterations){ |
| 1155 |
var countdown = fixture.trialIterations; |
| 1156 |
doh.debug("TIMING TEST: [" + fixture.name + |
| 1157 |
"]\n\t\tITERATIONS PER TRIAL: " + |
| 1158 |
iterations + "\n\tTRIALS: " + |
| 1159 |
countdown); |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
var trialRunner = function() { |
| 1165 |
|
| 1166 |
var start = new Date(); |
| 1167 |
var tTimer = new doh.Deferred(); |
| 1168 |
|
| 1169 |
var tState = { |
| 1170 |
countdown: iterations |
| 1171 |
}; |
| 1172 |
var testRunner = function(state){ |
| 1173 |
while(state){ |
| 1174 |
try{ |
| 1175 |
state.countdown--; |
| 1176 |
if(state.countdown){ |
| 1177 |
var ret = fixture.runTest(doh); |
| 1178 |
if(ret && ret.then){ |
| 1179 |
|
| 1180 |
|
| 1181 |
var atState = { |
| 1182 |
countdown: state.countdown |
| 1183 |
}; |
| 1184 |
ret.then( |
| 1185 |
function(){ |
| 1186 |
testRunner(atState) |
| 1187 |
}, |
| 1188 |
function(err){ |
| 1189 |
doh._handleFailure(groupName, fixture, err); |
| 1190 |
fixture.endTime = new Date(); |
| 1191 |
def.reject(err); |
| 1192 |
} |
| 1193 |
); |
| 1194 |
state = null; |
| 1195 |
} |
| 1196 |
}else{ |
| 1197 |
tTimer.resolve(new Date()); |
| 1198 |
state = null; |
| 1199 |
} |
| 1200 |
}catch(err){ |
| 1201 |
fixture.endTime = new Date(); |
| 1202 |
tTimer.reject(err); |
| 1203 |
} |
| 1204 |
} |
| 1205 |
}; |
| 1206 |
tTimer.then( |
| 1207 |
function(end){ |
| 1208 |
|
| 1209 |
var tResults = { |
| 1210 |
trial: (fixture.trialIterations - countdown), |
| 1211 |
testIterations: iterations, |
| 1212 |
executionTime: (end.getTime() - start.getTime()), |
| 1213 |
average: (end.getTime() - start.getTime())/iterations |
| 1214 |
}; |
| 1215 |
res.trials.push(tResults); |
| 1216 |
doh.debug("\n\t\tTRIAL #: " + |
| 1217 |
tResults.trial + "\n\tTIME: " + |
| 1218 |
tResults.executionTime + "ms.\n\tAVG TEST TIME: " + |
| 1219 |
(tResults.executionTime/tResults.testIterations) + "ms."); |
| 1220 |
|
| 1221 |
|
| 1222 |
countdown--; |
| 1223 |
if(countdown){ |
| 1224 |
setTimeout(trialRunner, fixture.trialDelay); |
| 1225 |
}else{ |
| 1226 |
|
| 1227 |
var t = res.trials; |
| 1228 |
|
| 1229 |
|
| 1230 |
fixture.endTime = new Date(); |
| 1231 |
def.resolve(true); |
| 1232 |
} |
| 1233 |
}, |
| 1234 |
|
| 1235 |
|
| 1236 |
function(err){ |
| 1237 |
fixture.endTime = new Date(); |
| 1238 |
def.reject(err); |
| 1239 |
} |
| 1240 |
); |
| 1241 |
testRunner(tState); |
| 1242 |
}; |
| 1243 |
trialRunner(); |
| 1244 |
} |
| 1245 |
}, |
| 1246 |
|
| 1247 |
|
| 1248 |
function(err){ |
| 1249 |
fixture.endTime = new Date(); |
| 1250 |
def.reject(err); |
| 1251 |
} |
| 1252 |
); |
| 1253 |
|
| 1254 |
|
| 1255 |
if(!fulfilled){ |
| 1256 |
doh.pause(); |
| 1257 |
} |
| 1258 |
return def; |
| 1259 |
}; |
| 1260 |
|
| 1261 |
doh._calcTrialIterations = function( groupName, fixture){ |
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
var def = new doh.Deferred(); |
| 1272 |
var calibrate = function () { |
| 1273 |
var testFunc = lang.hitch(fixture, fixture.runTest); |
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
var iState = { |
| 1279 |
start: new Date(), |
| 1280 |
curIter: 0, |
| 1281 |
iterations: 5 |
| 1282 |
}; |
| 1283 |
var handleIteration = function(state){ |
| 1284 |
while(state){ |
| 1285 |
if(state.curIter < state.iterations){ |
| 1286 |
try{ |
| 1287 |
var ret = testFunc(doh); |
| 1288 |
if(ret && ret.then){ |
| 1289 |
var aState = { |
| 1290 |
start: state.start, |
| 1291 |
curIter: state.curIter + 1, |
| 1292 |
iterations: state.iterations |
| 1293 |
}; |
| 1294 |
ret.then( |
| 1295 |
function(){ |
| 1296 |
handleIteration(aState); |
| 1297 |
}, |
| 1298 |
function(err) { |
| 1299 |
fixture.endTime = new Date(); |
| 1300 |
def.reject(err); |
| 1301 |
} |
| 1302 |
); |
| 1303 |
state = null; |
| 1304 |
}else{ |
| 1305 |
state.curIter++; |
| 1306 |
} |
| 1307 |
}catch(err){ |
| 1308 |
fixture.endTime = new Date(); |
| 1309 |
def.reject(err); |
| 1310 |
return; |
| 1311 |
} |
| 1312 |
}else{ |
| 1313 |
var end = new Date(); |
| 1314 |
var totalTime = (end.getTime() - state.start.getTime()); |
| 1315 |
if(totalTime < fixture.trialDuration){ |
| 1316 |
var nState = { |
| 1317 |
iterations: state.iterations * 2, |
| 1318 |
curIter: 0 |
| 1319 |
}; |
| 1320 |
state = null; |
| 1321 |
setTimeout(function(){ |
| 1322 |
nState.start = new Date(); |
| 1323 |
handleIteration(nState); |
| 1324 |
}, 50); |
| 1325 |
}else{ |
| 1326 |
var itrs = state.iterations; |
| 1327 |
setTimeout(function(){def.resolve(itrs)}, 50); |
| 1328 |
state = null; |
| 1329 |
} |
| 1330 |
} |
| 1331 |
} |
| 1332 |
}; |
| 1333 |
handleIteration(iState); |
| 1334 |
}; |
| 1335 |
setTimeout(calibrate, 10); |
| 1336 |
return def; |
| 1337 |
}; |
| 1338 |
|
| 1339 |
doh._runRegFixture = function( groupName, fixture){ |
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
var tg = this._groups[groupName]; |
| 1349 |
|
| 1350 |
fixture.startTime = new Date(); |
| 1351 |
|
| 1352 |
var ret = fixture.runTest(this); |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
if(ret && ret.then){ |
| 1358 |
|
| 1359 |
|
| 1360 |
if(ret.promise){ |
| 1361 |
ret = ret.promise; |
| 1362 |
} |
| 1363 |
|
| 1364 |
tg.inFlight++; |
| 1365 |
ret.groupName = groupName; |
| 1366 |
ret.fixture = fixture; |
| 1367 |
|
| 1368 |
|
| 1369 |
var threw = false; |
| 1370 |
ret.otherwise(function(err){ |
| 1371 |
if(threw){ |
| 1372 |
|
| 1373 |
return; |
| 1374 |
} |
| 1375 |
doh._handleFailure(groupName, fixture, err); |
| 1376 |
threw = true; |
| 1377 |
}); |
| 1378 |
|
| 1379 |
var fulfilled; |
| 1380 |
var retEnd = function(){ |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
if(fulfilled){ |
| 1385 |
|
| 1386 |
return; |
| 1387 |
} |
| 1388 |
fulfilled = true; |
| 1389 |
|
| 1390 |
fixture.endTime = new Date(); |
| 1391 |
|
| 1392 |
if(fixture.tearDown){ |
| 1393 |
try { |
| 1394 |
fixture.tearDown(doh); |
| 1395 |
}catch(e){ |
| 1396 |
doh.debug("Error tearing down test: "+e.message); |
| 1397 |
} |
| 1398 |
} |
| 1399 |
tg.inFlight--; |
| 1400 |
doh._testFinished(groupName, fixture, !threw); |
| 1401 |
|
| 1402 |
if((!tg.inFlight)&&(tg.iterated)){ |
| 1403 |
doh._groupFinished(groupName, !tg.failures); |
| 1404 |
} |
| 1405 |
|
| 1406 |
|
| 1407 |
if(doh._paused){ |
| 1408 |
doh.run(); |
| 1409 |
} |
| 1410 |
}; |
| 1411 |
|
| 1412 |
var timer = setTimeout(function(){ |
| 1413 |
if(!timer){ |
| 1414 |
|
| 1415 |
return; |
| 1416 |
} |
| 1417 |
|
| 1418 |
doh._handleFailure(groupName, fixture, new Error("test timeout in " + fixture.name.toString())); |
| 1419 |
threw = true; |
| 1420 |
retEnd(); |
| 1421 |
}, fixture["timeout"]||1000); |
| 1422 |
|
| 1423 |
ret.always(function(){ |
| 1424 |
clearTimeout(timer); |
| 1425 |
timer = null; |
| 1426 |
retEnd(); |
| 1427 |
}); |
| 1428 |
|
| 1429 |
if(!fulfilled){ |
| 1430 |
doh.pause(); |
| 1431 |
} |
| 1432 |
|
| 1433 |
return ret; |
| 1434 |
}else{ |
| 1435 |
|
| 1436 |
} |
| 1437 |
}; |
| 1438 |
|
| 1439 |
doh._runFixture = function(groupName, fixture){ |
| 1440 |
var tg = this._groups[groupName]; |
| 1441 |
this._testStarted(groupName, fixture); |
| 1442 |
var threw = false; |
| 1443 |
var err = null; |
| 1444 |
|
| 1445 |
try{ |
| 1446 |
|
| 1447 |
|
| 1448 |
fixture.group = tg; |
| 1449 |
|
| 1450 |
|
| 1451 |
if(fixture["setUp"]){ fixture.setUp(this); } |
| 1452 |
if(fixture["runTest"]){ |
| 1453 |
if(fixture.testType === "perf"){ |
| 1454 |
|
| 1455 |
return doh._runPerfFixture(groupName, fixture); |
| 1456 |
}else{ |
| 1457 |
|
| 1458 |
var ret = doh._runRegFixture(groupName, fixture); |
| 1459 |
if(ret){ |
| 1460 |
|
| 1461 |
|
| 1462 |
return ret; |
| 1463 |
} |
| 1464 |
} |
| 1465 |
} |
| 1466 |
}catch(e){ |
| 1467 |
threw = true; |
| 1468 |
err = e; |
| 1469 |
} |
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
fixture.endTime = new Date(); |
| 1474 |
|
| 1475 |
|
| 1476 |
try{ |
| 1477 |
if(fixture["tearDown"]){ fixture.tearDown(this); } |
| 1478 |
}catch(e){ |
| 1479 |
this.debug("Error tearing down test: "+e.message); |
| 1480 |
} |
| 1481 |
|
| 1482 |
var d = new doh.Deferred(); |
| 1483 |
setTimeout(lang.hitch(this, function(){ |
| 1484 |
if(threw){ |
| 1485 |
this._handleFailure(groupName, fixture, err); |
| 1486 |
} |
| 1487 |
this._testFinished(groupName, fixture, !threw); |
| 1488 |
|
| 1489 |
if((!tg.inFlight)&&(tg.iterated)){ |
| 1490 |
doh._groupFinished(groupName, !tg.failures); |
| 1491 |
}else if(tg.inFlight > 0){ |
| 1492 |
setTimeout(lang.hitch(this, function(){ |
| 1493 |
doh.runGroup(groupName); |
| 1494 |
}), 100); |
| 1495 |
this._paused = true; |
| 1496 |
} |
| 1497 |
if(doh._paused){ |
| 1498 |
doh.run(); |
| 1499 |
} |
| 1500 |
}), 30); |
| 1501 |
doh.pause(); |
| 1502 |
return d; |
| 1503 |
}; |
| 1504 |
|
| 1505 |
doh.runGroup = function( groupName, idx){ |
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
idx = idx || 0; |
| 1519 |
var tg = this._groups[groupName]; |
| 1520 |
if(tg.skip === true){ return; } |
| 1521 |
if(lang.isArray(tg)){ |
| 1522 |
if(tg.iterated===undefined){ |
| 1523 |
tg.iterated = false; |
| 1524 |
tg.inFlight = 0; |
| 1525 |
tg.failures = 0; |
| 1526 |
this._setupGroupForRun(groupName); |
| 1527 |
if(tg["setUp"]){ tg.setUp(this); } |
| 1528 |
} |
| 1529 |
for(var y=idx; y<tg.length; y++){ |
| 1530 |
if(this._paused){ |
| 1531 |
this._currentTest = y; |
| 1532 |
|
| 1533 |
return; |
| 1534 |
} |
| 1535 |
doh._runFixture(groupName, tg[y]); |
| 1536 |
if(this._paused){ |
| 1537 |
this._currentTest = y+1; |
| 1538 |
if(this._currentTest == tg.length){ |
| 1539 |
tg.iterated = true; |
| 1540 |
} |
| 1541 |
|
| 1542 |
return; |
| 1543 |
} |
| 1544 |
} |
| 1545 |
tg.iterated = true; |
| 1546 |
if(!tg.inFlight){ |
| 1547 |
if(tg["tearDown"]){ tg.tearDown(this); } |
| 1548 |
doh._groupFinished(groupName, !tg.failures); |
| 1549 |
} |
| 1550 |
} |
| 1551 |
}; |
| 1552 |
|
| 1553 |
doh._onEnd = function(){}; |
| 1554 |
|
| 1555 |
doh._report = function(){ |
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
this.debug(this._line); |
| 1565 |
this.debug("| TEST SUMMARY:"); |
| 1566 |
this.debug(this._line); |
| 1567 |
this.debug("\t", this._testCount, "tests in", this._groupCount, "groups"); |
| 1568 |
this.debug("\t", this._errorCount, "errors"); |
| 1569 |
this.debug("\t", this._failureCount, "failures"); |
| 1570 |
}; |
| 1571 |
|
| 1572 |
doh.togglePaused = function(){ |
| 1573 |
this[(this._paused) ? "run" : "pause"](); |
| 1574 |
}; |
| 1575 |
|
| 1576 |
doh.pause = function(){ |
| 1577 |
|
| 1578 |
|
| 1579 |
this._paused = true; |
| 1580 |
}; |
| 1581 |
|
| 1582 |
doh.run = function(){ |
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
this._paused = false; |
| 1587 |
var cg = this._currentGroup; |
| 1588 |
var ct = this._currentTest; |
| 1589 |
var found = false; |
| 1590 |
if(!cg){ |
| 1591 |
this._init(); |
| 1592 |
found = true; |
| 1593 |
} |
| 1594 |
this._currentGroup = null; |
| 1595 |
this._currentTest = null; |
| 1596 |
for(var x in this._groups){ |
| 1597 |
if( |
| 1598 |
( (!found)&&(x == cg) )||( found ) |
| 1599 |
){ |
| 1600 |
if(this._paused){ return; } |
| 1601 |
this._currentGroup = x; |
| 1602 |
if(!found){ |
| 1603 |
found = true; |
| 1604 |
this.runGroup(x, ct); |
| 1605 |
}else{ |
| 1606 |
this.runGroup(x); |
| 1607 |
} |
| 1608 |
if(this._paused){ return; } |
| 1609 |
} |
| 1610 |
} |
| 1611 |
this._currentGroup = null; |
| 1612 |
this._currentTest = null; |
| 1613 |
this._paused = false; |
| 1614 |
this._onEnd(); |
| 1615 |
this._report(); |
| 1616 |
}; |
| 1617 |
|
| 1618 |
doh.runOnLoad = function(){ |
| 1619 |
require(["dojo/ready"], function(ready){ |
| 1620 |
ready(doh, "run"); |
| 1621 |
}); |
| 1622 |
}; |
| 1623 |
|
| 1624 |
return doh; |
| 1625 |
|
| 1626 |
}); |
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
if (typeof window!="undefined" && typeof location!="undefined" && typeof document!="undefined" && window.location==location && window.document==document) { |
| 1633 |
require(["doh/_browserRunner"]); |
| 1634 |
} |