2013-09-07 17:43:03 +00:00
// svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump text + pixel results
if ( self . testRunner )
testRunner . dumpAsText ( self . enablePixelTesting ) ;
var description , debug , successfullyParsed , errorMessage , silentTestPass , didPassSomeTestsSilently , didFailSomeTests ;
silentTestPass = false ;
didPassSomeTestsSilently = false ;
didFailSomeTests = false ;
( function ( ) {
2014-04-02 21:40:26 +00:00
function createHTMLElement ( tagName )
{
// FIXME: In an XML document, document.createElement() creates an element with a null namespace URI.
// So, we need use document.createElementNS() to explicitly create an element with the specified
// tag name in the HTML namespace. We can remove this function and use document.createElement()
// directly once we fix <https://bugs.webkit.org/show_bug.cgi?id=131074>.
if ( document . createElementNS )
return document . createElementNS ( "http://www.w3.org/1999/xhtml" , tagName ) ;
return document . createElement ( tagName ) ;
}
2013-09-07 17:43:03 +00:00
function getOrCreate ( id , tagName )
{
var element = document . getElementById ( id ) ;
if ( element )
return element ;
2014-04-02 21:40:26 +00:00
element = createHTMLElement ( tagName ) ;
2013-09-07 17:43:03 +00:00
element . id = id ;
var refNode ;
var parent = document . body || document . documentElement ;
if ( id == "description" )
refNode = getOrCreate ( "console" , "div" ) ;
else
refNode = parent . firstChild ;
parent . insertBefore ( element , refNode ) ;
return element ;
}
description = function description ( msg , quiet )
{
// For MSIE 6 compatibility
2014-04-02 21:40:26 +00:00
var span = createHTMLElement ( "span" ) ;
2013-09-07 17:43:03 +00:00
if ( quiet )
span . innerHTML = '<p>' + msg + '</p><p>On success, you will see no "<span class="fail">FAIL</span>" messages, followed by "<span class="pass">TEST COMPLETE</span>".</p>' ;
else
span . innerHTML = '<p>' + msg + '</p><p>On success, you will see a series of "<span class="pass">PASS</span>" messages, followed by "<span class="pass">TEST COMPLETE</span>".</p>' ;
var description = getOrCreate ( "description" , "p" ) ;
if ( description . firstChild )
description . replaceChild ( span , description . firstChild ) ;
else
description . appendChild ( span ) ;
} ;
debug = function debug ( msg )
{
2014-04-02 21:40:26 +00:00
var span = createHTMLElement ( "span" ) ;
2013-09-07 17:43:03 +00:00
getOrCreate ( "console" , "div" ) . appendChild ( span ) ; // insert it first so XHTML knows the namespace
span . innerHTML = msg + '<br />' ;
} ;
var css =
".pass {" +
"font-weight: bold;" +
"color: green;" +
"}" +
".fail {" +
"font-weight: bold;" +
"color: red;" +
"}" +
"#console {" +
"white-space: pre-wrap;" +
"font-family: monospace;" +
"}" ;
function insertStyleSheet ( )
{
2014-04-02 21:40:26 +00:00
var styleElement = createHTMLElement ( "style" ) ;
2013-09-07 17:43:03 +00:00
styleElement . textContent = css ;
( document . head || document . documentElement ) . appendChild ( styleElement ) ;
}
if ( ! isWorker ( ) )
insertStyleSheet ( ) ;
self . onerror = function ( message )
{
errorMessage = message ;
} ;
} ) ( ) ;
function isWorker ( )
{
// It's conceivable that someone would stub out 'document' in a worker so
// also check for childNodes, an arbitrary DOM-related object that is
// meaningless in a WorkerContext.
return ( typeof document === 'undefined' || typeof document . childNodes === 'undefined' ) && ! ! self . importScripts ;
}
function descriptionQuiet ( msg ) { description ( msg , true ) ; }
function escapeHTML ( text )
{
return text . replace ( /&/g , "&" ) . replace ( /</g , "<" ) . replace ( /\0/g , "\\0" ) ;
}
2020-07-13 17:35:35 +00:00
function escapeHTMLAndStripFileURLs ( text )
{
return escapeHTML ( text ) . replace ( /file:\/\/.*LayoutTests/g , "file:///LayoutTests" ) ;
}
2013-09-07 17:43:03 +00:00
function testPassed ( msg )
{
if ( silentTestPass )
didPassSomeTestsSilently = true ;
else
2020-07-13 17:35:35 +00:00
debug ( '<span><span class="pass">PASS</span> ' + escapeHTMLAndStripFileURLs ( msg ) + '</span>' ) ;
2013-09-07 17:43:03 +00:00
}
function testFailed ( msg )
{
didFailSomeTests = true ;
2020-07-13 17:35:35 +00:00
debug ( '<span><span class="fail">FAIL</span> ' + escapeHTMLAndStripFileURLs ( msg ) + '</span>' ) ;
2013-09-07 17:43:03 +00:00
}
function areNumbersEqual ( _actual , _expected )
{
if ( _expected === 0 )
return _actual === _expected && ( 1 / _actual ) === ( 1 / _expected ) ;
if ( _actual === _expected )
return true ;
if ( typeof ( _expected ) == "number" && isNaN ( _expected ) )
return typeof ( _actual ) == "number" && isNaN ( _actual ) ;
return false ;
}
function areArraysEqual ( _a , _b )
{
try {
if ( _a . length !== _b . length )
return false ;
for ( var i = 0 ; i < _a . length ; i ++ )
if ( ! areNumbersEqual ( _a [ i ] , _b [ i ] ) )
return false ;
} catch ( ex ) {
return false ;
}
return true ;
}
function isMinusZero ( n )
{
// the only way to tell 0 from -0 in JS is the fact that 1/-0 is
// -Infinity instead of Infinity
return n === 0 && 1 / n < 0 ;
}
function isTypedArray ( array )
{
return array instanceof Int8Array
|| array instanceof Int16Array
|| array instanceof Int32Array
|| array instanceof Uint8Array
|| array instanceof Uint8ClampedArray
|| array instanceof Uint16Array
|| array instanceof Uint32Array
|| array instanceof Float32Array
|| array instanceof Float64Array ;
}
function isResultCorrect ( _actual , _expected )
{
if ( areNumbersEqual ( _actual , _expected ) )
return true ;
if ( _expected
&& ( Object . prototype . toString . call ( _expected ) ==
Object . prototype . toString . call ( [ ] )
|| isTypedArray ( _expected ) ) )
return areArraysEqual ( _actual , _expected ) ;
return false ;
}
function stringify ( v )
{
if ( v === 0 && 1 / v < 0 )
return "-0" ;
else if ( isTypedArray ( v ) )
return v . _ _proto _ _ . constructor . name + ":[" + Array . prototype . join . call ( v , "," ) + "]" ;
else
return "" + v ;
}
function evalAndLog ( _a , _quiet )
{
2017-05-02 20:10:12 +00:00
if ( typeof _a != "string" )
debug ( "WARN: evalAndLog() expects a string argument" ) ;
2013-09-07 17:43:03 +00:00
2017-05-02 20:10:12 +00:00
// Log first in case things go horribly wrong or this causes a sync event.
if ( ! _quiet )
debug ( _a ) ;
2013-09-07 17:43:03 +00:00
2017-05-02 20:10:12 +00:00
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
testFailed ( _a + " threw exception " + e ) ;
}
return _av ;
2013-09-07 17:43:03 +00:00
}
2016-11-01 05:32:35 +00:00
function evalAndLogResult ( _a )
{
2017-05-02 20:10:12 +00:00
if ( typeof _a != "string" )
debug ( "WARN: evalAndLogResult() expects a string argument" ) ;
2016-11-01 05:32:35 +00:00
2017-05-02 20:10:12 +00:00
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
testFailed ( _a + " threw exception " + e ) ;
}
2016-11-01 05:32:35 +00:00
2020-07-13 17:35:35 +00:00
debug ( '<span>' + _a + " is " + escapeHTMLAndStripFileURLs ( _av ) + '</span>' ) ;
2016-11-01 05:32:35 +00:00
}
2017-05-02 20:10:12 +00:00
function shouldBe ( _a , _b , _quiet )
2013-09-07 17:43:03 +00:00
{
2017-05-02 20:10:12 +00:00
if ( ( typeof _a != "function" && typeof _a != "string" ) || ( typeof _b != "function" && typeof _b != "string" ) )
debug ( "WARN: shouldBe() expects function or string arguments" ) ;
var _exception ;
var _av ;
try {
_av = ( typeof _a == "function" ? _a ( ) : eval ( _a ) ) ;
} catch ( e ) {
_exception = e ;
2013-09-07 17:43:03 +00:00
}
2017-05-02 20:10:12 +00:00
var _bv = ( typeof _b == "function" ? _b ( ) : eval ( _b ) ) ;
if ( _exception )
testFailed ( _a + " should be " + stringify ( _bv ) + ". Threw exception " + _exception ) ;
else if ( isResultCorrect ( _av , _bv ) ) {
if ( ! _quiet ) {
testPassed ( _a + " is " + ( typeof _b == "function" ? _bv : _b ) ) ;
}
} else if ( typeof ( _av ) == typeof ( _bv ) )
testFailed ( _a + " should be " + stringify ( _bv ) + ". Was " + stringify ( _av ) + "." ) ;
else
testFailed ( _a + " should be " + stringify ( _bv ) + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ")." ) ;
2013-09-07 17:43:03 +00:00
}
function dfgShouldBe ( theFunction , _a , _b )
{
2017-05-02 20:10:12 +00:00
if ( typeof theFunction != "function" || typeof _a != "string" || typeof _b != "string" )
debug ( "WARN: dfgShouldBe() expects a function and two strings" ) ;
noInline ( theFunction ) ;
var exception ;
var values = [ ] ;
// Defend against tests that muck with numeric properties on array.prototype.
values . _ _proto _ _ = null ;
values . push = Array . prototype . push ;
try {
while ( ! dfgCompiled ( { f : theFunction } ) )
values . push ( eval ( _a ) ) ;
values . push ( eval ( _a ) ) ;
} catch ( e ) {
exception = e ;
}
var _bv = eval ( _b ) ;
if ( exception )
testFailed ( _a + " should be " + stringify ( _bv ) + ". On iteration " + ( values . length + 1 ) + ", threw exception " + exception ) ;
else {
var allPassed = true ;
for ( var i = 0 ; i < values . length ; ++ i ) {
var _av = values [ i ] ;
if ( isResultCorrect ( _av , _bv ) )
continue ;
if ( typeof ( _av ) == typeof ( _bv ) )
testFailed ( _a + " should be " + stringify ( _bv ) + ". On iteration " + ( i + 1 ) + ", was " + stringify ( _av ) + "." ) ;
else
testFailed ( _a + " should be " + stringify ( _bv ) + " (of type " + typeof _bv + "). On iteration " + ( i + 1 ) + ", was " + _av + " (of type " + typeof _av + ")." ) ;
allPassed = false ;
}
if ( allPassed )
testPassed ( _a + " is " + _b + " on all iterations including after DFG tier-up." ) ;
}
return values . length ;
2013-09-07 17:43:03 +00:00
}
2013-09-30 20:47:43 +00:00
// Execute condition every 5 milliseconds until it succeeds.
function _waitForCondition ( condition , completionHandler )
2013-09-07 17:43:03 +00:00
{
2017-05-02 20:10:12 +00:00
if ( condition ( ) )
completionHandler ( ) ;
else
setTimeout ( _waitForCondition , 5 , condition , completionHandler ) ;
2013-09-07 17:43:03 +00:00
}
2013-09-30 20:47:43 +00:00
function shouldBecomeEqual ( _a , _b , completionHandler )
2013-09-07 17:43:03 +00:00
{
2017-05-02 20:10:12 +00:00
if ( typeof _a != "string" || typeof _b != "string" )
debug ( "WARN: shouldBecomeEqual() expects string arguments" ) ;
function condition ( ) {
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
var _bv = eval ( _b ) ;
if ( exception )
testFailed ( _a + " should become " + _bv + ". Threw exception " + exception ) ;
if ( isResultCorrect ( _av , _bv ) ) {
testPassed ( _a + " became " + _b ) ;
return true ;
}
return false ;
2013-09-07 17:43:03 +00:00
}
2021-06-09 22:42:51 +00:00
if ( ! completionHandler )
return new Promise ( resolve => setTimeout ( _waitForCondition , 0 , condition , resolve ) ) ;
2017-05-02 20:10:12 +00:00
setTimeout ( _waitForCondition , 0 , condition , completionHandler ) ;
2013-09-07 17:43:03 +00:00
}
2013-09-30 20:47:43 +00:00
function shouldBecomeEqualToString ( value , reference , completionHandler )
2013-09-07 17:43:03 +00:00
{
2017-05-02 20:10:12 +00:00
if ( typeof value !== "string" || typeof reference !== "string" )
debug ( "WARN: shouldBecomeEqualToString() expects string arguments" ) ;
var unevaledString = JSON . stringify ( reference ) ;
shouldBecomeEqual ( value , unevaledString , completionHandler ) ;
2013-09-07 17:43:03 +00:00
}
function shouldBeType ( _a , _type ) {
2017-05-02 20:10:12 +00:00
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
var _typev = eval ( _type ) ;
if ( _av instanceof _typev ) {
testPassed ( _a + " is an instance of " + _type ) ;
} else {
testFailed ( _a + " is not an instance of " + _type ) ;
}
2013-09-07 17:43:03 +00:00
}
// Variant of shouldBe()--confirms that result of eval(_to_eval) is within
// numeric _tolerance of numeric _target.
function shouldBeCloseTo ( _to _eval , _target , _tolerance , quiet )
{
2017-05-02 20:10:12 +00:00
if ( typeof _to _eval != "string" ) {
testFailed ( "shouldBeCloseTo() requires string argument _to_eval. was type " + typeof _to _eval ) ;
return ;
}
if ( typeof _target != "number" ) {
testFailed ( "shouldBeCloseTo() requires numeric argument _target. was type " + typeof _target ) ;
return ;
}
if ( typeof _tolerance != "number" ) {
testFailed ( "shouldBeCloseTo() requires numeric argument _tolerance. was type " + typeof _tolerance ) ;
return ;
}
var _result ;
try {
_result = eval ( _to _eval ) ;
} catch ( e ) {
testFailed ( _to _eval + " should be within " + _tolerance + " of "
+ _target + ". Threw exception " + e ) ;
return ;
}
if ( typeof ( _result ) != typeof ( _target ) ) {
testFailed ( _to _eval + " should be of type " + typeof _target
+ " but was of type " + typeof _result ) ;
} else if ( Math . abs ( _result - _target ) <= _tolerance ) {
if ( ! quiet ) {
testPassed ( _to _eval + " is within " + _tolerance + " of " + _target ) ;
}
} else {
testFailed ( _to _eval + " should be within " + _tolerance + " of " + _target
+ ". Was " + _result + "." ) ;
}
2013-09-07 17:43:03 +00:00
}
2017-05-02 20:10:12 +00:00
function shouldNotBe ( _a , _b , _quiet )
2013-09-07 17:43:03 +00:00
{
2017-05-02 20:10:12 +00:00
if ( ( typeof _a != "function" && typeof _a != "string" ) || ( typeof _b != "function" && typeof _b != "string" ) )
debug ( "WARN: shouldNotBe() expects function or string arguments" ) ;
var _exception ;
2013-09-07 17:43:03 +00:00
var _av ;
try {
2017-05-02 20:10:12 +00:00
_av = ( typeof _a == "function" ? _a ( ) : eval ( _a ) ) ;
2013-09-07 17:43:03 +00:00
} catch ( e ) {
2017-05-02 20:10:12 +00:00
_exception = e ;
2013-09-07 17:43:03 +00:00
}
2017-05-02 20:10:12 +00:00
var _bv = ( typeof _b == "function" ? _b ( ) : eval ( _b ) ) ;
if ( _exception )
testFailed ( _a + " should not be " + _bv + ". Threw exception " + _exception ) ;
else if ( ! isResultCorrect ( _av , _bv ) ) {
if ( ! _quiet ) {
testPassed ( _a + " is not " + ( typeof _b == "function" ? _bv : _b ) ) ;
}
} else
testFailed ( _a + " should not be " + _bv + "." ) ;
}
function shouldBecomeDifferent ( _a , _b , completionHandler )
{
if ( typeof _a != "string" || typeof _b != "string" )
debug ( "WARN: shouldBecomeDifferent() expects string arguments" ) ;
function condition ( ) {
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
var _bv = eval ( _b ) ;
if ( exception )
testFailed ( _a + " should became not equal to " + _bv + ". Threw exception " + exception ) ;
if ( ! isResultCorrect ( _av , _bv ) ) {
testPassed ( _a + " became different from " + _b ) ;
return true ;
}
return false ;
2013-09-07 17:43:03 +00:00
}
2021-06-09 22:42:51 +00:00
if ( ! completionHandler )
return new Promise ( resolve => setTimeout ( _waitForCondition , 0 , condition , resolve ) ) ;
2017-05-02 20:10:12 +00:00
setTimeout ( _waitForCondition , 0 , condition , completionHandler ) ;
2013-09-07 17:43:03 +00:00
}
function shouldBeTrue ( _a ) { shouldBe ( _a , "true" ) ; }
function shouldBeTrueQuiet ( _a ) { shouldBe ( _a , "true" , true ) ; }
function shouldBeFalse ( _a ) { shouldBe ( _a , "false" ) ; }
function shouldBeNaN ( _a ) { shouldBe ( _a , "NaN" ) ; }
function shouldBeNull ( _a ) { shouldBe ( _a , "null" ) ; }
function shouldBeZero ( _a ) { shouldBe ( _a , "0" ) ; }
function shouldBeEqualToString ( a , b )
{
2017-05-02 20:10:12 +00:00
if ( typeof a !== "string" || typeof b !== "string" )
debug ( "WARN: shouldBeEqualToString() expects string arguments" ) ;
var unevaledString = JSON . stringify ( b ) ;
shouldBe ( a , unevaledString ) ;
2013-09-07 17:43:03 +00:00
}
2013-09-12 16:44:22 +00:00
function shouldNotBeEqualToString ( a , b )
{
2017-05-02 20:10:12 +00:00
if ( typeof a !== "string" || typeof b !== "string" )
debug ( "WARN: shouldBeEqualToString() expects string arguments" ) ;
var unevaledString = JSON . stringify ( b ) ;
shouldNotBe ( a , unevaledString ) ;
2013-09-12 16:44:22 +00:00
}
2013-09-07 17:43:03 +00:00
function shouldBeEmptyString ( _a ) { shouldBeEqualToString ( _a , "" ) ; }
2016-11-01 05:32:35 +00:00
function shouldEvaluateTo ( actual , expected )
{
2017-05-02 20:10:12 +00:00
// A general-purpose comparator. 'actual' should be a string to be
// evaluated, as for shouldBe(). 'expected' may be any type and will be
// used without being eval'ed.
if ( expected == null ) {
// Do this before the object test, since null is of type 'object'.
shouldBeNull ( actual ) ;
} else if ( typeof expected == "undefined" ) {
shouldBeUndefined ( actual ) ;
} else if ( typeof expected == "function" ) {
// All this fuss is to avoid the string-arg warning from shouldBe().
try {
actualValue = eval ( actual ) ;
} catch ( e ) {
testFailed ( "Evaluating " + actual + ": Threw exception " + e ) ;
return ;
}
shouldBe ( "'" + actualValue . toString ( ) . replace ( /\n/g , "" ) + "'" ,
"'" + expected . toString ( ) . replace ( /\n/g , "" ) + "'" ) ;
} else if ( typeof expected == "object" ) {
shouldBeTrue ( actual + " == '" + expected + "'" ) ;
} else if ( typeof expected == "string" ) {
shouldBe ( actual , expected ) ;
} else if ( typeof expected == "boolean" ) {
shouldBe ( "typeof " + actual , "'boolean'" ) ;
if ( expected )
shouldBeTrue ( actual ) ;
else
shouldBeFalse ( actual ) ;
} else if ( typeof expected == "number" ) {
shouldBe ( actual , stringify ( expected ) ) ;
} else {
debug ( expected + " is unknown type " + typeof expected ) ;
shouldBeTrue ( actual , "'" + expected . toString ( ) + "'" ) ;
}
2013-09-07 17:43:03 +00:00
}
function shouldBeNonZero ( _a )
{
2017-05-02 20:10:12 +00:00
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
2013-09-07 17:43:03 +00:00
2017-05-02 20:10:12 +00:00
if ( exception )
testFailed ( _a + " should be non-zero. Threw exception " + exception ) ;
else if ( _av != 0 )
testPassed ( _a + " is non-zero." ) ;
else
testFailed ( _a + " should be non-zero. Was " + _av ) ;
2013-09-07 17:43:03 +00:00
}
function shouldBeNonNull ( _a )
{
2017-05-02 20:10:12 +00:00
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
2013-09-07 17:43:03 +00:00
2017-05-02 20:10:12 +00:00
if ( exception )
testFailed ( _a + " should be non-null. Threw exception " + exception ) ;
else if ( _av != null )
testPassed ( _a + " is non-null." ) ;
else
testFailed ( _a + " should be non-null. Was " + _av ) ;
2013-09-07 17:43:03 +00:00
}
function shouldBeUndefined ( _a )
{
2017-05-02 20:10:12 +00:00
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
2013-09-07 17:43:03 +00:00
2017-05-02 20:10:12 +00:00
if ( exception )
testFailed ( _a + " should be undefined. Threw exception " + exception ) ;
else if ( typeof _av == "undefined" )
testPassed ( _a + " is undefined." ) ;
else
testFailed ( _a + " should be undefined. Was " + _av ) ;
2013-09-07 17:43:03 +00:00
}
function shouldBeDefined ( _a )
{
2017-05-02 20:10:12 +00:00
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
2013-09-07 17:43:03 +00:00
2017-05-02 20:10:12 +00:00
if ( exception )
testFailed ( _a + " should be defined. Threw exception " + exception ) ;
else if ( _av !== undefined )
testPassed ( _a + " is defined." ) ;
else
testFailed ( _a + " should be defined. Was " + _av ) ;
2013-09-07 17:43:03 +00:00
}
function shouldBeGreaterThanOrEqual ( _a , _b ) {
if ( typeof _a != "string" || typeof _b != "string" )
debug ( "WARN: shouldBeGreaterThanOrEqual expects string arguments" ) ;
var exception ;
var _av ;
try {
_av = eval ( _a ) ;
} catch ( e ) {
exception = e ;
}
var _bv = eval ( _b ) ;
if ( exception )
testFailed ( _a + " should be >= " + _b + ". Threw exception " + exception ) ;
else if ( typeof _av == "undefined" || _av < _bv )
testFailed ( _a + " should be >= " + _b + ". Was " + _av + " (of type " + typeof _av + ")." ) ;
else
testPassed ( _a + " is >= " + _b ) ;
}
2014-01-12 03:53:39 +00:00
function expectTrue ( v , msg ) {
2017-05-02 20:10:12 +00:00
if ( v ) {
testPassed ( msg ) ;
} else {
testFailed ( msg ) ;
}
2014-01-12 03:53:39 +00:00
}
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
function shouldNotThrow ( _a , _message ) {
2013-09-07 17:43:03 +00:00
try {
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
typeof _a == "function" ? _a ( ) : eval ( _a ) ;
testPassed ( ( _message ? _message : _a ) + " did not throw exception." ) ;
2013-09-07 17:43:03 +00:00
} catch ( e ) {
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
testFailed ( ( _message ? _message : _a ) + " should not throw exception. Threw exception " + e + "." ) ;
2013-09-07 17:43:03 +00:00
}
}
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
function shouldThrow ( _a , _e , _message )
2013-09-07 17:43:03 +00:00
{
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
var _exception ;
var _av ;
try {
_av = typeof _a == "function" ? _a ( ) : eval ( _a ) ;
} catch ( e ) {
_exception = e ;
}
2013-09-07 17:43:03 +00:00
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
var _ev ;
if ( _e )
_ev = eval ( _e ) ;
2013-09-07 17:43:03 +00:00
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
if ( _exception ) {
if ( typeof _e == "undefined" || _exception == _ev )
testPassed ( ( _message ? _message : _a ) + " threw exception " + _exception + "." ) ;
else
testFailed ( ( _message ? _message : _a ) + " should throw " + ( typeof _e == "undefined" ? "an exception" : _ev ) + ". Threw exception " + _exception + "." ) ;
} else if ( typeof _av == "undefined" )
testFailed ( ( _message ? _message : _a ) + " should throw " + ( typeof _e == "undefined" ? "an exception" : _ev ) + ". Was undefined." ) ;
2013-09-07 17:43:03 +00:00
else
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.
Canonical link: https://commits.webkit.org/177356@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-06-29 04:17:36 +00:00
testFailed ( ( _message ? _message : _a ) + " should throw " + ( typeof _e == "undefined" ? "an exception" : _ev ) + ". Was " + _av + "." ) ;
2013-09-07 17:43:03 +00:00
}
2016-11-15 22:50:35 +00:00
function shouldReject ( _a , _message )
2016-10-25 06:07:04 +00:00
{
var _exception ;
var _av ;
try {
_av = typeof _a == "function" ? _a ( ) : eval ( _a ) ;
} catch ( e ) {
testFailed ( ( _message ? _message : _a ) + " should not throw exception. Threw exception " + e + "." ) ;
return Promise . resolve ( ) ;
}
2017-05-02 20:10:12 +00:00
return _av . then ( function ( result ) {
2016-10-25 06:07:04 +00:00
testFailed ( ( _message ? _message : _a ) + " should reject promise. Resolved with " + result + "." ) ;
} , function ( error ) {
testPassed ( ( _message ? _message : _a ) + " rejected promise with " + error + "." ) ;
} ) ;
}
2016-07-31 00:29:19 +00:00
function shouldThrowErrorName ( _a , _name )
{
var _exception ;
try {
typeof _a == "function" ? _a ( ) : eval ( _a ) ;
} catch ( e ) {
_exception = e ;
}
if ( _exception ) {
if ( _exception . name == _name )
testPassed ( _a + " threw exception " + _exception + "." ) ;
else
testFailed ( _a + " should throw a " + _name + ". Threw a " + _exception . name + "." ) ;
} else
testFailed ( _a + " should throw a " + _name + ". Did not throw." ) ;
}
2013-09-07 17:43:03 +00:00
function shouldHaveHadError ( message )
{
if ( errorMessage ) {
if ( ! message )
testPassed ( "Got expected error" ) ;
else if ( errorMessage . indexOf ( message ) !== - 1 )
testPassed ( "Got expected error: '" + message + "'" ) ;
else
testFailed ( "Unexpexted error '" + message + "'" ) ;
} else
testFailed ( "Missing expexted error" ) ;
errorMessage = undefined ;
}
function gc ( ) {
if ( typeof GCController !== "undefined" )
GCController . collect ( ) ;
else {
var gcRec = function ( n ) {
if ( n < 1 )
return { } ;
var temp = { i : "ab" + i + ( i / 100000 ) } ;
temp += "foo" ;
gcRec ( n - 1 ) ;
} ;
for ( var i = 0 ; i < 1000 ; i ++ )
gcRec ( 10 )
}
}
function dfgCompiled ( argument )
{
var numberOfCompiles = "compiles" in argument ? argument . compiles : 1 ;
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
if ( ! ( "f" in argument ) )
throw new Error ( "dfgCompiled called with invalid argument." ) ;
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
if ( argument . f instanceof Array ) {
for ( var i = 0 ; i < argument . f . length ; ++ i ) {
if ( testRunner . numberOfDFGCompiles ( argument . f [ i ] ) < numberOfCompiles )
return false ;
}
} else {
if ( testRunner . numberOfDFGCompiles ( argument . f ) < numberOfCompiles )
return false ;
}
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
return true ;
}
function dfgIncrement ( argument )
{
if ( ! self . testRunner )
return argument . i ;
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
if ( argument . i < argument . n )
return argument . i ;
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
if ( didFailSomeTests )
return argument . i ;
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
if ( ! dfgCompiled ( argument ) )
return "start" in argument ? argument . start : 0 ;
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
return argument . i ;
}
function noInline ( theFunction )
{
if ( ! self . testRunner )
return ;
2017-05-02 20:10:12 +00:00
2013-09-07 17:43:03 +00:00
testRunner . neverInlineFunction ( theFunction ) ;
}
function isSuccessfullyParsed ( )
{
// FIXME: Remove this and only report unexpected syntax errors.
if ( ! errorMessage )
successfullyParsed = true ;
shouldBeTrue ( "successfullyParsed" ) ;
if ( silentTestPass && didPassSomeTestsSilently )
debug ( "Passed some tests silently." ) ;
if ( silentTestPass && didFailSomeTests )
debug ( "Some tests failed." ) ;
debug ( '<br /><span class="pass">TEST COMPLETE</span>' ) ;
}
2019-06-18 21:02:19 +00:00
function asyncTestStart ( ) {
if ( self . testRunner )
testRunner . waitUntilDone ( ) ;
}
function asyncTestPassed ( ) {
if ( self . testRunner )
testRunner . notifyDone ( ) ;
}
2013-09-07 17:43:03 +00:00
// It's possible for an async test to call finishJSTest() before js-test-post.js
// has been parsed.
function finishJSTest ( )
{
wasFinishJSTestCalled = true ;
if ( ! self . wasPostTestScriptParsed )
return ;
isSuccessfullyParsed ( ) ;
if ( self . jsTestIsAsync && self . testRunner )
testRunner . notifyDone ( ) ;
}
2015-01-13 00:40:49 +00:00
function startWorker ( testScriptURL )
2013-09-07 17:43:03 +00:00
{
self . jsTestIsAsync = true ;
debug ( 'Starting worker: ' + testScriptURL ) ;
2015-01-13 00:40:49 +00:00
var worker = new Worker ( testScriptURL ) ;
2013-09-07 17:43:03 +00:00
worker . onmessage = function ( event )
{
var workerPrefix = "[Worker] " ;
if ( event . data . length < 5 || event . data . charAt ( 4 ) != ':' ) {
2017-05-02 20:10:12 +00:00
debug ( workerPrefix + event . data ) ;
return ;
2013-09-07 17:43:03 +00:00
}
var code = event . data . substring ( 0 , 4 ) ;
var payload = workerPrefix + event . data . substring ( 5 ) ;
if ( code == "PASS" )
testPassed ( payload ) ;
else if ( code == "FAIL" )
testFailed ( payload ) ;
else if ( code == "DESC" )
description ( payload ) ;
else if ( code == "DONE" )
finishJSTest ( ) ;
else
debug ( workerPrefix + event . data ) ;
} ;
worker . onerror = function ( event )
{
debug ( 'Got error from worker: ' + event . message ) ;
finishJSTest ( ) ;
}
return worker ;
}
if ( isWorker ( ) ) {
var workerPort = self ;
description = function ( msg , quiet ) {
workerPort . postMessage ( 'DESC:' + msg ) ;
}
testFailed = function ( msg ) {
workerPort . postMessage ( 'FAIL:' + msg ) ;
}
testPassed = function ( msg ) {
workerPort . postMessage ( 'PASS:' + msg ) ;
}
finishJSTest = function ( ) {
workerPort . postMessage ( 'DONE:' ) ;
}
debug = function ( msg ) {
workerPort . postMessage ( msg ) ;
}
}