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

Side by Side Diff: pkg/unittest/test/matchers_minified_test.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
« no previous file with comments | « pkg/unittest/test/instance_test.dart ('k') | pkg/unittest/test/matchers_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This file is for matcher tests that rely on the names of various Dart types. 5 // This file is for matcher tests that rely on the names of various Dart types.
6 // These tests normally fail when run in minified dart2js, since the names will 6 // These tests normally fail when run in minified dart2js, since the names will
7 // be mangled. This version of the file is modified to expect minified names. 7 // be mangled. This version of the file is modified to expect minified names.
8 8
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
11 import 'test_common.dart'; 11 import 'test_common.dart';
12 import 'test_utils.dart'; 12 import 'test_utils.dart';
13 13
14 // A regexp fragment matching a minified name. 14 // A regexp fragment matching a minified name.
15 final _minifiedName = r"[A-Za-z0-9]{1,3}"; 15 final _minifiedName = r"[A-Za-z0-9]{1,3}";
16 16
17 void main() { 17 void main() {
18 initUtils(); 18 initUtils();
19 19
20 group('Core matchers', () { 20 group('Core matchers', () {
21 test('throwsFormatException', () { 21 test('throwsFormatException', () {
22 shouldPass(() { throw new FormatException(''); }, 22 shouldPass(() { throw new FormatException(''); },
23 throwsFormatException); 23 throwsFormatException);
24 shouldFail(() { throw new Exception(); }, 24 shouldFail(() { throw new Exception(); },
25 throwsFormatException, 25 throwsFormatException,
26 matches( 26 matches(
27 r"Expected: throws an exception which matches FormatException +" 27 r"Expected: throws FormatException +"
28 r"But: exception " + _minifiedName + r":<Exception> " 28 r"Actual: <Closure(: \(dynamic\) => dynamic)?> +"
29 r"does not match FormatException\." 29 r"Which: threw " + _minifiedName + r":<Exception>"));
30 r"Actual: <Closure>"));
31 }); 30 });
32 31
33 test('throwsArgumentError', () { 32 test('throwsArgumentError', () {
34 shouldPass(() { throw new ArgumentError(''); }, 33 shouldPass(() { throw new ArgumentError(''); },
35 throwsArgumentError); 34 throwsArgumentError);
36 shouldFail(() { throw new Exception(); }, 35 shouldFail(() { throw new Exception(); },
37 throwsArgumentError, 36 throwsArgumentError,
38 matches( 37 matches(
39 r"Expected: throws an exception which matches ArgumentError +" 38 r"Expected: throws ArgumentError +"
40 r"But: exception " + _minifiedName + r":<Exception> " 39 r"Actual: <Closure(: \(dynamic\) => dynamic)?> +"
41 r"does not match ArgumentError\." 40 r"Which: threw " + _minifiedName + r":<Exception>"));
42 r"Actual: <Closure>"));
43 }); 41 });
44 42
45 test('throwsRangeError', () { 43 test('throwsRangeError', () {
46 shouldPass(() { throw new RangeError(0); }, 44 shouldPass(() { throw new RangeError(0); },
47 throwsRangeError); 45 throwsRangeError);
48 shouldFail(() { throw new Exception(); }, 46 shouldFail(() { throw new Exception(); },
49 throwsRangeError, 47 throwsRangeError,
50 matches( 48 matches(
51 r"Expected: throws an exception which matches RangeError +" 49 r"Expected: throws RangeError +"
52 r"But: exception " + _minifiedName + r":<Exception> " 50 r"Actual: <Closure(: \(dynamic\) => dynamic)?> +"
53 r"does not match RangeError\." 51 r"Which: threw " + _minifiedName + r":<Exception>"));
54 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
55 }); 52 });
56 53
57 test('throwsNoSuchMethodError', () { 54 test('throwsNoSuchMethodError', () {
58 shouldPass(() { throw new NoSuchMethodError(null, '', null, null); }, 55 shouldPass(() { throw new NoSuchMethodError(null, '', null, null); },
59 throwsNoSuchMethodError); 56 throwsNoSuchMethodError);
60 shouldFail(() { throw new Exception(); }, 57 shouldFail(() { throw new Exception(); },
61 throwsNoSuchMethodError, 58 throwsNoSuchMethodError,
62 matches( 59 matches(
63 r"Expected: throws an exception which matches NoSuchMethodError +" 60 r"Expected: throws NoSuchMethodError +"
64 r"But: exception " + _minifiedName + r":<Exception> " 61 r"Actual: <Closure(: \(dynamic\) => dynamic)?> +"
65 r"does not match NoSuchMethodError\." 62 r"Which: threw " + _minifiedName + r":<Exception>"));
66 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
67 }); 63 });
68 64
69 test('throwsUnimplementedError', () { 65 test('throwsUnimplementedError', () {
70 shouldPass(() { throw new UnimplementedError(''); }, 66 shouldPass(() { throw new UnimplementedError(''); },
71 throwsUnimplementedError); 67 throwsUnimplementedError);
72 shouldFail(() { throw new Exception(); }, 68 shouldFail(() { throw new Exception(); },
73 throwsUnimplementedError, 69 throwsUnimplementedError,
74 matches( 70 matches(
75 r"Expected: throws an exception which matches " 71 r"Expected: throws UnimplementedError +"
76 r"UnimplementedError +" 72 r"Actual: <Closure(: \(dynamic\) => dynamic)?> +"
77 r"But: exception " + _minifiedName + r":<Exception> " 73 r"Which: threw " + _minifiedName + r":<Exception>"));
78 r"does not match UnimplementedError\."
79 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
80 }); 74 });
81 75
82 test('throwsUnsupportedError', () { 76 test('throwsUnsupportedError', () {
83 shouldPass(() { throw new UnsupportedError(''); }, 77 shouldPass(() { throw new UnsupportedError(''); },
84 throwsUnsupportedError); 78 throwsUnsupportedError);
85 shouldFail(() { throw new Exception(); }, 79 shouldFail(() { throw new Exception(); },
86 throwsUnsupportedError, 80 throwsUnsupportedError,
87 matches( 81 matches(
88 r"Expected: throws an exception which matches UnsupportedError +" 82 r"Expected: throws UnsupportedError +"
89 r"But: exception " + _minifiedName + r":<Exception> " 83 r"Actual: <Closure(: \(dynamic\) => dynamic)?> +"
90 r"does not match UnsupportedError\." 84 r"Which: threw " + _minifiedName + r":<Exception>"));
91 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
92 }); 85 });
93 86
94 test('throwsStateError', () { 87 test('throwsStateError', () {
95 shouldPass(() { throw new StateError(''); }, 88 shouldPass(() { throw new StateError(''); },
96 throwsStateError); 89 throwsStateError);
97 shouldFail(() { throw new Exception(); }, 90 shouldFail(() { throw new Exception(); },
98 throwsStateError, 91 throwsStateError,
99 matches( 92 matches(
100 r"Expected: throws an exception which matches StateError +" 93 r"Expected: throws StateError +"
101 r"But: exception " + _minifiedName + r":<Exception> " 94 r"Actual: <Closure(: \(dynamic\) => dynamic)?> +"
102 r"does not match StateError\." 95 r"Which: threw " + _minifiedName + r":<Exception>"));
103 r"Actual: <Closure(: \(dynamic\) => dynamic)?>"));
104 }); 96 });
105 }); 97 });
106 98
107 group('Iterable Matchers', () { 99 group('Iterable Matchers', () {
108 test('isEmpty', () { 100 test('isEmpty', () {
109 var d = new SimpleIterable(0); 101 var d = new SimpleIterable(0);
110 var e = new SimpleIterable(1); 102 var e = new SimpleIterable(1);
111 shouldPass(d, isEmpty); 103 shouldPass(d, isEmpty);
112 shouldFail(e, isEmpty, 104 shouldFail(e, isEmpty,
113 matches(r"Expected: empty +But: was " + _minifiedName + r":\[1\]\.")); 105 matches(r"Expected: empty +Actual: " + _minifiedName + r":\[1\]"));
114 }); 106 });
115 107
116 test('contains', () { 108 test('contains', () {
117 var d = new SimpleIterable(3); 109 var d = new SimpleIterable(3);
118 shouldPass(d, contains(2)); 110 shouldPass(d, contains(2));
119 shouldFail(d, contains(5), 111 shouldFail(d, contains(5),
120 matches( 112 matches(
121 r"Expected: contains <5> +" 113 r"Expected: contains <5> +"
122 r"But: was " + _minifiedName + r":\[3, 2, 1\]\.")); 114 r"Actual: " + _minifiedName + r":\[3, 2, 1\]"));
123 }); 115 });
124 }); 116 });
125 117
126 group('Feature Matchers', () { 118 group('Feature Matchers', () {
127 test("Feature Matcher", () { 119 test("Feature Matcher", () {
128 var w = new Widget(); 120 var w = new Widget();
129 w.price = 10; 121 w.price = 10;
130 shouldPass(w, new HasPrice(10)); 122 shouldPass(w, new HasPrice(10));
131 shouldPass(w, new HasPrice(greaterThan(0))); 123 shouldPass(w, new HasPrice(greaterThan(0)));
132 shouldFail(w, new HasPrice(greaterThan(10)), 124 shouldFail(w, new HasPrice(greaterThan(10)),
133 matches( 125 matches(
134 r"Expected: Widget with a price that is a value greater than " 126 r"Expected: Widget with a price that is a value greater than "
135 r"<10> +" 127 r"<10> +"
136 r"But: price was <10>\." 128 r"Actual: <Instance of '" + _minifiedName + r"'> +"
137 r"Actual: <Instance of '" + _minifiedName + r"'>")); 129 r"Which: has price with value <10> which is not "
130 r"a value greater than <10>"));
138 }); 131 });
139 }); 132 });
140 } 133 }
OLDNEW
« no previous file with comments | « pkg/unittest/test/instance_test.dart ('k') | pkg/unittest/test/matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698