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

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

Issue 10832058: Improved the way we generate mismatch descriptions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 // To decouple the reporting of errors, and allow for extensibility of 5 // To decouple the reporting of errors, and allow for extensibility of
6 // matchers, we make use of some interfaces. 6 // matchers, we make use of some interfaces.
7 7
8 /** 8 /**
9 * The ErrorFormatter type is used for functions that 9 * The ErrorFormatter type is used for functions that
10 * can be used to build up error reports upon [expect] failures. 10 * can be used to build up error reports upon [expect] failures.
11 * There is one built-in implementation ([defaultErrorFormatter]) 11 * There is one built-in implementation ([defaultErrorFormatter])
12 * which is used by the default failure handler. If the failure handler 12 * which is used by the default failure handler. If the failure handler
13 * is replaced it may be desirable to replace the [stringDescription] 13 * is replaced it may be desirable to replace the [stringDescription]
14 * error formatter with another. 14 * error formatter with another.
15 */ 15 */
16 typedef String ErrorFormatter(actual, Matcher matcher, String reason); 16 typedef String ErrorFormatter(actual, Matcher matcher, String reason,
17 MatchState matchState, bool verbose);
17 18
18 /** 19 /**
19 * Matchers build up their error messages by appending to 20 * Matchers build up their error messages by appending to
20 * Description objects. This interface is implemented by 21 * Description objects. This interface is implemented by
21 * StringDescription. This interface is unlikely to need 22 * StringDescription. This interface is unlikely to need
22 * other implementations, but could be useful to replace in 23 * other implementations, but could be useful to replace in
23 * some cases - e.g. language conversion. 24 * some cases - e.g. language conversion.
24 */ 25 */
25 interface Description { 26 interface Description {
26 /** Change the value of the description. */ 27 /** Change the value of the description. */
(...skipping 15 matching lines...) Expand all
42 43
43 /** 44 /**
44 * [expect] Matchers must implement the Matcher interface. 45 * [expect] Matchers must implement the Matcher interface.
45 * The base Matcher class that implements this interface has 46 * The base Matcher class that implements this interface has
46 * a generic implementation of [describeMismatch] so this does 47 * a generic implementation of [describeMismatch] so this does
47 * not need to be provided unless a more clear description is 48 * not need to be provided unless a more clear description is
48 * required. The other two methods ([matches] and [describe]) 49 * required. The other two methods ([matches] and [describe])
49 * must always be provided as they are highly matcher-specific. 50 * must always be provided as they are highly matcher-specific.
50 */ 51 */
51 interface Matcher { 52 interface Matcher {
52 /** This does the matching of the actual vs expected values. */ 53 /**
53 bool matches(item); 54 * This does the matching of the actual vs expected values.
55 * [item] is the actual value. [matchState] can be supplied
56 * and may be used to add details about the mismatch that are too
57 * costly to determine in [describeMismatch].
58 */
59 bool matches(item, MatchState matchState);
Siggi Cherem (dart-lang) 2012/07/31 17:16:40 should matchState be optional?
gram 2012/07/31 17:56:01 I decided not to do this because the initial call
54 60
55 /** This builds a textual description of the matcher. */ 61 /** This builds a textual description of the matcher. */
56 Description describe(Description description); 62 Description describe(Description description);
57 63
58 /**This builds a textual description of a specific mismatch. */ 64 /**
59 Description describeMismatch(item, Description mismatchDescription); 65 * This builds a textual description of a specific mismatch. [item]
66 * is the value that was tested by [matches]; [matchState] is
67 * the [MatchState] that was passed to and supplemented by [matches]
68 * with additional information about the mismact, and [mismatchDescription]
69 * is the [Description] that is being built to decribe the mismatch.
70 * A few matchers make use of the [verbose] flag to provide detailed
71 * information that is not typically included but can be of help in
72 * diagnosing failures, such as stack traces.
73 */
74 Description describeMismatch(item, Description mismatchDescription,
75 MatchState matchState, bool verbose);
Siggi Cherem (dart-lang) 2012/07/31 17:16:40 should matchState + verbose be optional?
gram 2012/07/31 17:56:01 Similarly, there is currently only one place where
60 } 76 }
61 77
62 /** 78 /**
63 * Failed matches are reported using a default IFailureHandler. 79 * Failed matches are reported using a default IFailureHandler.
64 * The default implementation simply throws ExpectExceptions; 80 * The default implementation simply throws ExpectExceptions;
65 * this can be replaced by some other implementation of 81 * this can be replaced by some other implementation of
66 * IFailureHandler by calling configureExpectHandler. 82 * IFailureHandler by calling configureExpectHandler.
67 */ 83 */
68 interface FailureHandler { 84 interface FailureHandler {
69 /** This handles failures given a textual decription */ 85 /** This handles failures given a textual decription */
70 void fail(String reason); 86 void fail(String reason);
71 87
72 /** 88 /**
73 * This handles failures given the actual [value], the [matcher] 89 * This handles failures given the actual [value], the [matcher]
74 * and the [reason]. It will typically use these to create a 90 * the [reason] (argument from [expect]), some additonal [matchState]
75 * detailed error message (typically using an [ErrorFormatter]) 91 * generated by the [matcher], and a verbose flag which controls in
76 * and then call [fail]. 92 * some cases how much [matchState] information is used. It will use
93 * these to create a detailed error message (typically by calling
94 * an [ErrorFormatter]) and then call [fail] with this message.
77 */ 95 */
78 void failMatch(actual, Matcher matcher, String reason); 96 void failMatch(actual, Matcher matcher, String reason,
97 MatchState matchState, bool verbose);
79 } 98 }
80 99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698