Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: test/mjsunit/mjsunit.js

Issue 1544793002: [tests] Fix bogus uses of assertThrows. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/reflect.js ('k') | test/mjsunit/regress/regress-70066.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // Checks that the found value is *not* null. 86 // Checks that the found value is *not* null.
87 var assertNotNull; 87 var assertNotNull;
88 88
89 // Assert that the passed function or eval code throws an exception. 89 // Assert that the passed function or eval code throws an exception.
90 // The optional second argument is an exception constructor that the 90 // The optional second argument is an exception constructor that the
91 // thrown exception is checked against with "instanceof". 91 // thrown exception is checked against with "instanceof".
92 // The optional third argument is a message type string that is compared 92 // The optional third argument is a message type string that is compared
93 // to the type property on the thrown exception. 93 // to the type property on the thrown exception.
94 var assertThrows; 94 var assertThrows;
95 95
96 // Assert that the passed function throws an exception.
97 // The exception is checked against the second argument using assertEquals.
98 var assertThrowsEquals;
99
96 // Assert that the passed function or eval code does not throw an exception. 100 // Assert that the passed function or eval code does not throw an exception.
97 var assertDoesNotThrow; 101 var assertDoesNotThrow;
98 102
99 // Asserts that the found value is an instance of the constructor passed 103 // Asserts that the found value is an instance of the constructor passed
100 // as the second argument. 104 // as the second argument.
101 var assertInstanceof; 105 var assertInstanceof;
102 106
103 // Assert that this code is never executed (i.e., always fails if executed). 107 // Assert that this code is never executed (i.e., always fails if executed).
104 var assertUnreachable; 108 var assertUnreachable;
105 109
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 try { 350 try {
347 if (typeof code === 'function') { 351 if (typeof code === 'function') {
348 code(); 352 code();
349 } else { 353 } else {
350 eval(code); 354 eval(code);
351 } 355 }
352 threwException = false; 356 threwException = false;
353 } catch (e) { 357 } catch (e) {
354 if (typeof type_opt === 'function') { 358 if (typeof type_opt === 'function') {
355 assertInstanceof(e, type_opt); 359 assertInstanceof(e, type_opt);
360 } else if (type_opt !== void 0) {
361 fail("invalid use of assertThrows, maybe you want assertThrowsEquals");
356 } 362 }
357 if (arguments.length >= 3) { 363 if (arguments.length >= 3) {
358 assertEquals(e.type, cause_opt); 364 assertEquals(e.type, cause_opt);
359 } 365 }
360 // Success. 366 // Success.
361 return; 367 return;
362 } 368 }
363 throw new MjsUnitAssertionError("Did not throw exception"); 369 throw new MjsUnitAssertionError("Did not throw exception");
364 }; 370 };
365 371
366 372
373 assertThrowsEquals = function assertThrowsEquals(fun, val) {
374 try {
375 fun();
376 } catch(e) {
377 assertEquals(val, e);
378 return;
379 }
380 throw new MjsUnitAssertionError("Did not throw exception");
381 };
382
383
367 assertInstanceof = function assertInstanceof(obj, type) { 384 assertInstanceof = function assertInstanceof(obj, type) {
368 if (!(obj instanceof type)) { 385 if (!(obj instanceof type)) {
369 var actualTypeName = null; 386 var actualTypeName = null;
370 var actualConstructor = Object.getPrototypeOf(obj).constructor; 387 var actualConstructor = Object.getPrototypeOf(obj).constructor;
371 if (typeof actualConstructor === "function") { 388 if (typeof actualConstructor === "function") {
372 actualTypeName = actualConstructor.name || String(actualConstructor); 389 actualTypeName = actualConstructor.name || String(actualConstructor);
373 } 390 }
374 fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" + 391 fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" +
375 (type.name || type) + ">" + 392 (type.name || type) + ">" +
376 (actualTypeName ? " but of < " + actualTypeName + ">" : "")); 393 (actualTypeName ? " but of < " + actualTypeName + ">" : ""));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (sync_opt === undefined) sync_opt = ""; 434 if (sync_opt === undefined) sync_opt = "";
418 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); 435 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt);
419 } 436 }
420 437
421 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { 438 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) {
422 if (sync_opt === undefined) sync_opt = ""; 439 if (sync_opt === undefined) sync_opt = "";
423 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); 440 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt);
424 } 441 }
425 442
426 })(); 443 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/reflect.js ('k') | test/mjsunit/regress/regress-70066.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698