OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 | 200 |
201 function PrettyPrintArrayElement(value, index, array) { | 201 function PrettyPrintArrayElement(value, index, array) { |
202 if (value === undefined && !(index in array)) return ""; | 202 if (value === undefined && !(index in array)) return ""; |
203 return PrettyPrint(value); | 203 return PrettyPrint(value); |
204 } | 204 } |
205 | 205 |
206 | 206 |
| 207 function failWithMessage(message) { |
| 208 throw new MjsUnitAssertionError(message); |
| 209 } |
| 210 |
| 211 |
207 function fail(expectedText, found, name_opt) { | 212 function fail(expectedText, found, name_opt) { |
208 var message = "Fail" + "ure"; | 213 var message = "Fail" + "ure"; |
209 if (name_opt) { | 214 if (name_opt) { |
210 // Fix this when we ditch the old test runner. | 215 // Fix this when we ditch the old test runner. |
211 message += " (" + name_opt + ")"; | 216 message += " (" + name_opt + ")"; |
212 } | 217 } |
213 | 218 |
214 message += ": expected <" + expectedText + | 219 message += ": expected <" + expectedText + |
215 "> found <" + PrettyPrint(found) + ">"; | 220 "> found <" + PrettyPrint(found) + ">"; |
216 throw new MjsUnitAssertionError(message); | 221 throw new MjsUnitAssertionError(message); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 if (typeof code === 'function') { | 362 if (typeof code === 'function') { |
358 code(); | 363 code(); |
359 } else { | 364 } else { |
360 eval(code); | 365 eval(code); |
361 } | 366 } |
362 threwException = false; | 367 threwException = false; |
363 } catch (e) { | 368 } catch (e) { |
364 if (typeof type_opt === 'function') { | 369 if (typeof type_opt === 'function') { |
365 assertInstanceof(e, type_opt); | 370 assertInstanceof(e, type_opt); |
366 } else if (type_opt !== void 0) { | 371 } else if (type_opt !== void 0) { |
367 fail("invalid use of assertThrows, maybe you want assertThrowsEquals"); | 372 failWithMessage("invalid use of assertThrows, maybe you want assertThrow
sEquals"); |
368 } | 373 } |
369 if (arguments.length >= 3) { | 374 if (arguments.length >= 3) { |
370 assertEquals(e.type, cause_opt); | 375 assertEquals(e.type, cause_opt); |
371 } | 376 } |
372 // Success. | 377 // Success. |
373 return; | 378 return; |
374 } | 379 } |
375 throw new MjsUnitAssertionError("Did not throw exception"); | 380 failWithMessage("Did not throw exception"); |
376 }; | 381 }; |
377 | 382 |
378 | 383 |
379 assertThrowsEquals = function assertThrowsEquals(fun, val) { | 384 assertThrowsEquals = function assertThrowsEquals(fun, val) { |
380 try { | 385 try { |
381 fun(); | 386 fun(); |
382 } catch(e) { | 387 } catch(e) { |
383 assertEquals(val, e); | 388 assertEquals(val, e); |
384 return; | 389 return; |
385 } | 390 } |
386 throw new MjsUnitAssertionError("Did not throw exception"); | 391 failWithMessage("Did not throw exception"); |
387 }; | 392 }; |
388 | 393 |
389 | 394 |
390 assertInstanceof = function assertInstanceof(obj, type) { | 395 assertInstanceof = function assertInstanceof(obj, type) { |
391 if (!(obj instanceof type)) { | 396 if (!(obj instanceof type)) { |
392 var actualTypeName = null; | 397 var actualTypeName = null; |
393 var actualConstructor = Object.getPrototypeOf(obj).constructor; | 398 var actualConstructor = Object.getPrototypeOf(obj).constructor; |
394 if (typeof actualConstructor === "function") { | 399 if (typeof actualConstructor === "function") { |
395 actualTypeName = actualConstructor.name || String(actualConstructor); | 400 actualTypeName = actualConstructor.name || String(actualConstructor); |
396 } | 401 } |
397 fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" + | 402 failWithmessage("Object <" + PrettyPrint(obj) + "> is not an instance of <
" + |
398 (type.name || type) + ">" + | 403 (type.name || type) + ">" + |
399 (actualTypeName ? " but of < " + actualTypeName + ">" : "")); | 404 (actualTypeName ? " but of <" + actualTypeName + ">" : "")); |
400 } | 405 } |
401 }; | 406 }; |
402 | 407 |
403 | 408 |
404 assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) { | 409 assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) { |
405 try { | 410 try { |
406 if (typeof code === 'function') { | 411 if (typeof code === 'function') { |
407 code(); | 412 code(); |
408 } else { | 413 } else { |
409 eval(code); | 414 eval(code); |
410 } | 415 } |
411 } catch (e) { | 416 } catch (e) { |
412 fail("threw an exception: ", e.message || e, name_opt); | 417 failWithMessage("threw an exception: " + (e.message || e)); |
413 } | 418 } |
414 }; | 419 }; |
415 | 420 |
416 assertUnreachable = function assertUnreachable(name_opt) { | 421 assertUnreachable = function assertUnreachable(name_opt) { |
417 // Fix this when we ditch the old test runner. | 422 // Fix this when we ditch the old test runner. |
418 var message = "Fail" + "ure: unreachable"; | 423 var message = "Fail" + "ure: unreachable"; |
419 if (name_opt) { | 424 if (name_opt) { |
420 message += " - " + name_opt; | 425 message += " - " + name_opt; |
421 } | 426 } |
422 throw new MjsUnitAssertionError(message); | 427 failWithMessage(message); |
423 }; | 428 }; |
424 | 429 |
425 assertContains = function(sub, value, name_opt) { | 430 assertContains = function(sub, value, name_opt) { |
426 if (value == null ? (sub != null) : value.indexOf(sub) == -1) { | 431 if (value == null ? (sub != null) : value.indexOf(sub) == -1) { |
427 fail("contains '" + String(sub) + "'", value, name_opt); | 432 fail("contains '" + String(sub) + "'", value, name_opt); |
428 } | 433 } |
429 }; | 434 }; |
430 | 435 |
431 assertMatches = function(regexp, str, name_opt) { | 436 assertMatches = function(regexp, str, name_opt) { |
432 if (!(regexp instanceof RegExp)) { | 437 if (!(regexp instanceof RegExp)) { |
(...skipping 22 matching lines...) Expand all Loading... |
455 if (sync_opt === undefined) sync_opt = ""; | 460 if (sync_opt === undefined) sync_opt = ""; |
456 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); | 461 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); |
457 } | 462 } |
458 | 463 |
459 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { | 464 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { |
460 if (sync_opt === undefined) sync_opt = ""; | 465 if (sync_opt === undefined) sync_opt = ""; |
461 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); | 466 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); |
462 } | 467 } |
463 | 468 |
464 })(); | 469 })(); |
OLD | NEW |