Changeset 202609 in webkit


Ignore:
Timestamp:
Jun 28, 2016 9:17:36 PM (8 years ago)
Author:
ddkilzer@apple.com
Message:

Enhance shouldNotThrow()/shouldThrow() to accept functions and a descriptive message
<https://webkit.org/b/159232>

Reviewed by Brent Fulgham.

Based on a Blink change (patch by <hongchan@chromium.org>):
<https://src.chromium.org/viewvc/blink?view=revision&revision=192204>

Currently, shouldNotThrow() and shouldThrow() take the following
arguments:

shouldNotThrow(evalString)
shouldThrow(evalString, expectedExceptionString)

The challenges with this design are:

1) The 'evalString' must capture every variable that it

needs, which means the code can be long, and concatenated
into a single line. It would be really nice to be able
to use an (anonymous) function to capture variables
instead.

2) The 'evalString' is literally printed out in the test

results, which isn't always the most descriptive. A
descriptive message would make it clearer what failed.

3) When changing a shouldThrow() into a shouldNotThrow()

or copying/pasting code, it's possible to forget to
remove 'expectedExceptionString' from the function call.

This patch changes the methods to take the following arguments:

shouldNotThrow(evalString|function [, message])
shouldThrow(evalString|function, expectedExceptionString [, message])

If 'function' is passed in, then it is invoked instead of
evaluated, and 'message' replaces the literal code in the
pass/fail output.

This patch also adds the global 'didFailSomeTests' variable to
js-test.js, which already exists in js-test-pre.js. This was
added to js-test-pre.js in r153203 by Oliver Hunt to
LayoutTests/fast/js/resources/js-test-pre.js.

  • fast/canvas/webgl/canvas-supports-context-expected.txt:
  • fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt:
  • fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt:
  • fast/dom/getElementsByClassName/ASCII-case-insensitive-expected.txt:
  • storage/indexeddb/cursor-basics-expected.txt:
  • storage/indexeddb/cursor-basics-private-expected.txt:
  • Update expected results to include "Some tests fail." since some subtests actually do fail during these tests.
  • fast/css/parsing-css-lang.html:
  • fast/css/parsing-css-matches-1.html:
  • fast/css/parsing-css-matches-2.html:
  • fast/css/parsing-css-matches-3.html:
  • fast/css/parsing-css-matches-4.html:
  • fast/css/parsing-css-not-1.html:
  • fast/css/parsing-css-not-2.html:
  • fast/css/parsing-css-not-3.html:
  • fast/css/parsing-css-not-4.html:
  • fast/css/parsing-css-nth-child-of-1.html:
  • fast/css/parsing-css-nth-child-of-2.html:
  • fast/css/parsing-css-nth-last-child-of-1.html:
  • fast/css/parsing-css-nth-last-child-of-2.html:
  • js/script-tests/arrowfunction-supercall.js:
  • Remove expectedExceptionString from shouldNotThrow() calls after they were changed from shouldThrow() calls.
  • resources/js-test-pre.js:

(shouldNotThrow): Change to invoke first argument if it is a
function, else use eval() as before. Use second argurment in
place of first argument (if set) when printing results. NOTE:
Care was taken not to add any lines of code to prevent changes
to test results.
(shouldThrow): Ditto. Reformat code.

  • resources/js-test.js: Declare 'didFailSomeTests'.

(testFailed): Set 'didFailSomeTests' to true when a test fails.
(shouldNotThrow): Same changes as js-test-pre.js.
(shouldThrow): Ditto.
(isSuccessfullyParsed): Output a message if 'didFailSomeTests'
is true.

Location:
trunk/LayoutTests
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r202599 r202609  
     12016-06-28  David Kilzer  <ddkilzer@apple.com>
     2
     3        Enhance shouldNotThrow()/shouldThrow() to accept functions and a descriptive message
     4        <https://webkit.org/b/159232>
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Based on a Blink change (patch by <hongchan@chromium.org>):
     9        <https://src.chromium.org/viewvc/blink?view=revision&revision=192204>
     10
     11        Currently, shouldNotThrow() and shouldThrow() take the following
     12        arguments:
     13
     14            shouldNotThrow(evalString)
     15            shouldThrow(evalString, expectedExceptionString)
     16
     17        The challenges with this design are:
     18
     19            1) The 'evalString' must capture every variable that it
     20               needs, which means the code can be long, and concatenated
     21               into a single line.  It would be really nice to be able
     22               to use an (anonymous) function to capture variables
     23               instead.
     24            2) The 'evalString' is literally printed out in the test
     25               results, which isn't always the most descriptive.  A
     26               descriptive message would make it clearer what failed.
     27            3) When changing a shouldThrow() into a shouldNotThrow()
     28               or copying/pasting code, it's possible to forget to
     29               remove 'expectedExceptionString' from the function call.
     30
     31        This patch changes the methods to take the following arguments:
     32
     33            shouldNotThrow(evalString|function [, message])
     34            shouldThrow(evalString|function, expectedExceptionString [, message])
     35
     36        If 'function' is passed in, then it is invoked instead of
     37        evaluated, and 'message' replaces the literal code in the
     38        pass/fail output.
     39
     40        This patch also adds the global 'didFailSomeTests' variable to
     41        js-test.js, which already exists in js-test-pre.js.  This was
     42        added to js-test-pre.js in r153203 by Oliver Hunt to
     43        LayoutTests/fast/js/resources/js-test-pre.js.
     44
     45        * fast/canvas/webgl/canvas-supports-context-expected.txt:
     46        * fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt:
     47        * fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt:
     48        * fast/dom/getElementsByClassName/ASCII-case-insensitive-expected.txt:
     49        * storage/indexeddb/cursor-basics-expected.txt:
     50        * storage/indexeddb/cursor-basics-private-expected.txt:
     51        - Update expected results to include "Some tests fail." since
     52          some subtests actually do fail during these tests.
     53
     54        * fast/css/parsing-css-lang.html:
     55        * fast/css/parsing-css-matches-1.html:
     56        * fast/css/parsing-css-matches-2.html:
     57        * fast/css/parsing-css-matches-3.html:
     58        * fast/css/parsing-css-matches-4.html:
     59        * fast/css/parsing-css-not-1.html:
     60        * fast/css/parsing-css-not-2.html:
     61        * fast/css/parsing-css-not-3.html:
     62        * fast/css/parsing-css-not-4.html:
     63        * fast/css/parsing-css-nth-child-of-1.html:
     64        * fast/css/parsing-css-nth-child-of-2.html:
     65        * fast/css/parsing-css-nth-last-child-of-1.html:
     66        * fast/css/parsing-css-nth-last-child-of-2.html:
     67        * js/script-tests/arrowfunction-supercall.js:
     68        - Remove expectedExceptionString from shouldNotThrow() calls
     69          after they were changed from shouldThrow() calls.
     70
     71        * resources/js-test-pre.js:
     72        (shouldNotThrow): Change to invoke first argument if it is a
     73        function, else use eval() as before.  Use second argurment in
     74        place of first argument (if set) when printing results.  NOTE:
     75        Care was taken not to add any lines of code to prevent changes
     76        to test results.
     77        (shouldThrow): Ditto.  Reformat code.
     78        * resources/js-test.js: Declare 'didFailSomeTests'.
     79        (testFailed): Set 'didFailSomeTests' to true when a test fails.
     80        (shouldNotThrow): Same changes as js-test-pre.js.
     81        (shouldThrow): Ditto.
     82        (isSuccessfullyParsed): Output a message if 'didFailSomeTests'
     83        is true.
     84
    1852016-06-28  Jiewen Tan  <jiewen_tan@apple.com>
    286
  • trunk/LayoutTests/fast/canvas/webgl/canvas-supports-context-expected.txt

    r155137 r202609  
    116116
    117117PASS successfullyParsed is true
     118Some tests failed.
    118119
    119120TEST COMPLETE
  • trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt

    r168112 r202609  
    2424
    2525PASS successfullyParsed is true
     26Some tests failed.
    2627
    2728TEST COMPLETE
  • trunk/LayoutTests/fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt

    r201399 r202609  
    5858PASS window.getComputedStyle(element, '').getPropertyValue('grid-template-columns') is "none"
    5959PASS successfullyParsed is true
     60Some tests failed.
    6061
    6162TEST COMPLETE
  • trunk/LayoutTests/fast/css/parsing-css-lang.html

    r180558 r202609  
    1212
    1313function testValidLanguageRange(languageRangeString, expectedSerializedLanguageRange) {
    14     shouldNotThrow('document.querySelector(\':lang(' + languageRangeString.replace(/\\/g, '\\\\') + ')\')', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(\':lang(' + languageRangeString.replace(/\\/g, '\\\\') + ')\')');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-matches-1.html

    r177313 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-matches-2.html

    r177313 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-matches-3.html

    r174259 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-matches-4.html

    r177313 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":matches(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-not-1.html

    r177313 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-not-2.html

    r177313 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-not-3.html

    r174535 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-not-4.html

    r177313 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":not(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-nth-child-of-1.html

    r173856 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":nth-child(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":nth-child(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-nth-child-of-2.html

    r173856 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":nth-child(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":nth-child(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-nth-last-child-of-1.html

    r175848 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":nth-last-child(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":nth-last-child(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/css/parsing-css-nth-last-child-of-2.html

    r175848 r202609  
    1212
    1313function testValidSelector(selectorString, expectedSerializedSelector) {
    14     shouldNotThrow('document.querySelector(":nth-last-child(' + selectorString.replace(/\\/g, '\\\\') + ')")', '"Error: SyntaxError: DOM Exception 12"');
     14    shouldNotThrow('document.querySelector(":nth-last-child(' + selectorString.replace(/\\/g, '\\\\') + ')")');
    1515
    1616    var styleContainer = document.getElementById('style-container');
  • trunk/LayoutTests/fast/dom/getElementsByClassName/ASCII-case-insensitive-expected.txt

    r169358 r202609  
    44PASS getByClassName('Ä') is "Ä"
    55PASS successfullyParsed is true
     6Some tests failed.
    67
    78TEST COMPLETE
  • trunk/LayoutTests/js/script-tests/arrowfunction-supercall.js

    r200824 r202609  
    152152shouldThrow('(new class extends A { constructor() { ((a = this)=>{ return a; })() } })', '"ReferenceError: Cannot access uninitialized variable."');
    153153shouldThrow('(new class extends A { constructor() { ((a = this, b=super())=>{ return a; })() } })', '"ReferenceError: Cannot access uninitialized variable."');
    154 shouldNotThrow('(new class extends A { constructor() { ((a = new.target)=>{ return a; })(); super(); } })', '"ReferenceError: Cannot access uninitialized variable."');
    155 shouldNotThrow('(new class extends A { constructor() { ((a = new.target, b=super())=>{ return a; })() } })', '"ReferenceError: Cannot access uninitialized variable."');
     154shouldNotThrow('(new class extends A { constructor() { ((a = new.target)=>{ return a; })(); super(); } })');
     155shouldNotThrow('(new class extends A { constructor() { ((a = new.target, b=super())=>{ return a; })() } })');
    156156
    157157var successfullyParsed = true;
  • trunk/LayoutTests/resources/js-test-pre.js

    r178756 r202609  
    584584}
    585585
    586 function shouldNotThrow(_a) {
     586function shouldNotThrow(_a, _message) {
    587587    try {
    588         eval(_a);
    589         testPassed(_a + " did not throw exception.");
     588        typeof _a == "function" ? _a() : eval(_a);
     589        testPassed((_message ? _message : _a) + " did not throw exception.");
    590590    } catch (e) {
    591         testFailed(_a + " should not throw exception. Threw exception " + e + ".");
    592     }
    593 }
    594 
    595 function shouldThrow(_a, _e)
    596 {
    597   var exception;
    598   var _av;
    599   try {
    600      _av = eval(_a);
    601   } catch (e) {
    602      exception = e;
    603   }
    604 
    605   var _ev;
    606   if (_e)
    607       _ev =  eval(_e);
    608 
    609   if (exception) {
    610     if (typeof _e == "undefined" || exception == _ev)
    611       testPassed(_a + " threw exception " + exception + ".");
     591        testFailed((_message ? _message : _a) + " should not throw exception. Threw exception " + e + ".");
     592    }
     593}
     594
     595function shouldThrow(_a, _e, _message)
     596{
     597    var _exception;
     598    var _av;
     599    try {
     600        _av = typeof _a == "function" ? _a() : eval(_a);
     601    } catch (e) {
     602        _exception = e;
     603    }
     604
     605    var _ev;
     606    if (_e)
     607        _ev = eval(_e);
     608
     609    if (_exception) {
     610        if (typeof _e == "undefined" || _exception == _ev)
     611            testPassed((_message ? _message : _a) + " threw exception " + _exception + ".");
     612        else
     613            testFailed((_message ? _message : _a) + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Threw exception " + _exception + ".");
     614    } else if (typeof _av == "undefined")
     615        testFailed((_message ? _message : _a) + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was undefined.");
    612616    else
    613       testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Threw exception " + exception + ".");
    614   } else if (typeof _av == "undefined")
    615     testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was undefined.");
    616   else
    617     testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + ".");
     617        testFailed((_message ? _message : _a) + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + ".");
    618618}
    619619
  • trunk/LayoutTests/resources/js-test.js

    r196137 r202609  
    1111}
    1212
    13 var description, debug, successfullyParsed;
     13var description, debug, didFailSomeTests, successfullyParsed;
     14
     15didFailSomeTests = false;
    1416
    1517var expectingError; // set by shouldHaveError()
     
    154156function testFailed(msg)
    155157{
     158    didFailSomeTests = true;
    156159    debug('<span><span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>');
    157160}
     
    560563}
    561564
    562 function shouldNotThrow(_a) {
     565function shouldNotThrow(_a, _message) {
    563566    try {
    564         eval(_a);
    565         testPassed(_a + " did not throw exception.");
     567        typeof _a == "function" ?  _a() : eval(_a);
     568        testPassed((_message ? _message : _a) + " did not throw exception.");
    566569    } catch (e) {
    567         testFailed(_a + " should not throw exception. Threw exception " + e + ".");
    568     }
    569 }
    570 
    571 function shouldThrow(_a, _e)
    572 {
    573   var _exception;
    574   var _av;
    575   try {
    576      _av = eval(_a);
    577   } catch (e) {
    578      _exception = e;
    579   }
    580 
    581   var _ev;
    582   if (_e)
    583       _ev = eval(_e);
    584 
    585   if (_exception) {
    586     if (typeof _e == "undefined" || _exception == _ev)
    587       testPassed(_a + " threw exception " + _exception + ".");
     570        testFailed((_message ? _message : _a) + " should not throw exception. Threw exception " + e + ".");
     571    }
     572}
     573
     574function shouldThrow(_a, _e, _message)
     575{
     576    var _exception;
     577    var _av;
     578    try {
     579        _av = typeof _a == "function" ? _a() : eval(_a);
     580    } catch (e) {
     581        _exception = e;
     582    }
     583
     584    var _ev;
     585    if (_e)
     586        _ev = eval(_e);
     587
     588    if (_exception) {
     589        if (typeof _e == "undefined" || _exception == _ev)
     590            testPassed((_message ? _message : _a) + " threw exception " + _exception + ".");
     591        else
     592            testFailed((_message ? _message : _a) + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Threw exception " + _exception + ".");
     593    } else if (typeof _av == "undefined")
     594        testFailed((_message ? _message : _a) + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was undefined.");
    588595    else
    589       testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Threw exception " + _exception + ".");
    590   } else if (typeof _av == "undefined")
    591     testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was undefined.");
    592   else
    593     testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + ".");
     596        testFailed((_message ? _message : _a) + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + ".");
    594597}
    595598
     
    692695    successfullyParsed = !unexpectedErrorMessage;
    693696    shouldBeTrue("successfullyParsed");
     697    if (didFailSomeTests)
     698        debug("Some tests failed.");
    694699    debug('<br /><span class="pass">TEST COMPLETE</span>');
    695700}
  • trunk/LayoutTests/storage/indexeddb/cursor-basics-expected.txt

    r195181 r202609  
    8383PASS 'value' in cursor is false
    8484PASS successfullyParsed is true
     85Some tests failed.
    8586
    8687TEST COMPLETE
  • trunk/LayoutTests/storage/indexeddb/cursor-basics-private-expected.txt

    r195247 r202609  
    8383PASS 'value' in cursor is false
    8484PASS successfullyParsed is true
     85Some tests failed.
    8586
    8687TEST COMPLETE
Note: See TracChangeset for help on using the changeset viewer.