<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206237] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206237">206237</a></dd>
<dt>Author</dt> <dd>mattbaker@apple.com</dd>
<dt>Date</dt> <dd>2016-09-21 14:40:22 -0700 (Wed, 21 Sep 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: Improve output of TestHarness.expect* failures
https://bugs.webkit.org/show_bug.cgi?id=162177
<rdar://problem/28367186>
Reviewed by Joseph Pecoraro.
Source/WebInspectorUI:
This patch adds specific expectation functions to TestHarness, to better
express intent when writing tests, and to allow more details to be logged
in the event of a failure.
For functions taking both `actual` and `expected` parameters, the `actual`
parameter comes first. This convention simplifies the implementation of
TestHarness, improves the readability of tests involving inequalities,
and is consistent with XCTest assertions.
* UserInterface/Test/TestHarness.js:
(TestHarness):
(TestHarness.prototype.expectThat):
(TestHarness.prototype.expectFalse):
(TestHarness.prototype.expectNull):
(TestHarness.prototype.expectNotNull):
(TestHarness.prototype.expectEqual):
(TestHarness.prototype.expectNotEqual):
(TestHarness.prototype.expectShallowEqual):
(TestHarness.prototype.expectNotShallowEqual):
(TestHarness.prototype.expectEqualWithAccuracy):
(TestHarness.prototype.expectLessThan):
(TestHarness.prototype.expectLessThanOrEqual):
(TestHarness.prototype.expectGreaterThan):
(TestHarness.prototype.expectGreaterThanOrEqual):
New expectation functions, all of which call _expect under the hood.
(TestHarness.prototype._expect):
Helper method which calls pass or fail. Creates a message when no user
message is provided, and logs expected and actual values in the event
of a failure.
(TestHarness.prototype._expectationValueAsString):
(TestHarness.prototype._expectationMessageFormat):
Get a message format string for the expectation type. Used to create
pass/fail message when no user message is provided.
(TestHarness.prototype._expectedValueFormat):
Get a format string for displaying the expected value. Used to create
the "Expected: " failure message line.
LayoutTests:
Extend coverage to more TestHarness messages by omitting the optional
`message` parameter when calling expect* functions.
Other improvements:
- expectEqual/expectNotEqual should test WebInspector object instances,
to cover more TestHarness message formatting cases.
- expectEqual/expectNotEqual should test shallow equal arrays, since the
test is for strict equality.
* inspector/indexeddb/requestData-expected.txt:
* inspector/unit-tests/number-utilities-expected.txt:
Updated expectations for new TestHarness output.
* inspector/unit-tests/test-harness-expect-functions-expected.txt:
* inspector/unit-tests/test-harness-expect-functions.html:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectorindexeddbrequestDataexpectedtxt">trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorunittestsnumberutilitiesexpectedtxt">trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorunitteststestharnessexpectfunctionsexpectedtxt">trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorunitteststestharnessexpectfunctionshtml">trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceTestTestHarnessjs">trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/ChangeLog        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-09-21 Matt Baker <mattbaker@apple.com>
+
+ Web Inspector: Improve output of TestHarness.expect* failures
+ https://bugs.webkit.org/show_bug.cgi?id=162177
+ <rdar://problem/28367186>
+
+ Reviewed by Joseph Pecoraro.
+
+ Extend coverage to more TestHarness messages by omitting the optional
+ `message` parameter when calling expect* functions.
+
+ Other improvements:
+ - expectEqual/expectNotEqual should test WebInspector object instances,
+ to cover more TestHarness message formatting cases.
+ - expectEqual/expectNotEqual should test shallow equal arrays, since the
+ test is for strict equality.
+
+ * inspector/indexeddb/requestData-expected.txt:
+ * inspector/unit-tests/number-utilities-expected.txt:
+ Updated expectations for new TestHarness output.
+
+ * inspector/unit-tests/test-harness-expect-functions-expected.txt:
+ * inspector/unit-tests/test-harness-expect-functions.html:
+
</ins><span class="cx"> 2016-09-21 Ryan Haddad <ryanhaddad@apple.com>
</span><span class="cx">
</span><span class="cx"> Marking inspector/css/manager-preferredInspectorStyleSheetForFrame.html as flaky on mac.
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorindexeddbrequestDataexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/indexeddb/requestData-expected.txt        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -41,9 +41,13 @@
</span><span class="cx"> PASS: Key should be ordered by email: 'beaver@webkit.org'
</span><span class="cx"> PASS: Value should be a remote object for: 'Monstrous Beaver'
</span><span class="cx"> FAIL: Primary key should be ordered by email: 2
</span><ins>+ Expected: truthy
+ Actual: false
</ins><span class="cx"> PASS: Key should be ordered by email: 'hampster@webkit.org'
</span><span class="cx"> PASS: Value should be a remote object for: 'Thirsty Hampster'
</span><span class="cx"> FAIL: Primary key should be ordered by email: 1
</span><ins>+ Expected: truthy
+ Actual: false
</ins><span class="cx"> PASS: Key should be ordered by email: 'peacock@webkit.org'
</span><span class="cx"> PASS: Value should be a remote object for: 'Jamming Peacock'
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunittestsnumberutilitiesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -12,6 +12,8 @@
</span><span class="cx"> PASS: constrain of a value above max becomes max
</span><span class="cx"> PASS: constrain of a value above max becomes max
</span><span class="cx"> FAIL: constrain of NaN becomes min
</span><ins>+ Expected: truthy
+ Actual: false
</ins><span class="cx">
</span><span class="cx"> -- Running test case: Number.secondsToString
</span><span class="cx"> PASS: normal resolution of 0ms should be ms with no decimals
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunitteststestharnessexpectfunctionsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -11,11 +11,23 @@
</span><span class="cx"> PASS: expectThat([])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectThat(false)
</span><ins>+ Expected: truthy
+ Actual: false
</ins><span class="cx"> FAIL: expectThat(0)
</span><ins>+ Expected: truthy
+ Actual: 0
</ins><span class="cx"> FAIL: expectThat("")
</span><ins>+ Expected: truthy
+ Actual: ""
</ins><span class="cx"> FAIL: expectThat(null)
</span><ins>+ Expected: truthy
+ Actual: null
</ins><span class="cx"> FAIL: expectThat(undefined)
</span><ins>+ Expected: truthy
+ Actual: undefined
</ins><span class="cx"> FAIL: expectThat(NaN)
</span><ins>+ Expected: truthy
+ Actual: NaN
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectFalse
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -27,10 +39,20 @@
</span><span class="cx"> PASS: expectFalse(NaN)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectFalse(true)
</span><ins>+ Expected: falsey
+ Actual: true
</ins><span class="cx"> FAIL: expectFalse(1)
</span><ins>+ Expected: falsey
+ Actual: 1
</ins><span class="cx"> FAIL: expectFalse("abc")
</span><ins>+ Expected: falsey
+ Actual: "abc"
</ins><span class="cx"> FAIL: expectFalse({})
</span><ins>+ Expected: falsey
+ Actual: {}
</ins><span class="cx"> FAIL: expectFalse([])
</span><ins>+ Expected: falsey
+ Actual: []
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectNull
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -37,12 +59,26 @@
</span><span class="cx"> PASS: expectNull(null)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNull(true)
</span><ins>+ Expected: null
+ Actual: true
</ins><span class="cx"> FAIL: expectNull(false)
</span><ins>+ Expected: null
+ Actual: false
</ins><span class="cx"> FAIL: expectNull(1)
</span><ins>+ Expected: null
+ Actual: 1
</ins><span class="cx"> FAIL: expectNull("")
</span><ins>+ Expected: null
+ Actual: ""
</ins><span class="cx"> FAIL: expectNull(undefined)
</span><ins>+ Expected: null
+ Actual: undefined
</ins><span class="cx"> FAIL: expectNull({})
</span><ins>+ Expected: null
+ Actual: {}
</ins><span class="cx"> FAIL: expectNull([])
</span><ins>+ Expected: null
+ Actual: []
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectNotNull
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -55,11 +91,14 @@
</span><span class="cx"> PASS: expectNotNull([])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNotNull(null)
</span><ins>+ Expected: not null
+ Actual: null
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectEqual
</span><span class="cx"> Expected to PASS
</span><span class="cx"> PASS: expectEqual(true, true)
</span><span class="cx"> PASS: expectEqual({"a":1,"b":2}, {"a":1,"b":2})
</span><ins>+PASS: expectEqual(CSSStyleDeclaration instance #1, CSSStyleDeclaration instance #1)
</ins><span class="cx"> PASS: expectEqual(1.23, 1.23)
</span><span class="cx"> PASS: expectEqual("abc", "abc")
</span><span class="cx"> PASS: expectEqual(null, null)
</span><span class="lines">@@ -66,18 +105,38 @@
</span><span class="cx"> PASS: expectEqual(undefined, undefined)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectEqual(true, false)
</span><del>-FAIL: expectEqual({"a":1,"b":2}, {"c":3,"d":4})
</del><ins>+ Expected: false
+ Actual: true
+FAIL: expectEqual({"a":1,"b":2}, {"a":1,"b":2})
+ Expected: {"a":1,"b":2}
+ Actual: {"a":1,"b":2}
+FAIL: expectEqual(CSSStyleDeclaration instance #1, CSSRule instance #2)
+ Expected: CSSRule instance #2
+ Actual: CSSStyleDeclaration instance #1
</ins><span class="cx"> FAIL: expectEqual(1.23, 4.56)
</span><ins>+ Expected: 4.56
+ Actual: 1.23
</ins><span class="cx"> FAIL: expectEqual("abc", "def")
</span><ins>+ Expected: "def"
+ Actual: "abc"
</ins><span class="cx"> FAIL: expectEqual(null, undefined)
</span><ins>+ Expected: undefined
+ Actual: null
</ins><span class="cx"> FAIL: expectEqual(NaN, NaN)
</span><ins>+ Expected: NaN
+ Actual: NaN
</ins><span class="cx"> FAIL: expectEqual({}, {})
</span><ins>+ Expected: {}
+ Actual: {}
</ins><span class="cx"> FAIL: expectEqual([], [])
</span><ins>+ Expected: []
+ Actual: []
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectNotEqual
</span><span class="cx"> Expected to PASS
</span><span class="cx"> PASS: expectNotEqual(true, false)
</span><del>-PASS: expectNotEqual({"a":1,"b":2}, {"c":3,"d":4})
</del><ins>+PASS: expectNotEqual({"a":1,"b":2}, {"a":1,"b":2})
+PASS: expectNotEqual(CSSStyleDeclaration instance #1, CSSRule instance #2)
</ins><span class="cx"> PASS: expectNotEqual(1.23, 4.56)
</span><span class="cx"> PASS: expectNotEqual("abc", "def")
</span><span class="cx"> PASS: expectNotEqual(null, undefined)
</span><span class="lines">@@ -86,11 +145,26 @@
</span><span class="cx"> PASS: expectNotEqual([], [])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNotEqual(true, true)
</span><ins>+ Expected: not true
+ Actual: true
</ins><span class="cx"> FAIL: expectNotEqual({"a":1,"b":2}, {"a":1,"b":2})
</span><ins>+ Expected: not {"a":1,"b":2}
+ Actual: {"a":1,"b":2}
+FAIL: expectNotEqual(CSSStyleDeclaration instance #1, CSSStyleDeclaration instance #1)
+ Expected: not CSSStyleDeclaration instance #1
+ Actual: CSSStyleDeclaration instance #1
</ins><span class="cx"> FAIL: expectNotEqual(1.23, 1.23)
</span><ins>+ Expected: not 1.23
+ Actual: 1.23
</ins><span class="cx"> FAIL: expectNotEqual("abc", "abc")
</span><ins>+ Expected: not "abc"
+ Actual: "abc"
</ins><span class="cx"> FAIL: expectNotEqual(null, null)
</span><ins>+ Expected: not null
+ Actual: null
</ins><span class="cx"> FAIL: expectNotEqual(undefined, undefined)
</span><ins>+ Expected: not undefined
+ Actual: undefined
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectShallowEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -99,7 +173,11 @@
</span><span class="cx"> PASS: expectShallowEqual([], [])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectShallowEqual({"a":1,"b":2}, {"a":3,"b":4})
</span><ins>+ Expected: {"a":3,"b":4}
+ Actual: {"a":1,"b":2}
</ins><span class="cx"> FAIL: expectShallowEqual({}, [])
</span><ins>+ Expected: []
+ Actual: {}
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectNotShallowEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -107,8 +185,14 @@
</span><span class="cx"> PASS: expectNotShallowEqual({}, [])
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectNotShallowEqual({"a":1,"b":2}, {"a":1,"b":2})
</span><ins>+ Expected: not {"a":1,"b":2}
+ Actual: {"a":1,"b":2}
</ins><span class="cx"> FAIL: expectNotShallowEqual({}, {})
</span><ins>+ Expected: not {}
+ Actual: {}
</ins><span class="cx"> FAIL: expectNotShallowEqual([], [])
</span><ins>+ Expected: not []
+ Actual: []
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectEqualWithAccuracy
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -118,7 +202,11 @@
</span><span class="cx"> PASS: expectEqualWithAccuracy(1, 0, 1)
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectEqualWithAccuracy(0, 2, 1)
</span><ins>+ Expected: 2 +/- 1
+ Actual: 0
</ins><span class="cx"> FAIL: expectEqualWithAccuracy(2, 0, 1)
</span><ins>+ Expected: 0 +/- 1
+ Actual: 2
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectLessThan
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -126,9 +214,17 @@
</span><span class="cx"> PASS: expectLessThan("abc", "def")
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectLessThan(0, 0)
</span><ins>+ Expected: less than 0
+ Actual: 0
</ins><span class="cx"> FAIL: expectLessThan(1, 0)
</span><ins>+ Expected: less than 0
+ Actual: 1
</ins><span class="cx"> FAIL: expectLessThan("abc", "abc")
</span><ins>+ Expected: less than "abc"
+ Actual: "abc"
</ins><span class="cx"> FAIL: expectLessThan("def", "abc")
</span><ins>+ Expected: less than "abc"
+ Actual: "def"
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectLessThanOrEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -138,7 +234,11 @@
</span><span class="cx"> PASS: expectLessThanOrEqual("abc", "abc")
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectLessThanOrEqual(1, 0)
</span><ins>+ Expected: less than or equal to 0
+ Actual: 1
</ins><span class="cx"> FAIL: expectLessThanOrEqual("def", "abc")
</span><ins>+ Expected: less than or equal to "abc"
+ Actual: "def"
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectGreaterThan
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -146,9 +246,17 @@
</span><span class="cx"> PASS: expectGreaterThan("def", "abc")
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectGreaterThan(0, 0)
</span><ins>+ Expected: greater than 0
+ Actual: 0
</ins><span class="cx"> FAIL: expectGreaterThan(0, 1)
</span><ins>+ Expected: greater than 1
+ Actual: 0
</ins><span class="cx"> FAIL: expectGreaterThan("abc", "abc")
</span><ins>+ Expected: greater than "abc"
+ Actual: "abc"
</ins><span class="cx"> FAIL: expectGreaterThan("abc", "def")
</span><ins>+ Expected: greater than "def"
+ Actual: "abc"
</ins><span class="cx">
</span><span class="cx"> -- Running test case: InspectorTest.expectGreaterThanOrEqual
</span><span class="cx"> Expected to PASS
</span><span class="lines">@@ -158,5 +266,9 @@
</span><span class="cx"> PASS: expectGreaterThanOrEqual("abc", "abc")
</span><span class="cx"> Expected to FAIL
</span><span class="cx"> FAIL: expectGreaterThanOrEqual(0, 1)
</span><ins>+ Expected: greater than or equal to 1
+ Actual: 0
</ins><span class="cx"> FAIL: expectGreaterThanOrEqual("abc", "def")
</span><ins>+ Expected: greater than or equal to "def"
+ Actual: "abc"
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunitteststestharnessexpectfunctionshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/LayoutTests/inspector/unit-tests/test-harness-expect-functions.html        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -5,8 +5,6 @@
</span><span class="cx"> <script>
</span><span class="cx"> function test()
</span><span class="cx"> {
</span><del>- console.assert(false, "FAIL ASSERTION!!!!!!!");
-
</del><span class="cx"> let suite = InspectorTest.createSyncSuite("InspectorTestExpectFunctions");
</span><span class="cx">
</span><span class="cx"> function toArray(a) {
</span><span class="lines">@@ -13,15 +11,6 @@
</span><span class="cx"> return a instanceof Array && a.length ? a : [a];
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function stringifyArguments(args) {
- return args.map((a) => {
- if (typeof a === "number")
- return a;
- // Append empty string so `undefined` is displayed correctly.
- return JSON.stringify(a) + "";
- }).join(", ");
- }
-
</del><span class="cx"> function addTestCase({functionName, passingInputs, failingInputs}) {
</span><span class="cx"> let functionUnderTest = InspectorTest[functionName];
</span><span class="cx"> InspectorTest.assert(typeof functionUnderTest === "function", "Unknown InspectorTest function: " + functionName);
</span><span class="lines">@@ -36,10 +25,8 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> InspectorTest.log("Expected to " + (shouldPass ? "PASS" : "FAIL"));
</span><del>- for (let input of inputs.map(toArray)) {
- let argumentsString = stringifyArguments(input);
- functionUnderTest.call(InspectorTest, ...input, `${functionName}(${argumentsString})`);
- }
</del><ins>+ for (let input of inputs.map(toArray))
+ functionUnderTest.call(InspectorTest, ...input);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> exerciseFunction(passingInputs, true);
</span><span class="lines">@@ -70,12 +57,15 @@
</span><span class="cx"> addInverseTestCase("expectNotNull", expectNullTestCase);
</span><span class="cx">
</span><span class="cx"> let object1 = {a: 1, b: 2};
</span><del>- let object2 = {c: 3, d: 4};
</del><ins>+ let object2 = {a: 1, b: 2};
+ let customObject1 = new WebInspector.CSSStyleDeclaration;
+ let customObject2 = new WebInspector.CSSRule;
</ins><span class="cx"> let expectEqualTestCase = {
</span><span class="cx"> functionName: "expectEqual",
</span><span class="cx"> passingInputs: [
</span><span class="cx"> [true, true],
</span><span class="cx"> [object1, object1],
</span><ins>+ [customObject1, customObject1],
</ins><span class="cx"> [1.23, 1.23],
</span><span class="cx"> ["abc", "abc"],
</span><span class="cx"> [null, null],
</span><span class="lines">@@ -84,6 +74,7 @@
</span><span class="cx"> failingInputs: [
</span><span class="cx"> [true, false],
</span><span class="cx"> [object1, object2],
</span><ins>+ [customObject1, customObject2],
</ins><span class="cx"> [1.23, 4.56],
</span><span class="cx"> ["abc", "def"],
</span><span class="cx"> [null, undefined],
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/Source/WebInspectorUI/ChangeLog        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2016-09-21 Matt Baker <mattbaker@apple.com>
+
+ Web Inspector: Improve output of TestHarness.expect* failures
+ https://bugs.webkit.org/show_bug.cgi?id=162177
+ <rdar://problem/28367186>
+
+ Reviewed by Joseph Pecoraro.
+
+ This patch adds specific expectation functions to TestHarness, to better
+ express intent when writing tests, and to allow more details to be logged
+ in the event of a failure.
+
+ For functions taking both `actual` and `expected` parameters, the `actual`
+ parameter comes first. This convention simplifies the implementation of
+ TestHarness, improves the readability of tests involving inequalities,
+ and is consistent with XCTest assertions.
+
+ * UserInterface/Test/TestHarness.js:
+ (TestHarness):
+ (TestHarness.prototype.expectThat):
+ (TestHarness.prototype.expectFalse):
+ (TestHarness.prototype.expectNull):
+ (TestHarness.prototype.expectNotNull):
+ (TestHarness.prototype.expectEqual):
+ (TestHarness.prototype.expectNotEqual):
+ (TestHarness.prototype.expectShallowEqual):
+ (TestHarness.prototype.expectNotShallowEqual):
+ (TestHarness.prototype.expectEqualWithAccuracy):
+ (TestHarness.prototype.expectLessThan):
+ (TestHarness.prototype.expectLessThanOrEqual):
+ (TestHarness.prototype.expectGreaterThan):
+ (TestHarness.prototype.expectGreaterThanOrEqual):
+ New expectation functions, all of which call _expect under the hood.
+
+ (TestHarness.prototype._expect):
+ Helper method which calls pass or fail. Creates a message when no user
+ message is provided, and logs expected and actual values in the event
+ of a failure.
+
+ (TestHarness.prototype._expectationValueAsString):
+ (TestHarness.prototype._expectationMessageFormat):
+ Get a message format string for the expectation type. Used to create
+ pass/fail message when no user message is provided.
+
+ (TestHarness.prototype._expectedValueFormat):
+ Get a format string for displaying the expected value. Used to create
+ the "Expected: " failure message line.
+
</ins><span class="cx"> 2016-09-20 Joseph Pecoraro <pecoraro@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: Reload unexpectedly switches to Storage Tab
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceTestTestHarnessjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js (206236 => 206237)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js        2016-09-21 21:22:00 UTC (rev 206236)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/TestHarness.js        2016-09-21 21:40:22 UTC (rev 206237)
</span><span class="lines">@@ -30,6 +30,8 @@
</span><span class="cx"> super();
</span><span class="cx">
</span><span class="cx"> this._logCount = 0;
</span><ins>+ this._failureObjects = new Map;
+ this._failureObjectIdentifier = 1;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> completeTest()
</span><span class="lines">@@ -91,74 +93,72 @@
</span><span class="cx"> this.log("ASSERT: " + stringifiedMessage);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- expectThat(condition, message)
</del><ins>+ expectThat(actual, message)
</ins><span class="cx"> {
</span><del>- if (condition)
- this.pass(message);
- else
- this.fail(message);
</del><ins>+ this._expect(TestHarness.ExpectationType.True, !!actual, message, actual);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectFalse(expression, message)
</del><ins>+ expectFalse(actual, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(!expression, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.False, !actual, message, actual);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectNull(expression, message)
</del><ins>+ expectNull(actual, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression === null, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.Null, actual === null, message, actual, null);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectNotNull(expression, message)
</del><ins>+ expectNotNull(actual, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression !== null, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.NotNull, actual !== null, message, actual);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectEqual(expression1, expression2, message)
</del><ins>+ expectEqual(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression1 === expression2, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.Equal, expected === actual, message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectNotEqual(expression1, expression2, message)
</del><ins>+ expectNotEqual(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression1 !== expression2, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.NotEqual, expected !== actual, message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectShallowEqual(expression1, expression2, message)
</del><ins>+ expectShallowEqual(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(Object.shallowEqual(expression1, expression2), message);
</del><ins>+ this._expect(TestHarness.ExpectationType.ShallowEqual, Object.shallowEqual(actual, expected), message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectNotShallowEqual(expression1, expression2, message)
</del><ins>+ expectNotShallowEqual(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(!Object.shallowEqual(expression1, expression2), message);
</del><ins>+ this._expect(TestHarness.ExpectationType.NotShallowEqual, !Object.shallowEqual(actual, expected), message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectEqualWithAccuracy(expression1, expression2, accuracy, message)
</del><ins>+ expectEqualWithAccuracy(actual, expected, accuracy, message)
</ins><span class="cx"> {
</span><del>- console.assert(typeof expression1 === "number");
- console.assert(typeof expression2 === "number");
- this.expectThat(Math.abs(expression1 - expression2) <= accuracy, message);
</del><ins>+ console.assert(typeof expected === "number");
+ console.assert(typeof actual === "number");
+
+ this._expect(TestHarness.ExpectationType.EqualWithAccuracy, Math.abs(expected - actual) <= accuracy, message, actual, expected, accuracy);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectLessThan(expression1, expression2, message)
</del><ins>+ expectLessThan(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression1 < expression2, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.LessThan, actual < expected, message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectLessThanOrEqual(expression1, expression2, message)
</del><ins>+ expectLessThanOrEqual(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression1 <= expression2, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.LessThanOrEqual, actual <= expected, message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectGreaterThan(expression1, expression2, message)
</del><ins>+ expectGreaterThan(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression1 > expression2, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.GreaterThan, actual > expected, message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- expectGreaterThanOrEqual(expression1, expression2, message)
</del><ins>+ expectGreaterThanOrEqual(actual, expected, message)
</ins><span class="cx"> {
</span><del>- this.expectThat(expression1 >= expression2, message);
</del><ins>+ this._expect(TestHarness.ExpectationType.GreaterThanOrEqual, actual >= expected, message, actual, expected);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> pass(message)
</span><span class="lines">@@ -182,4 +182,138 @@
</span><span class="cx">
</span><span class="cx"> return (typeof message !== "string") ? JSON.stringify(message) : message;
</span><span class="cx"> }
</span><ins>+
+ // Private
+
+ _expect(type, condition, message, ...values)
+ {
+ console.assert(values.length > 0, "Should have an 'actual' value.");
+
+ if (!message || !condition) {
+ values = values.map(this._expectationValueAsString.bind(this));
+ message = message || this._expectationMessageFormat(type).format(...values);
+ }
+
+ if (condition) {
+ this.pass(message);
+ return;
+ }
+
+ message += "\n Expected: " + this._expectedValueFormat(type).format(...values.slice(1));
+ message += "\n Actual: " + values[0];
+
+ this.fail(message);
+ }
+
+ _expectationValueAsString(value)
+ {
+ let instanceIdentifier = (object) => {
+ let id = this._failureObjects.get(object);
+ if (!id) {
+ id = this._failureObjectIdentifier++;
+ this._failureObjects.set(object, id);
+ }
+ return "#" + id;
+ };
+
+ const maximumValueStringLength = 200;
+ const defaultValueString = String(new Object); // [object Object]
+
+ // Special case for numbers, since JSON.stringify converts Infinity and NaN to null.
+ if (typeof value === "number")
+ return value;
+
+ try {
+ let valueString = JSON.stringify(value);
+ if (valueString.length <= maximumValueStringLength)
+ return valueString;
+ } catch (e) {}
+
+ try {
+ let valueString = String(value);
+ if (valueString === defaultValueString && value.constructor && value.constructor.name !== "Object")
+ return value.constructor.name + " instance " + instanceIdentifier(value);
+ return valueString;
+ } catch (e) {
+ return defaultValueString;
+ }
+ }
+
+ _expectationMessageFormat(type)
+ {
+ switch (type) {
+ case TestHarness.ExpectationType.True:
+ return "expectThat(%s)";
+ case TestHarness.ExpectationType.False:
+ return "expectFalse(%s)";
+ case TestHarness.ExpectationType.Null:
+ return "expectNull(%s)";
+ case TestHarness.ExpectationType.NotNull:
+ return "expectNotNull(%s)";
+ case TestHarness.ExpectationType.Equal:
+ return "expectEqual(%s, %s)";
+ case TestHarness.ExpectationType.NotEqual:
+ return "expectNotEqual(%s, %s)";
+ case TestHarness.ExpectationType.ShallowEqual:
+ return "expectShallowEqual(%s, %s)";
+ case TestHarness.ExpectationType.NotShallowEqual:
+ return "expectNotShallowEqual(%s, %s)";
+ case TestHarness.ExpectationType.EqualWithAccuracy:
+ return "expectEqualWithAccuracy(%s, %s, %s)";
+ case TestHarness.ExpectationType.LessThan:
+ return "expectLessThan(%s, %s)";
+ case TestHarness.ExpectationType.LessThanOrEqual:
+ return "expectLessThanOrEqual(%s, %s)";
+ case TestHarness.ExpectationType.GreaterThan:
+ return "expectGreaterThan(%s, %s)";
+ case TestHarness.ExpectationType.GreaterThanOrEqual:
+ return "expectGreaterThanOrEqual(%s, %s)";
+ default:
+ console.error("Unknown TestHarness.ExpectationType type: " + type);
+ return null;
+ }
+ }
+
+ _expectedValueFormat(type)
+ {
+ switch (type) {
+ case TestHarness.ExpectationType.True:
+ return "truthy";
+ case TestHarness.ExpectationType.False:
+ return "falsey";
+ case TestHarness.ExpectationType.NotNull:
+ return "not null";
+ case TestHarness.ExpectationType.NotEqual:
+ case TestHarness.ExpectationType.NotShallowEqual:
+ return "not %s";
+ case TestHarness.ExpectationType.EqualWithAccuracy:
+ return "%s +/- %s";
+ case TestHarness.ExpectationType.LessThan:
+ return "less than %s";
+ case TestHarness.ExpectationType.LessThanOrEqual:
+ return "less than or equal to %s";
+ case TestHarness.ExpectationType.GreaterThan:
+ return "greater than %s";
+ case TestHarness.ExpectationType.GreaterThanOrEqual:
+ return "greater than or equal to %s";
+ default:
+ return "%s";
+ }
+ }
</ins><span class="cx"> };
</span><ins>+
+TestHarness.ExpectationType = {
+ True: Symbol("expect-true"),
+ False: Symbol("expect-false"),
+ Null: Symbol("expect-null"),
+ NotNull: Symbol("expect-not-null"),
+ Equal: Symbol("expect-equal"),
+ NotEqual: Symbol("expect-not-equal"),
+ ShallowEqual: Symbol("expect-shallow-equal"),
+ NotShallowEqual: Symbol("expect-not-shallow-equal"),
+ EqualWithAccuracy: Symbol("expect-equal-with-accuracy"),
+ LessThan: Symbol("expect-less-than"),
+ LessThanOrEqual: Symbol("expect-less-than-or-equal"),
+ GreaterThan: Symbol("expect-greater-than"),
+ GreaterThanOrEqual: Symbol("expect-greater-than-or-equal"),
+};
</ins></span></pre>
</div>
</div>
</body>
</html>