From 837900ef24dcfaa94fcd6cb3ae00c69f717f4e21 Mon Sep 17 00:00:00 2001 From: neis Date: Thu, 7 Jan 2016 06:48:57 -0800 Subject: [PATCH] [tests] Fix bogus uses of assertThrows. Some tests passed a string as second argument to assertThrows, expecting it to be matched against the exception. However, assertThrows simply ignored these. (Some other tests actually seem to use that argument as a comment ...) This CL - changes assertThrows to fail if the second argument is not a function, - adds assertThrowsEquals which compares the exception to a given value using assertEquals - fixes some bogus tests that got exposed by this. R=jarin@chromium.org BUG= Review URL: https://codereview.chromium.org/1544793002 Cr-Commit-Position: refs/heads/master@{#33159} --- test/mjsunit/asm/infinite-loops-taken.js | 6 +- test/mjsunit/d8-os.js | 22 +-- test/mjsunit/es6/array-tostring.js | 2 +- test/mjsunit/es6/object-tostring.js | 2 +- test/mjsunit/harmony/proxies-for.js | 4 +- test/mjsunit/harmony/proxies-with.js | 10 +- test/mjsunit/harmony/proxies.js | 175 +++++++----------- test/mjsunit/harmony/reflect.js | 13 +- test/mjsunit/mjsunit.js | 17 ++ test/mjsunit/regress/regress-70066.js | 4 +- .../third_party/regexp-pcre/regexp-pcre.js | 102 +++++----- 11 files changed, 163 insertions(+), 194 deletions(-) diff --git a/test/mjsunit/asm/infinite-loops-taken.js b/test/mjsunit/asm/infinite-loops-taken.js index d136c62469..8a3f91a67a 100644 --- a/test/mjsunit/asm/infinite-loops-taken.js +++ b/test/mjsunit/asm/infinite-loops-taken.js @@ -35,7 +35,7 @@ function Module() { } var m = Module(); -assertThrows(function() { m.w0(counter(5)) }, error); -assertThrows(function() { m.w1(counter(5)) }, error); -assertThrows(function() { m.w2(counter(5)) }, error); +assertThrowsEquals(function() { m.w0(counter(5)) }, error); +assertThrowsEquals(function() { m.w1(counter(5)) }, error); +assertThrowsEquals(function() { m.w2(counter(5)) }, error); assertEquals(111, m.w3(counter(5))); diff --git a/test/mjsunit/d8-os.js b/test/mjsunit/d8-os.js index 29d31032e7..c2d8ec59bc 100644 --- a/test/mjsunit/d8-os.js +++ b/test/mjsunit/d8-os.js @@ -73,7 +73,7 @@ if (this.os && os.system) { // Check that they are there. os.system('ls', [TEST_DIR + '/dir/foo']); // Check that we can detect when something is not there. - assertThrows("os.system('ls', [TEST_DIR + '/dir/bar']);", "dir not there"); + assertThrows("os.system('ls', [TEST_DIR + '/dir/bar']);"); // Check that mkdirp makes intermediate directories. os.mkdirp(TEST_DIR + "/dir2/foo"); os.system("ls", [TEST_DIR + "/dir2/foo"]); @@ -86,16 +86,16 @@ if (this.os && os.system) { // Check that we get an error if the name is taken by a file. os.system("sh", ["-c", "echo foo > " + TEST_DIR + "/file1"]); os.system("ls", [TEST_DIR + "/file1"]); - assertThrows("os.mkdirp(TEST_DIR + '/file1');", "mkdir over file1"); - assertThrows("os.mkdirp(TEST_DIR + '/file1/foo');", "mkdir over file2"); - assertThrows("os.mkdirp(TEST_DIR + '/file1/');", "mkdir over file3"); - assertThrows("os.mkdirp(TEST_DIR + '/file1/foo/');", "mkdir over file4"); + assertThrows("os.mkdirp(TEST_DIR + '/file1');"); + assertThrows("os.mkdirp(TEST_DIR + '/file1/foo');"); + assertThrows("os.mkdirp(TEST_DIR + '/file1/');"); + assertThrows("os.mkdirp(TEST_DIR + '/file1/foo/');"); // Create a dir we cannot read. os.mkdirp(TEST_DIR + "/dir4", 0); // This test fails if you are root since root can read any dir. - assertThrows("os.chdir(TEST_DIR + '/dir4');", "chdir dir4 I"); + assertThrows("os.chdir(TEST_DIR + '/dir4');"); os.rmdir(TEST_DIR + "/dir4"); - assertThrows("os.chdir(TEST_DIR + '/dir4');", "chdir dir4 II"); + assertThrows("os.chdir(TEST_DIR + '/dir4');"); // Set umask. This changes the umask for the whole process and is // the reason why the test cannot be run multi-threaded. @@ -103,9 +103,9 @@ if (this.os && os.system) { // Create a dir we cannot read. os.mkdirp(TEST_DIR + "/dir5"); // This test fails if you are root since root can read any dir. - assertThrows("os.chdir(TEST_DIR + '/dir5');", "cd dir5 I"); + assertThrows("os.chdir(TEST_DIR + '/dir5');"); os.rmdir(TEST_DIR + "/dir5"); - assertThrows("os.chdir(TEST_DIR + '/dir5');", "chdir dir5 II"); + assertThrows("os.chdir(TEST_DIR + '/dir5');"); os.umask(old_umask); os.mkdirp(TEST_DIR + "/hest/fisk/../fisk/ged"); @@ -129,10 +129,10 @@ if (this.os && os.system) { have_echo = false; } if (have_sleep) { - assertThrows("os.system('sleep', ['2000'], 20);", "sleep 1"); + assertThrows("os.system('sleep', ['2000'], 20);"); // Check we time out with total time. - assertThrows("os.system('sleep', ['2000'], -1, 20);", "sleep 2"); + assertThrows("os.system('sleep', ['2000'], -1, 20);"); // Check that -1 means no timeout. os.system('sleep', ['1'], -1, -1); diff --git a/test/mjsunit/es6/array-tostring.js b/test/mjsunit/es6/array-tostring.js index 8a9198ca16..397fde4ab1 100644 --- a/test/mjsunit/es6/array-tostring.js +++ b/test/mjsunit/es6/array-tostring.js @@ -41,7 +41,7 @@ function testToStringTag(className) { Object.defineProperty(obj, Symbol.toStringTag, { get: function() { throw className; } }); - assertThrows(function() { + assertThrowsEquals(function() { Array.prototype.toString.call(obj); }, className); diff --git a/test/mjsunit/es6/object-tostring.js b/test/mjsunit/es6/object-tostring.js index 0a2f89cb88..4d6090faf1 100644 --- a/test/mjsunit/es6/object-tostring.js +++ b/test/mjsunit/es6/object-tostring.js @@ -41,7 +41,7 @@ function testToStringTag(className) { Object.defineProperty(obj, Symbol.toStringTag, { get: function() { throw className; } }); - assertThrows(function() { + assertThrowsEquals(function() { Object.prototype.toString.call(obj); }, className); diff --git a/test/mjsunit/harmony/proxies-for.js b/test/mjsunit/harmony/proxies-for.js index dd37a3bd6b..aea9bd6c21 100644 --- a/test/mjsunit/harmony/proxies-for.js +++ b/test/mjsunit/harmony/proxies-for.js @@ -115,8 +115,8 @@ function TestForInThrow(handler) { function TestForInThrow2(create, handler) { var p = create(handler) var o = Object.create(p) - assertThrows(function(){ for (var x in p) {} }, "myexn") - assertThrows(function(){ for (var x in o) {} }, "myexn") + assertThrowsEquals(function(){ for (var x in p) {} }, "myexn") + assertThrowsEquals(function(){ for (var x in o) {} }, "myexn") } TestForInThrow({ diff --git a/test/mjsunit/harmony/proxies-with.js b/test/mjsunit/harmony/proxies-with.js index bd051ac25f..1aa13adea6 100644 --- a/test/mjsunit/harmony/proxies-with.js +++ b/test/mjsunit/harmony/proxies-with.js @@ -168,14 +168,14 @@ function TestWithGetCallThrow2(create, handler) { var p = create(handler) with (p) { - assertThrows(function(){ a() }, "myexn") + assertThrowsEquals(function(){ a() }, "myexn") assertEquals("local", b()) assertEquals("global", c()) } var o = Object.create(p, {d: {value: function() { return "own" }}}) with (o) { - assertThrows(function(){ a() }, "myexn") + assertThrowsEquals(function(){ a() }, "myexn") assertEquals("local", b()) assertEquals("global", c()) assertEquals("own", d()) @@ -185,10 +185,12 @@ function TestWithGetCallThrow2(create, handler) { function onproxythrow() { throw "myexn" } TestWithGetCallThrow({ + has: function(r, k) { return k === "a"; }, get: function(r, k) { key = k; return k === "a" ? onproxythrow : undefined }, }) TestWithGetCallThrow({ + has: function(r, k) { return k === "a"; }, get: function(r, k) { return this.get2(r, k) }, get2: function(r, k) { key = k; return k === "a" ? onproxythrow : undefined }, }) @@ -305,7 +307,7 @@ function TestWithSetThrow(handler, hasSetter) { function TestWithSetThrow2(create, handler, hasSetter) { var p = create(handler) - assertThrows(function(){ + assertThrowsEquals(function(){ with (p) { a = 1 } @@ -314,7 +316,7 @@ function TestWithSetThrow2(create, handler, hasSetter) { if (!hasSetter) return var o = Object.create(p, {}) - assertThrows(function(){ + assertThrowsEquals(function(){ with (o) { a = 1 } diff --git a/test/mjsunit/harmony/proxies.js b/test/mjsunit/harmony/proxies.js index f3b355b76d..bebe14e36d 100644 --- a/test/mjsunit/harmony/proxies.js +++ b/test/mjsunit/harmony/proxies.js @@ -46,9 +46,7 @@ function TestWithObjectProxy(test, x, y, z) { } function TestWithFunctionProxy(test, x, y, z) { - test((handler) => { - return new Proxy(function() {}, handler) - }, x, y, z) + test((handler) => { return new Proxy(() => {}, handler) }, x, y, z) } // --------------------------------------------------------------------------- @@ -106,8 +104,8 @@ function TestGetOwnPropertyThrow(handler) { function TestGetOwnPropertyThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") - assertThrows(function(){ Object.getOwnPropertyDescriptor(p, 77) }, "myexn") + assertThrowsEquals(() => Object.getOwnPropertyDescriptor(p, "a"), "myexn") + assertThrowsEquals(() => Object.getOwnPropertyDescriptor(p, 77), "myexn") } TestGetOwnPropertyThrow({ @@ -116,7 +114,7 @@ TestGetOwnPropertyThrow({ TestGetOwnPropertyThrow({ getOwnPropertyDescriptor: function(k) { - return this.getPropertyDescriptor2(k) + return this.getOwnPropertyDescriptor2(k) }, getOwnPropertyDescriptor2: function(k) { throw "myexn" } }) @@ -267,18 +265,18 @@ function TestGetThrow(handler) { function TestGetThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ p.a }, "myexn") - assertThrows(function(){ p["b"] }, "myexn") - assertThrows(function(){ p[3] }, "myexn") - assertThrows(function(){ (function(n) { p[n] })("c") }, "myexn") - assertThrows(function(){ (function(n) { p[n] })(99) }, "myexn") + assertThrowsEquals(function(){ p.a }, "myexn") + assertThrowsEquals(function(){ p["b"] }, "myexn") + assertThrowsEquals(function(){ p[3] }, "myexn") + assertThrowsEquals(function(){ (function(n) { p[n] })("c") }, "myexn") + assertThrowsEquals(function(){ (function(n) { p[n] })(99) }, "myexn") var o = Object.create(p, {x: {value: 88}, '4': {value: 89}}) - assertThrows(function(){ o.a }, "myexn") - assertThrows(function(){ o["b"] }, "myexn") - assertThrows(function(){ o[3] }, "myexn") - assertThrows(function(){ (function(n) { o[n] })("c") }, "myexn") - assertThrows(function(){ (function(n) { o[n] })(99) }, "myexn") + assertThrowsEquals(function(){ o.a }, "myexn") + assertThrowsEquals(function(){ o["b"] }, "myexn") + assertThrowsEquals(function(){ o[3] }, "myexn") + assertThrowsEquals(function(){ (function(n) { o[n] })("c") }, "myexn") + assertThrowsEquals(function(){ (function(n) { o[n] })(99) }, "myexn") } TestGetThrow({ @@ -358,11 +356,11 @@ function TestSetThrow(handler) { function TestSetThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ p.a = 42 }, "myexn") - assertThrows(function(){ p["b"] = 42 }, "myexn") - assertThrows(function(){ p[22] = 42 }, "myexn") - assertThrows(function(){ (function(n) { p[n] = 45 })("c") }, "myexn") - assertThrows(function(){ (function(n) { p[n] = 46 })(99) }, "myexn") + assertThrowsEquals(function(){ p.a = 42 }, "myexn") + assertThrowsEquals(function(){ p["b"] = 42 }, "myexn") + assertThrowsEquals(function(){ p[22] = 42 }, "myexn") + assertThrowsEquals(function(){ (function(n) { p[n] = 45 })("c") }, "myexn") + assertThrowsEquals(function(){ (function(n) { p[n] = 46 })(99) }, "myexn") } TestSetThrow({ @@ -380,7 +378,9 @@ TestSetThrow({ }) TestSetThrow({ - getOwnPropertyDescriptor: function(k) { return {writable: true} }, + getOwnPropertyDescriptor: function(k) { + return {configurable: true, writable: true} + }, defineProperty: function(k, desc) { throw "myexn" } }) @@ -397,7 +397,9 @@ TestSetThrow({ getOwnPropertyDescriptor: function(k) { return this.getOwnPropertyDescriptor2(k) }, - getOwnPropertyDescriptor2: function(k) { return {writable: true} }, + getOwnPropertyDescriptor2: function(k) { + return {configurable: true, writable: true} + }, defineProperty: function(k, desc) { this.defineProperty2(k, desc) }, defineProperty2: function(k, desc) { throw "myexn" } }) @@ -409,7 +411,10 @@ TestSetThrow({ TestSetThrow({ getOwnPropertyDescriptor: function(k) { - return {get writable() { return true }} + return { + get configurable() { return true }, + get writable() { return true } + } }, defineProperty: function(k, desc) { throw "myexn" } }) @@ -418,51 +423,11 @@ TestSetThrow({ getOwnPropertyDescriptor: function(k) { throw "myexn" } }) -TestSetThrow({ - getOwnPropertyDescriptor: function(k) { - return {set: function(v) { throw "myexn" }} - } -}) - TestSetThrow({ getOwnPropertyDescriptor: function(k) { throw "myexn" }, - getPropertyDescriptor: function(k) { return {writable: true} }, defineProperty: function(k, desc) { key = k; val = desc.value } }) -TestSetThrow({ - getOwnPropertyDescriptor: function(k) { return null }, - getPropertyDescriptor: function(k) { throw "myexn" }, - defineProperty: function(k, desc) { key = k; val = desc.value } -}) - -TestSetThrow({ - getOwnPropertyDescriptor: function(k) { return null }, - getPropertyDescriptor: function(k) { return {writable: true} }, - defineProperty: function(k, desc) { throw "myexn" } -}) - -TestSetThrow({ - getOwnPropertyDescriptor: function(k) { return null }, - getPropertyDescriptor: function(k) { - return {get writable() { throw "myexn" }} - }, - defineProperty: function(k, desc) { key = k; val = desc.value } -}) - -TestSetThrow({ - getOwnPropertyDescriptor: function(k) { return null }, - getPropertyDescriptor: function(k) { - return {set: function(v) { throw "myexn" }} - } -}) - -TestSetThrow({ - getOwnPropertyDescriptor: function(k) { return null }, - getPropertyDescriptor: function(k) { return null }, - defineProperty: function(k, desc) { throw "myexn" } -}) - TestSetThrow(new Proxy({}, { get: function(pr, pk) { throw "myexn" } })) @@ -577,7 +542,7 @@ function TestDefine2(create, handler) { assertEquals(undefined, desc.mine) // Arguably a bug in the spec... var props = {bla: {get value() { throw "myexn" }}} - assertThrows(function(){ Object.defineProperties(p, props) }, "myexn") + assertThrowsEquals(function(){ Object.defineProperties(p, props) }, "myexn") } TestDefine({ @@ -597,22 +562,22 @@ function TestDefineThrow(handler) { function TestDefineThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn") - assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn") + assertThrowsEquals(() => Object.defineProperty(p, "a", {value: 44}), "myexn") + assertThrowsEquals(() => Object.defineProperty(p, 0, {value: 44}), "myexn") var d1 = create({ get: function(r, k) { throw "myexn" }, getOwnPropertyNames: function() { return ["value"] } }) - assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn") + assertThrowsEquals(function(){ Object.defineProperty(p, "p", d1) }, "myexn") var d2 = create({ get: function(r, k) { return 77 }, getOwnPropertyNames: function() { throw "myexn" } }) - assertThrows(function(){ Object.defineProperty(p, "p", d2) }, "myexn") + assertThrowsEquals(function(){ Object.defineProperty(p, "p", d2) }, "myexn") var props = {bla: {get value() { throw "otherexn" }}} - assertThrows(function(){ Object.defineProperties(p, props) }, "otherexn") + assertThrowsEquals(() => Object.defineProperties(p, props), "otherexn") } TestDefineThrow({ @@ -698,15 +663,15 @@ function TestDeleteThrow(handler) { function TestDeleteThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ delete p.a }, "myexn") - assertThrows(function(){ delete p["b"] }, "myexn"); - assertThrows(function(){ delete p[3] }, "myexn"); + assertThrowsEquals(function(){ delete p.a }, "myexn") + assertThrowsEquals(function(){ delete p["b"] }, "myexn"); + assertThrowsEquals(function(){ delete p[3] }, "myexn"); (function() { "use strict" - assertThrows(function(){ delete p.c }, "myexn") - assertThrows(function(){ delete p["d"] }, "myexn") - assertThrows(function(){ delete p[4] }, "myexn"); + assertThrowsEquals(function(){ delete p.c }, "myexn") + assertThrowsEquals(function(){ delete p["d"] }, "myexn") + assertThrowsEquals(function(){ delete p[4] }, "myexn"); })() } @@ -779,7 +744,7 @@ function TestDescriptorThrow(handler) { function TestDescriptorThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn") + assertThrowsEquals(() => Object.getOwnPropertyDescriptor(p, "a"), "myexn") } TestDescriptorThrow({ @@ -907,13 +872,13 @@ function TestInThrow(handler) { function TestInThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ return "a" in o }, "myexn") - assertThrows(function(){ return 99 in o }, "myexn") - assertThrows(function(){ return !("a" in o) }, "myexn") - assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn") - assertThrows(function(){ if ("b" in o) {} }, "myexn") - assertThrows(function(){ if (!("b" in o)) {} }, "myexn") - assertThrows(function(){ if ("zzz" in o) {} }, "myexn") + assertThrowsEquals(function(){ return "a" in p }, "myexn") + assertThrowsEquals(function(){ return 99 in p }, "myexn") + assertThrowsEquals(function(){ return !("a" in p) }, "myexn") + assertThrowsEquals(function(){ return ("a" in p) ? 2 : 3 }, "myexn") + assertThrowsEquals(function(){ if ("b" in p) {} }, "myexn") + assertThrowsEquals(function(){ if (!("b" in p)) {} }, "myexn") + assertThrowsEquals(function(){ if ("zzz" in p) {} }, "myexn") } TestInThrow({ @@ -925,20 +890,6 @@ TestInThrow({ has2: function(k) { throw "myexn" } }) -TestInThrow({ - getPropertyDescriptor: function(k) { throw "myexn" } -}) - -TestInThrow({ - getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) }, - getPropertyDescriptor2: function(k) { throw "myexn" } -}) - -TestInThrow({ - has: undefined, - getPropertyDescriptor: function(k) { throw "myexn" } -}) - TestInThrow(new Proxy({},{ get: function(pr, pk) { throw "myexn" } })) @@ -993,9 +944,9 @@ function TestHasOwnThrow(handler) { function TestHasOwnThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, + assertThrowsEquals(function(){ Object.prototype.hasOwnProperty.call(p, "a")}, "myexn") - assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, + assertThrowsEquals(function(){ Object.prototype.hasOwnProperty.call(p, 99)}, "myexn") } @@ -1182,7 +1133,7 @@ function TestPropertyNamesThrow(handler) { function TestPropertyNamesThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ Object.getOwnPropertyNames(p) }, "myexn") + assertThrowsEquals(function(){ Object.getOwnPropertyNames(p) }, "myexn") } TestPropertyNamesThrow({ @@ -1263,8 +1214,8 @@ function TestKeysThrow(handler) { } function TestKeysThrow2(create, handler) { - var p = create(handler) - assertThrows(function(){ Object.keys(p) }, "myexn") + var p = create(handler); + assertThrowsEquals(function(){ Object.keys(p) }, "myexn"); } TestKeysThrow({ @@ -1283,7 +1234,7 @@ TestKeysThrow({ TestKeysThrow({ ownKeys() { return this.getOwnPropertyNames2() }, - getOwnPropertyNames2() { return [1, 2] }, + getOwnPropertyNames2() { return ['1', '2'] }, getOwnPropertyDescriptor(k) { return this.getOwnPropertyDescriptor2(k) }, @@ -1302,7 +1253,7 @@ TestKeysThrow({ TestKeysThrow({ get ownKeys() { - return function() { return [1, 2] } + return function() { return ['1', '2'] } }, getOwnPropertyDescriptor(k) { throw "myexn" } }) @@ -1361,15 +1312,15 @@ TestToString(new Proxy({}, { function TestToStringThrow(handler) { var p = new Proxy({}, handler) assertEquals("[object Object]", Object.prototype.toString.call(p)) - assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn") + assertThrowsEquals(() => Object.prototype.toLocaleString.call(p), "myexn") var f = new Proxy(function(){}, handler) assertEquals("[object Function]", Object.prototype.toString.call(f)) - assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn") + assertThrowsEquals(() => Object.prototype.toLocaleString.call(f), "myexn") var o = Object.create(p) assertEquals("[object Object]", Object.prototype.toString.call(o)) - assertThrows(function(){ Object.prototype.toLocaleString.call(o) }, "myexn") + assertThrowsEquals(() => Object.prototype.toLocaleString.call(o), "myexn") } TestToStringThrow({ @@ -1478,10 +1429,10 @@ function TestIsEnumerableThrow(handler) { function TestIsEnumerableThrow2(create, handler) { var p = create(handler) - assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, "a") }, - "myexn") - assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, 11) }, - "myexn") + assertThrowsEquals(() => Object.prototype.propertyIsEnumerable.call(p, "a"), + "myexn") + assertThrowsEquals(() => Object.prototype.propertyIsEnumerable.call(p, 11), + "myexn") } TestIsEnumerableThrow({ diff --git a/test/mjsunit/harmony/reflect.js b/test/mjsunit/harmony/reflect.js index 8f04a44803..8ee1227a44 100644 --- a/test/mjsunit/harmony/reflect.js +++ b/test/mjsunit/harmony/reflect.js @@ -87,7 +87,7 @@ function prepare(target) { var a = { [Symbol.toPrimitive]: function() { return "bla" } }; var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; assertEquals(42, Reflect.get(target, a)); - assertThrows(function() { Reflect.get(target, b); }, "gaga"); + assertThrowsEquals(function() { Reflect.get(target, b); }, "gaga"); })(); @@ -156,7 +156,7 @@ function prepare(target) { var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; assertTrue(Reflect.set(target, a, 42)); assertEquals(42, target.bla); - assertThrows(function() { Reflect.set(target, b, 42); }, "gaga"); + assertThrowsEquals(function() { Reflect.set(target, b, 42); }, "gaga"); })(); @@ -297,7 +297,7 @@ function prepare(target) { var a = { [Symbol.toPrimitive]: function() { return "bla" } }; var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; assertTrue(Reflect.has(target, a)); - assertThrows(function() { Reflect.has(target, b); }, "gaga"); + assertThrowsEquals(function() { Reflect.has(target, b); }, "gaga"); })(); @@ -350,7 +350,7 @@ function prepare(target) { var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; assertTrue(Reflect.defineProperty(target, a, {value: 42})); assertEquals(target.bla, 42); - assertThrows(function() { Reflect.defineProperty(target, b); }, "gaga"); + assertThrowsEquals(function() { Reflect.defineProperty(target, b); }, "gaga"); })(); @@ -379,7 +379,7 @@ function prepare(target) { var a = { [Symbol.toPrimitive]: function() { return "bla" } }; var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; assertTrue(Reflect.deleteProperty(target, a)); - assertThrows(function() { Reflect.deleteProperty(target, b); }, "gaga"); + assertThrowsEquals(function() { Reflect.deleteProperty(target, b); }, "gaga"); })(); @@ -530,8 +530,7 @@ function prepare(target) { var a = { [Symbol.toPrimitive]: function() { return "bla" } }; var b = { [Symbol.toPrimitive]: function() { throw "gaga" } }; assertEquals(42, Reflect.getOwnPropertyDescriptor(target, a).value); - assertThrows(function() { Reflect.getOwnPropertyDescriptor(target, b); }, - "gaga"); + assertThrowsEquals(() => Reflect.getOwnPropertyDescriptor(target, b), "gaga"); })(); diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js index 27f4d3942a..9b07953c8a 100644 --- a/test/mjsunit/mjsunit.js +++ b/test/mjsunit/mjsunit.js @@ -93,6 +93,10 @@ var assertNotNull; // to the type property on the thrown exception. var assertThrows; +// Assert that the passed function throws an exception. +// The exception is checked against the second argument using assertEquals. +var assertThrowsEquals; + // Assert that the passed function or eval code does not throw an exception. var assertDoesNotThrow; @@ -353,6 +357,8 @@ var assertUnoptimized; } catch (e) { if (typeof type_opt === 'function') { assertInstanceof(e, type_opt); + } else if (type_opt !== void 0) { + fail("invalid use of assertThrows, maybe you want assertThrowsEquals"); } if (arguments.length >= 3) { assertEquals(e.type, cause_opt); @@ -364,6 +370,17 @@ var assertUnoptimized; }; + assertThrowsEquals = function assertThrowsEquals(fun, val) { + try { + fun(); + } catch(e) { + assertEquals(val, e); + return; + } + throw new MjsUnitAssertionError("Did not throw exception"); + }; + + assertInstanceof = function assertInstanceof(obj, type) { if (!(obj instanceof type)) { var actualTypeName = null; diff --git a/test/mjsunit/regress/regress-70066.js b/test/mjsunit/regress/regress-70066.js index 01c2f4f3a3..8787b76646 100644 --- a/test/mjsunit/regress/regress-70066.js +++ b/test/mjsunit/regress/regress-70066.js @@ -120,7 +120,7 @@ function test8() { } assertEquals(true, test8(), "test8"); -assertThrows("x", "test8"); // Global x should be deleted. +assertThrows("x"); // Global x should be deleted. // Delete on a property that is not found anywhere. @@ -128,7 +128,7 @@ function test9() { with ({}) { return delete x; } } -assertThrows("x", "test9"); // Make sure it's not there. +assertThrows("x"); // Make sure it's not there. assertEquals(true, test9(), "test9"); diff --git a/test/mjsunit/third_party/regexp-pcre/regexp-pcre.js b/test/mjsunit/third_party/regexp-pcre/regexp-pcre.js index c049fb4d09..68b8f0525b 100644 --- a/test/mjsunit/third_party/regexp-pcre/regexp-pcre.js +++ b/test/mjsunit/third_party/regexp-pcre/regexp-pcre.js @@ -1657,19 +1657,19 @@ assertNull(res[2].exec("Adefabc", 10)); assertToStringEquals("abc", res[7].exec("abc"), 11); assertNull(res[7].exec("*** Failers", 12)); assertNull(res[7].exec("def\nabc", 13)); -assertThrows("var re = /x{5,4}/;", 14); -assertThrows("var re = /[abcd/;", 15); -assertThrows("var re = /[z-a]/;", 16); -assertThrows("var re = /^*/;", 17); -assertThrows("var re = /(abc/;", 18); -assertThrows("var re = /(?# abc/;", 19); +assertThrows("var re = /x{5,4}/;"); +assertThrows("var re = /[abcd/;"); +assertThrows("var re = /[z-a]/;"); +assertThrows("var re = /^*/;"); +assertThrows("var re = /(abc/;"); +assertThrows("var re = /(?# abc/;"); assertToStringEquals("cat", res[11].exec("this sentence eventually mentions a cat"), 20); assertToStringEquals("elephant", res[11].exec("this sentences rambles on and on for a while and then reaches elephant"), 21); assertToStringEquals("cat", res[12].exec("this sentence eventually mentions a cat"), 22); assertToStringEquals("elephant", res[12].exec("this sentences rambles on and on for a while and then reaches elephant"), 23); assertToStringEquals("CAT", res[13].exec("this sentence eventually mentions a CAT cat"), 24); assertToStringEquals("elephant", res[13].exec("this sentences rambles on and on for a while to elephant ElePhant"), 25); -assertThrows("var re = /{4,5}abc/;", 26); +assertThrows("var re = /{4,5}abc/;"); assertToStringEquals("abcb,a,b,c", res[18].exec("abcb"), 27); assertToStringEquals("abcb,a,b,c", res[18].exec("O0abcb"), 28); assertToStringEquals("abcb,a,b,c", res[18].exec("O3abcb"), 29); @@ -1712,7 +1712,7 @@ assertNull(res[30].exec("abc\ndef", 65)); assertToStringEquals("abc", res[31].exec("abc"), 66); assertNull(res[31].exec("abc\n", 67)); assertToStringEquals("abc,abc", res[33].exec("abc"), 68); -assertThrows("var re = /)/;", 69); +assertThrows("var re = /)/;"); assertToStringEquals("-pr", res[35].exec("co-processors, and for"), 70); assertToStringEquals("ghi", res[36].exec("abcghinop"), 71); assertToStringEquals("", res[37].exec("abcghinop"), 72); @@ -1772,28 +1772,28 @@ assertNull(res[45].exec("fooabar", 125)); assertNull(res[46].exec("*** Failers", 126)); assertNull(res[46].exec("a", 127)); assertNull(res[48].exec("aaaaaa", 128)); -assertThrows("var re = /a[b-a]/;", 129); -assertThrows("var re = /a[/;", 130); -assertThrows("var re = /*a/;", 131); -assertThrows("var re = /abc)/;", 132); -assertThrows("var re = /(abc/;", 133); -assertThrows("var re = /a**/;", 134); -assertThrows("var re = /)(/;", 135); -assertThrows("var re = /a[b-a]/;", 136); -assertThrows("var re = /a[/;", 137); -assertThrows("var re = /*a/;", 138); -assertThrows("var re = /abc)/;", 139); -assertThrows("var re = /(abc/;", 140); -assertThrows("var re = /a**/;", 141); -assertThrows("var re = /)(/;", 142); -assertThrows("var re = /:(?:/;", 143); -assertThrows("var re = /a(?{)b/;", 144); -assertThrows("var re = /a(?{{})b/;", 145); -assertThrows("var re = /a(?{}})b/;", 146); -assertThrows("var re = /a(?{\"{\"})b/;", 147); -assertThrows("var re = /a(?{\"{\"}})b/;", 148); -assertThrows("var re = /[a[:xyz:/;", 149); -assertThrows("var re = /a{37,17}/;", 150); +assertThrows("var re = /a[b-a]/;"); +assertThrows("var re = /a[/;"); +assertThrows("var re = /*a/;"); +assertThrows("var re = /abc)/;"); +assertThrows("var re = /(abc/;"); +assertThrows("var re = /a**/;"); +assertThrows("var re = /)(/;"); +assertThrows("var re = /a[b-a]/;"); +assertThrows("var re = /a[/;"); +assertThrows("var re = /*a/;"); +assertThrows("var re = /abc)/;"); +assertThrows("var re = /(abc/;"); +assertThrows("var re = /a**/;"); +assertThrows("var re = /)(/;"); +assertThrows("var re = /:(?:/;"); +assertThrows("var re = /a(?{)b/;"); +assertThrows("var re = /a(?{{})b/;"); +assertThrows("var re = /a(?{}})b/;"); +assertThrows("var re = /a(?{\"{\"})b/;"); +assertThrows("var re = /a(?{\"{\"}})b/;"); +assertThrows("var re = /[a[:xyz:/;"); +assertThrows("var re = /a{37,17}/;"); assertToStringEquals("abcd,a,d", res[58].exec("abcd"), 151); assertToStringEquals("abcd,a,d", res[58].exec("abcdC2"), 152); assertToStringEquals("abcd,a,d", res[58].exec("abcdC5"), 153); @@ -1884,7 +1884,7 @@ assertNull(res[147].exec("aB", 237)); assertNull(res[147].exec("*** Failers", 238)); assertNull(res[147].exec("Ab", 239)); assertNull(res[147].exec("AB", 240)); -assertThrows("var re = /[\\200-\\110]/;", 241); +assertThrows("var re = /[\\200-\\110]/;"); assertToStringEquals("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 ABC ABC,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,50 ,51 ,52 ,53 ,54 ,55 ,56 ,57 ,58 ,59 ,60 ,61 ,62 ,63 ,64 ,65 ,66 ,67 ,68 ,69 ,70 ,71 ,72 ,73 ,74 ,75 ,76 ,77 ,78 ,79 ,80 ,81 ,82 ,83 ,84 ,85 ,86 ,87 ,88 ,89 ,90 ,91 ,92 ,93 ,94 ,95 ,96 ,97 ,98 ,99 ,100 ,101 ,102 ,103 ,104 ,105 ,106 ,107 ,108 ,109 ,110 ,111 ,112 ,113 ,114 ,115 ,116 ,117 ,118 ,119 ,120 ,121 ,122 ,123 ,124 ,125 ,126 ,127 ,128 ,129 ,130 ,131 ,132 ,133 ,134 ,135 ,136 ,137 ,138 ,139 ,140 ,141 ,142 ,143 ,144 ,145 ,146 ,147 ,148 ,149 ,150 ,151 ,152 ,153 ,154 ,155 ,156 ,157 ,158 ,159 ,160 ,161 ,162 ,163 ,164 ,165 ,166 ,167 ,168 ,169 ,170 ,171 ,172 ,173 ,174 ,175 ,176 ,177 ,178 ,179 ,180 ,181 ,182 ,183 ,184 ,185 ,186 ,187 ,188 ,189 ,190 ,191 ,192 ,193 ,194 ,195 ,196 ,197 ,198 ,199 ,200 ,201 ,202 ,203 ,204 ,205 ,206 ,207 ,208 ,209 ,210 ,211 ,212 ,213 ,214 ,215 ,216 ,217 ,218 ,219 ,220 ,221 ,222 ,223 ,224 ,225 ,226 ,227 ,228 ,229 ,230 ,231 ,232 ,233 ,234 ,235 ,236 ,237 ,238 ,239 ,240 ,241 ,242 ,243 ,244 ,245 ,246 ,247 ,248 ,249 ,250 ,251 ,252 ,253 ,254 ,255 ,256 ,257 ,258 ,259 ,260 ,261 ,262 ,263 ,264 ,265 ,266 ,267 ,268 ,269 ,ABC,ABC", res[149].exec("O900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 ABC ABC"), 242); assertToStringEquals("mainmain,main,", res[151].exec("mainmain"), 243); assertToStringEquals("mainOmain,main,", res[151].exec("mainOmain"), 244); @@ -1902,7 +1902,7 @@ assertToStringEquals("aabbaa,", res[163].exec("aabbaa"), 255); assertToStringEquals("aabbbaa,", res[164].exec("aabbbaa"), 256); assertToStringEquals("aabbbaa,aa,,", res[165].exec("aabbbaa"), 257); assertToStringEquals("aabbbbaa,aa,,", res[166].exec("aabbbbaa"), 258); -assertThrows("var re = //;", 259); +assertThrows("var re = //;"); assertToStringEquals("a", res[169].exec("ab"), 260); assertToStringEquals("a", res[169].exec("aB"), 261); assertToStringEquals("*", res[169].exec("*** Failers"), 262); @@ -1930,8 +1930,8 @@ assertNull(res[177].exec("*** Failers", 283)); assertNull(res[177].exec("((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 284)); assertNull(res[177].exec("xaaaab", 285)); assertNull(res[177].exec("xaaaab", 286)); -assertThrows("var re = /[/;", 287); -assertThrows("var re = /[a-/;", 288); +assertThrows("var re = /[/;"); +assertThrows("var re = /[a-/;"); assertNull(res[189].exec("<>", 289)); assertNull(res[189].exec("", 290)); assertNull(res[189].exec(" hij>", 291)); @@ -2111,7 +2111,7 @@ assertNull(res[255].exec("AbCd", 464)); assertNull(res[255].exec("** Failers", 465)); assertNull(res[255].exec("abcd", 466)); // We are compatible with JSC, and don't throw an exception in this case. -// assertThrows("var re = /(){2,4294967295}/;", 467); +// assertThrows("var re = /(){2,4294967295}/;"); assertNull(res[255].exec("abcdefghijklAkB", 468)); assertNull(res[255].exec("abcdefghijklAkB", 469)); assertNull(res[255].exec("abcdefghijklAkB", 470)); @@ -2230,7 +2230,7 @@ assertToStringEquals("x", res[350].exec("x"), 582); assertToStringEquals("ab", res[350].exec("abcabc"), 583); assertToStringEquals("Xaaa,a", res[351].exec("Xaaa"), 584); assertToStringEquals("Xaba,a", res[351].exec("Xaba"), 585); -assertThrows("var re = /^[a-\\Q\\E]/;", 586); +assertThrows("var re = /^[a-\\Q\\E]/;"); assertNull(res[353].exec("(xy)x", 587)); assertNull(res[353].exec("1221", 588)); assertNull(res[353].exec("Satan, oscillate my metallic sonatas!", 589)); @@ -2353,13 +2353,13 @@ assertToStringEquals("abc1", res[378].exec("abc1\n abc2\x0b abc3\x0c abc4\x0d ab assertToStringEquals("X", res[379].exec("XABC"), 706); assertNull(res[379].exec("** Failers ", 707)); assertToStringEquals("X", res[379].exec("XABCB"), 708); -assertThrows("var re = /(ab|c)(?-1)/;", 709); +assertThrows("var re = /(ab|c)(?-1)/;"); assertNull(res[379].exec("abc", 710)); assertNull(res[379].exec("xyabcabc", 711)); assertNull(res[379].exec("** Failers", 712)); assertNull(res[379].exec("xyabc ", 713)); -assertThrows("var re = /x(?-0)y/;", 714); -assertThrows("var re = /x(?-1)y/;", 715); +assertThrows("var re = /x(?-0)y/;"); +assertThrows("var re = /x(?-1)y/;"); assertNull(res[379].exec("abcX", 716)); assertNull(res[379].exec("Y", 717)); assertNull(res[379].exec("** Failers", 718)); @@ -2379,14 +2379,14 @@ assertNull(res[382].exec("** Failers", 731)); assertNull(res[382].exec("tom-bon ", 732)); assertNull(res[382].exec("tom-tom", 733)); assertNull(res[382].exec("bon-bon ", 734)); -assertThrows("var re = /(?|(abc)|(xyz))/;", 735); -assertThrows("var re = /(x)(?|(abc)|(xyz))(x)/;", 736); +assertThrows("var re = /(?|(abc)|(xyz))/;"); +assertThrows("var re = /(x)(?|(abc)|(xyz))(x)/;"); assertNull(res[383].exec("xabcx", 737)); assertNull(res[383].exec("xxyzx ", 738)); -assertThrows("var re = /(x)(?|(abc)(pqr)|(xyz))(x)/;", 739); +assertThrows("var re = /(x)(?|(abc)(pqr)|(xyz))(x)/;"); assertNull(res[383].exec("xabcpqrx", 740)); assertNull(res[383].exec("xxyzx ", 741)); -assertThrows("var re = /(?|(abc)|(xyz))\\1/;", 742); +assertThrows("var re = /(?|(abc)|(xyz))\\1/;"); assertNull(res[383].exec("abcabc", 743)); assertNull(res[383].exec("xyzxyz ", 744)); assertNull(res[383].exec("** Failers", 745)); @@ -2528,7 +2528,7 @@ assertNull(res[431].exec("a\x85b", 880)); assertNull(res[431].exec("a\nb", 881)); assertNull(res[431].exec("a\x0db ", 882)); assertNull(res[431].exec("a\x85b", 883)); -assertThrows("var re = /(?-+a)/;", 884); +assertThrows("var re = /(?-+a)/;"); assertNull(res[443].exec("aaaa", 885)); assertNull(res[443].exec("bacxxx", 886)); assertNull(res[443].exec("bbaccxxx ", 887)); @@ -4082,7 +4082,7 @@ assertToStringEquals("bababc,ba", res[808].exec("bababc"), 2434); assertNull(res[808].exec("*** Failers", 2435)); assertNull(res[808].exec("bababbc", 2436)); assertNull(res[808].exec("babababc", 2437)); -assertThrows("var re = /^\\ca\\cA\\c[\\c{\\c:/;", 2438); +assertThrows("var re = /^\\ca\\cA\\c[\\c{\\c:/;"); assertNull(res[808].exec("\x01\x01e;z", 2439)); assertToStringEquals("a", res[809].exec("athing"), 2440); assertToStringEquals("b", res[809].exec("bthing"), 2441); @@ -4478,7 +4478,7 @@ assertToStringEquals(".23,.23,", res[925].exec("1.230003938 "), 2830); assertToStringEquals(".875,.875,5", res[925].exec("1.875000282"), 2831); assertNull(res[925].exec("*** Failers ", 2832)); assertNull(res[925].exec("1.235 ", 2833)); -assertThrows("var re = /a(?)b/;", 2834); +assertThrows("var re = /a(?)b/;"); assertNull(res[925].exec("ab ", 2835)); assertToStringEquals("foo table,foo,table", res[926].exec("Food is on the foo table"), 2836); assertToStringEquals("food is under the bar in the bar,d is under the bar in the ", res[927].exec("The food is under the bar in the barn."), 2837); @@ -4625,7 +4625,7 @@ assertToStringEquals("\"the \\\"quick\\\" brown fox\", brown fox", res[983].exec assertToStringEquals("", res[984].exec("abc"), 2978); assertToStringEquals("", res[985].exec("abc "), 2979); assertToStringEquals("", res[986].exec("abc "), 2980); -assertThrows("var re = //;", 2981); +assertThrows("var re = //;"); assertToStringEquals("", res[986].exec("abc"), 2982); assertToStringEquals("acb", res[988].exec("acb"), 2983); assertToStringEquals("a\nb", res[988].exec("a\nb"), 2984); @@ -5593,11 +5593,11 @@ assertToStringEquals("X", res[1330].exec("XABCB"), 3945); assertNull(res[1330].exec("abc\x0d\n\x0d\n", 3946)); assertNull(res[1330].exec("abc\x0d\n\x0d\n", 3947)); assertNull(res[1330].exec("abc\x0d\n\x0d\n", 3948)); -assertThrows("var re = /(?|(abc)|(xyz))/;", 3949); -assertThrows("var re = /(x)(?|(abc)|(xyz))(x)/;", 3950); +assertThrows("var re = /(?|(abc)|(xyz))/;"); +assertThrows("var re = /(x)(?|(abc)|(xyz))(x)/;"); assertNull(res[1330].exec("xabcx", 3951)); assertNull(res[1330].exec("xxyzx ", 3952)); -assertThrows("var re = /(x)(?|(abc)(pqr)|(xyz))(x)/;", 3953); +assertThrows("var re = /(x)(?|(abc)(pqr)|(xyz))(x)/;"); assertNull(res[1330].exec("xabcpqrx", 3954)); assertNull(res[1330].exec("xxyzx ", 3955)); assertNull(res[1330].exec("abcabc", 3956)); @@ -6600,4 +6600,4 @@ assertNull(res[1546].exec("x{1d79}x{a77d} ", 4952)); assertNull(res[1546].exec("x{a77d}x{1d79}", 4953)); assertNull(res[1546].exec("** Failers ", 4954)); assertNull(res[1546].exec("x{1d79}x{a77d} ", 4955)); -assertThrows("var re = //;", 4956); +assertThrows("var re = //;");