Enhance shouldNotThrow()/shouldThrow() to accept functions and a descriptive message
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Jun 2016 04:17:36 +0000 (04:17 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Jun 2016 04:17:36 +0000 (04:17 +0000)
commit769ccc08cdcf7e04360ebb32c090bd0e8406f07e
treea11012d53ee2137408f542b69424e6a5f8181b0f
parent2dfbcef1310cd58110f860ac0d907f5acdf49428
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
23 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/canvas-supports-context-expected.txt
LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt
LayoutTests/fast/css-grid-layout/grid-element-auto-repeat-get-set-expected.txt
LayoutTests/fast/css/parsing-css-lang.html
LayoutTests/fast/css/parsing-css-matches-1.html
LayoutTests/fast/css/parsing-css-matches-2.html
LayoutTests/fast/css/parsing-css-matches-3.html
LayoutTests/fast/css/parsing-css-matches-4.html
LayoutTests/fast/css/parsing-css-not-1.html
LayoutTests/fast/css/parsing-css-not-2.html
LayoutTests/fast/css/parsing-css-not-3.html
LayoutTests/fast/css/parsing-css-not-4.html
LayoutTests/fast/css/parsing-css-nth-child-of-1.html
LayoutTests/fast/css/parsing-css-nth-child-of-2.html
LayoutTests/fast/css/parsing-css-nth-last-child-of-1.html
LayoutTests/fast/css/parsing-css-nth-last-child-of-2.html
LayoutTests/fast/dom/getElementsByClassName/ASCII-case-insensitive-expected.txt
LayoutTests/js/script-tests/arrowfunction-supercall.js
LayoutTests/resources/js-test-pre.js
LayoutTests/resources/js-test.js
LayoutTests/storage/indexeddb/cursor-basics-expected.txt
LayoutTests/storage/indexeddb/cursor-basics-private-expected.txt