Web Inspector: Improve output of TestHarness.expect* failures
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 21:40:22 +0000 (21:40 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 21:40:22 +0000 (21:40 +0000)
commitf6a40f923ac2b05ea6d2e4f934a3898e32ef1885
tree639a2e8512d8daa655d224637194f481cdd85c36
parentc353f7f272ec3d6240eb9d2825979412a3be272a
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206237 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/inspector/indexeddb/requestData-expected.txt
LayoutTests/inspector/unit-tests/number-utilities-expected.txt
LayoutTests/inspector/unit-tests/test-harness-expect-functions-expected.txt
LayoutTests/inspector/unit-tests/test-harness-expect-functions.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Test/TestHarness.js