Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: pkg/unittest/lib/src/interfaces.dart

Issue 16408019: Improved error messages from unittest. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of matcher; 5 part of matcher;
6 6
7 // To decouple the reporting of errors, and allow for extensibility of 7 // To decouple the reporting of errors, and allow for extensibility of
8 // matchers, we make use of some interfaces. 8 // matchers, we make use of some interfaces.
9 9
10 /** 10 /**
11 * The ErrorFormatter type is used for functions that 11 * The ErrorFormatter type is used for functions that
12 * can be used to build up error reports upon [expect] failures. 12 * can be used to build up error reports upon [expect] failures.
13 * There is one built-in implementation ([defaultErrorFormatter]) 13 * There is one built-in implementation ([defaultErrorFormatter])
14 * which is used by the default failure handler. If the failure handler 14 * which is used by the default failure handler. If the failure handler
15 * is replaced it may be desirable to replace the [stringDescription] 15 * is replaced it may be desirable to replace the [stringDescription]
16 * error formatter with another. 16 * error formatter with another.
17 */ 17 */
18 typedef String ErrorFormatter(actual, Matcher matcher, String reason, 18 typedef String ErrorFormatter(actual, Matcher matcher, String reason,
19 MatchState matchState, bool verbose); 19 Map matchState, bool verbose);
20 20
21 /** 21 /**
22 * Matchers build up their error messages by appending to 22 * Matchers build up their error messages by appending to
23 * Description objects. This interface is implemented by 23 * Description objects. This interface is implemented by
24 * StringDescription. This interface is unlikely to need 24 * StringDescription. This interface is unlikely to need
25 * other implementations, but could be useful to replace in 25 * other implementations, but could be useful to replace in
26 * some cases - e.g. language conversion. 26 * some cases - e.g. language conversion.
27 */ 27 */
28 abstract class Description { 28 abstract class Description {
29 /** Change the value of the description. */ 29 /** Change the value of the description. */
(...skipping 21 matching lines...) Expand all
51 * required. The other two methods ([matches] and [describe]) 51 * required. The other two methods ([matches] and [describe])
52 * must always be provided as they are highly matcher-specific. 52 * must always be provided as they are highly matcher-specific.
53 */ 53 */
54 abstract class Matcher { 54 abstract class Matcher {
55 /** 55 /**
56 * This does the matching of the actual vs expected values. 56 * This does the matching of the actual vs expected values.
57 * [item] is the actual value. [matchState] can be supplied 57 * [item] is the actual value. [matchState] can be supplied
58 * and may be used to add details about the mismatch that are too 58 * and may be used to add details about the mismatch that are too
59 * costly to determine in [describeMismatch]. 59 * costly to determine in [describeMismatch].
60 */ 60 */
61 bool matches(item, MatchState matchState); 61 bool matches(item, Map matchState);
62 62
63 /** This builds a textual description of the matcher. */ 63 /** This builds a textual description of the matcher. */
64 Description describe(Description description); 64 Description describe(Description description);
65 65
66 /** 66 /**
67 * This builds a textual description of a specific mismatch. [item] 67 * This builds a textual description of a specific mismatch. [item]
68 * is the value that was tested by [matches]; [matchState] is 68 * is the value that was tested by [matches]; [matchState] is
69 * the [MatchState] that was passed to and supplemented by [matches] 69 * the [Map] that was passed to and supplemented by [matches]
70 * with additional information about the mismact, and [mismatchDescription] 70 * with additional information about the mismact, and [mismatchDescription]
71 * is the [Description] that is being built to decribe the mismatch. 71 * is the [Description] that is being built to decribe the mismatch.
72 * A few matchers make use of the [verbose] flag to provide detailed 72 * A few matchers make use of the [verbose] flag to provide detailed
73 * information that is not typically included but can be of help in 73 * information that is not typically included but can be of help in
74 * diagnosing failures, such as stack traces. 74 * diagnosing failures, such as stack traces.
75 */ 75 */
76 Description describeMismatch(item, Description mismatchDescription, 76 Description describeMismatch(item, Description mismatchDescription,
77 MatchState matchState, bool verbose); 77 Map matchState, bool verbose);
78 } 78 }
79 79
80 /** 80 /**
81 * Failed matches are reported using a default IFailureHandler. 81 * Failed matches are reported using a default IFailureHandler.
82 * The default implementation simply throws [TestFailure]s; 82 * The default implementation simply throws [TestFailure]s;
83 * this can be replaced by some other implementation of 83 * this can be replaced by some other implementation of
84 * IFailureHandler by calling configureExpectHandler. 84 * IFailureHandler by calling configureExpectHandler.
85 */ 85 */
86 abstract class FailureHandler { 86 abstract class FailureHandler {
87 /** This handles failures given a textual decription */ 87 /** This handles failures given a textual decription */
88 void fail(String reason); 88 void fail(String reason);
89 89
90 /** 90 /**
91 * This handles failures given the actual [value], the [matcher] 91 * This handles failures given the actual [value], the [matcher]
92 * the [reason] (argument from [expect]), some additonal [matchState] 92 * the [reason] (argument from [expect]), some additonal [matchState]
93 * generated by the [matcher], and a verbose flag which controls in 93 * generated by the [matcher], and a verbose flag which controls in
94 * some cases how much [matchState] information is used. It will use 94 * some cases how much [matchState] information is used. It will use
95 * these to create a detailed error message (typically by calling 95 * these to create a detailed error message (typically by calling
96 * an [ErrorFormatter]) and then call [fail] with this message. 96 * an [ErrorFormatter]) and then call [fail] with this message.
97 */ 97 */
98 void failMatch(actual, Matcher matcher, String reason, 98 void failMatch(actual, Matcher matcher, String reason,
99 MatchState matchState, bool verbose); 99 Map matchState, bool verbose);
100 } 100 }
101 101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698