From 57f3466cf718e017fcbeea9de72404885ad05219 Mon Sep 17 00:00:00 2001 From: Mike Pennisi <mike@mikepennisi.com> Date: Tue, 16 Jun 2015 12:35:27 -0400 Subject: [PATCH] Fix tautological pattern in tests In neglecting to assert the type of error thrown (or that any error was thrown at all), these tests cannot fail. Refactor the tests to use the `assert.throws` helper method, which takes these details into consideration. --- test/built-ins/Function/prototype/S15.3.4_A5.js | 13 +++---------- .../Function/prototype/toString/S15.3.4.2_A7.js | 11 +++-------- test/built-ins/Object/prototype/S15.2.4_A3.js | 10 ++-------- test/built-ins/Object/prototype/S15.2.4_A4.js | 12 +++--------- .../Object/prototype/hasOwnProperty/S15.2.4.5_A7.js | 10 +++------- .../Object/prototype/isPrototypeOf/S15.2.4.6_A7.js | 12 +++--------- .../prototype/propertyIsEnumerable/S15.2.4.7_A7.js | 12 +++--------- .../Object/prototype/toLocaleString/S15.2.4.3_A7.js | 12 +++--------- .../Object/prototype/toString/S15.2.4.2_A7.js | 11 +++-------- .../Object/prototype/valueOf/S15.2.4.4_A7.js | 10 +++------- .../String/prototype/lastIndexOf/S15.5.4.8_A7.js | 13 ++++--------- .../String/prototype/slice/S15.5.4.13_A7.js | 13 ++++--------- test/language/statements/block/S12.1_A2.js | 12 ++++++------ test/language/statements/variable/S12.2_A1.js | 8 ++------ test/language/statements/variable/S12.2_A5.js | 8 ++------ 15 files changed, 47 insertions(+), 120 deletions(-) diff --git a/test/built-ins/Function/prototype/S15.3.4_A5.js b/test/built-ins/Function/prototype/S15.3.4_A5.js index e691fb2f89..49886228fd 100644 --- a/test/built-ins/Function/prototype/S15.3.4_A5.js +++ b/test/built-ins/Function/prototype/S15.3.4_A5.js @@ -7,15 +7,8 @@ info: > [[Construct]] property es5id: 15.3.4_A5 description: Checking if creating "new Function.prototype object" fails -includes: - - $PRINT.js ---*/ -//CHECK# -try { - var obj = new Function.prototype; - $ERROR('#1: The Function prototype object is itself a Function object without [[Construct]] property: '+e); -} catch (e) { - $PRINT("#1.1: The Function prototype object is itself a Function object without [[Construct]] property "+e); - -} +assert.throws(TypeError, function() { + new Function.prototype; +}); diff --git a/test/built-ins/Function/prototype/toString/S15.3.4.2_A7.js b/test/built-ins/Function/prototype/toString/S15.3.4.2_A7.js index c6d46fcae2..ef8ce26959 100644 --- a/test/built-ins/Function/prototype/toString/S15.3.4.2_A7.js +++ b/test/built-ins/Function/prototype/toString/S15.3.4.2_A7.js @@ -5,15 +5,10 @@ info: Function.prototype.toString can't be used as constructor es5id: 15.3.4.2_A7 description: Checking if creating "new Function.prototype.toString" fails -includes: - - $PRINT.js ---*/ var FACTORY = Function.prototype.toString; -try { - var instance = new FACTORY; - $ERROR('#1: Function.prototype.toString can\'t be used as constructor'); -} catch (e) { - $PRINT(e); -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/Object/prototype/S15.2.4_A3.js b/test/built-ins/Object/prototype/S15.2.4_A3.js index 4f8f3bad8f..3afac8afb5 100644 --- a/test/built-ins/Object/prototype/S15.2.4_A3.js +++ b/test/built-ins/Object/prototype/S15.2.4_A3.js @@ -7,14 +7,8 @@ info: > method es5id: 15.2.4_A3 description: Checking if calling Object prototype as a function fails -includes: - - $PRINT.js ---*/ -//CHECK#1 -try { +assert.throws(TypeError, function() { Object.prototype(); - $ERROR('#1: Since Object prototype object is not function it has not [[call]] method'); -} catch (e) { - $PRINT(e); -} +}); diff --git a/test/built-ins/Object/prototype/S15.2.4_A4.js b/test/built-ins/Object/prototype/S15.2.4_A4.js index 8cff6c8f43..3f575d5fa3 100644 --- a/test/built-ins/Object/prototype/S15.2.4_A4.js +++ b/test/built-ins/Object/prototype/S15.2.4_A4.js @@ -7,14 +7,8 @@ info: > [[create]] method es5id: 15.2.4_A4 description: Checking if creating "new Object.prototype" fails -includes: - - $PRINT.js ---*/ -//CHECK#1 -try { - var instance = new Object.prototype; - $ERROR('#1: Since Object prototype object is not function it has not [[create]] method'); -} catch (e) { - $PRINT(e); -} +assert.throws(TypeError, function() { + new Object.prototype; +}); diff --git a/test/built-ins/Object/prototype/hasOwnProperty/S15.2.4.5_A7.js b/test/built-ins/Object/prototype/hasOwnProperty/S15.2.4.5_A7.js index 228b00b07c..a6480454eb 100644 --- a/test/built-ins/Object/prototype/hasOwnProperty/S15.2.4.5_A7.js +++ b/test/built-ins/Object/prototype/hasOwnProperty/S15.2.4.5_A7.js @@ -11,10 +11,6 @@ includes: var FACTORY = Object.prototype.hasOwnProperty; -try { - var instance = new FACTORY; - $ERROR('#1: Object.prototype.hasOwnProperty can\'t be used as a constructor'); -} catch (e) { - $PRINT(e); - -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/Object/prototype/isPrototypeOf/S15.2.4.6_A7.js b/test/built-ins/Object/prototype/isPrototypeOf/S15.2.4.6_A7.js index 410f91bb64..5e9bf6d46f 100644 --- a/test/built-ins/Object/prototype/isPrototypeOf/S15.2.4.6_A7.js +++ b/test/built-ins/Object/prototype/isPrototypeOf/S15.2.4.6_A7.js @@ -5,16 +5,10 @@ info: Object.prototype.isPrototypeOf can't be used as a constructor es5id: 15.2.4.6_A7 description: Checking if creating new "Object.prototype.isPrototypeOf" fails -includes: - - $PRINT.js ---*/ var FACTORY = Object.prototype.isPrototypeOf; -try { - var instance = new FACTORY; - $ERROR('#1: Object.prototype.isPrototypeOf can\'t be used as a constructor'); -} catch (e) { - $PRINT(e); - -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/Object/prototype/propertyIsEnumerable/S15.2.4.7_A7.js b/test/built-ins/Object/prototype/propertyIsEnumerable/S15.2.4.7_A7.js index 34821898f3..98ac74a123 100644 --- a/test/built-ins/Object/prototype/propertyIsEnumerable/S15.2.4.7_A7.js +++ b/test/built-ins/Object/prototype/propertyIsEnumerable/S15.2.4.7_A7.js @@ -7,16 +7,10 @@ es5id: 15.2.4.7_A7 description: > Checking if creating "new Object.prototype.propertyIsEnumerable" fails -includes: - - $PRINT.js ---*/ var FACTORY = Object.prototype.propertyIsEnumerable; -try { - var instance = new FACTORY; - $ERROR('#1: Object.prototype.propertyIsEnumerable can\'t be used as a constructor'); -} catch (e) { - $PRINT(e); - -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/Object/prototype/toLocaleString/S15.2.4.3_A7.js b/test/built-ins/Object/prototype/toLocaleString/S15.2.4.3_A7.js index 5567a3fb80..b186512351 100644 --- a/test/built-ins/Object/prototype/toLocaleString/S15.2.4.3_A7.js +++ b/test/built-ins/Object/prototype/toLocaleString/S15.2.4.3_A7.js @@ -5,16 +5,10 @@ info: Object.prototype.toLocaleString can't be used as a constructor es5id: 15.2.4.3_A7 description: Checking if creating "new Object.prototype.toLocaleString" fails -includes: - - $PRINT.js ---*/ var FACTORY = Object.prototype.toLocaleString; -try { - var instance = new FACTORY; - $ERROR('#1: Object.prototype.toLocaleString can\'t be used as a constructor'); -} catch (e) { - $PRINT(e); - -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/Object/prototype/toString/S15.2.4.2_A7.js b/test/built-ins/Object/prototype/toString/S15.2.4.2_A7.js index ea58f028ec..99e331d7d9 100644 --- a/test/built-ins/Object/prototype/toString/S15.2.4.2_A7.js +++ b/test/built-ins/Object/prototype/toString/S15.2.4.2_A7.js @@ -5,15 +5,10 @@ info: Object.prototype.toString can't be used as a constructor es5id: 15.2.4.2_A7 description: Checking if creating "new Object.prototype.toString" fails -includes: - - $PRINT.js ---*/ var FACTORY = Object.prototype.toString; -try { - var instance = new FACTORY; - $ERROR('#1: Object.prototype.toString can\'t be used as a constructor'); -} catch (e) { - $PRINT(e); -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/Object/prototype/valueOf/S15.2.4.4_A7.js b/test/built-ins/Object/prototype/valueOf/S15.2.4.4_A7.js index 902fa142a8..44490329c7 100644 --- a/test/built-ins/Object/prototype/valueOf/S15.2.4.4_A7.js +++ b/test/built-ins/Object/prototype/valueOf/S15.2.4.4_A7.js @@ -11,10 +11,6 @@ includes: var FACTORY = Object.prototype.valueOf; -try { - var instance = new FACTORY; - $ERROR('#1: Object.prototype.valueOf can\'t be used as a constructor'); -} catch (e) { - $PRINT(e); - -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/String/prototype/lastIndexOf/S15.5.4.8_A7.js b/test/built-ins/String/prototype/lastIndexOf/S15.5.4.8_A7.js index a9e1972280..40a0c4941f 100644 --- a/test/built-ins/String/prototype/lastIndexOf/S15.5.4.8_A7.js +++ b/test/built-ins/String/prototype/lastIndexOf/S15.5.4.8_A7.js @@ -5,15 +5,10 @@ info: String.prototype.lastIndexOf can't be used as constructor es5id: 15.5.4.8_A7 description: Checking if creating the String.prototype.lastIndexOf object fails -includes: - - $PRINT.js ---*/ -var __FACTORY = String.prototype.lastIndexOf; +var FACTORY = String.prototype.lastIndexOf; -try { - var __instance = new __FACTORY; - $ERROR('#1: __FACTORY = String.prototype.lastIndexOf; __instance = new __FACTORY lead to throwing exception'); -} catch (e) { - $PRINT(e); -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/built-ins/String/prototype/slice/S15.5.4.13_A7.js b/test/built-ins/String/prototype/slice/S15.5.4.13_A7.js index 7246b6d8f0..deba84f20f 100644 --- a/test/built-ins/String/prototype/slice/S15.5.4.13_A7.js +++ b/test/built-ins/String/prototype/slice/S15.5.4.13_A7.js @@ -5,15 +5,10 @@ info: String.prototype.slice can't be used as constructor es5id: 15.5.4.13_A7 description: Checking if creating the String.prototype.slice object fails -includes: - - $PRINT.js ---*/ -var __FACTORY = String.prototype.slice; +var FACTORY = String.prototype.slice; -try { - var __instance = new __FACTORY; - $ERROR('#1: __FACTORY = String.prototype.slice; "__instance = new __FACTORY" lead to throwing exception'); -} catch (e) { - $PRINT(e); -} +assert.throws(TypeError, function() { + new FACTORY; +}); diff --git a/test/language/statements/block/S12.1_A2.js b/test/language/statements/block/S12.1_A2.js index eda09af2c4..7b3cf0d396 100644 --- a/test/language/statements/block/S12.1_A2.js +++ b/test/language/statements/block/S12.1_A2.js @@ -13,12 +13,12 @@ includes: [$PRINT.js] ////////////////////////////////////////////////////////////////////////////// //CHECK#1 -try { - x(); - $ERROR('#1: "x()" lead to throwing exception'); -} catch (e) { - $PRINT(e.message); -} +assert.throws(ReferenceError, function() { + { + x(); + } +}); + // ////////////////////////////////////////////////////////////////////////////// diff --git a/test/language/statements/variable/S12.2_A1.js b/test/language/statements/variable/S12.2_A1.js index 76bf477558..1a53da0664 100644 --- a/test/language/statements/variable/S12.2_A1.js +++ b/test/language/statements/variable/S12.2_A1.js @@ -8,7 +8,6 @@ info: > VariableStatement is executed, not when the variable is created es5id: 12.2_A1 description: Creating variables after entering the execution scope -includes: [$PRINT.js] ---*/ ////////////////////////////////////////////////////////////////////////////// @@ -25,12 +24,9 @@ try { ////////////////////////////////////////////////////////////////////////////// //CHECK#2 -try{ +assert.throws(ReferenceError, function() { __something__undefined = __something__undefined; - $ERROR('#2: "__something__undefined = __something__undefined" lead to throwing exception'); -} catch(e){ - $PRINT(e.message); -} +}); // ////////////////////////////////////////////////////////////////////////////// diff --git a/test/language/statements/variable/S12.2_A5.js b/test/language/statements/variable/S12.2_A5.js index 877b9c7287..6a0de73113 100644 --- a/test/language/statements/variable/S12.2_A5.js +++ b/test/language/statements/variable/S12.2_A5.js @@ -7,18 +7,14 @@ info: > reaches the eval statement es5id: 12.2_A5 description: Executing eval("var x") -includes: [$PRINT.js] flags: [noStrict] ---*/ ////////////////////////////////////////////////////////////////////////////// //CHECK#1 -try{ +assert.throws(ReferenceError, function() { x=x; - $ERROR('#1: "x=x" lead to throwing exception'); -}catch(e){ - $PRINT(e.message); -}; +}); // ////////////////////////////////////////////////////////////////////////////// -- GitLab