Chromium Code Reviews| Index: pkg/unittest/test/matchers_test.dart |
| diff --git a/pkg/unittest/test/matchers_test.dart b/pkg/unittest/test/matchers_test.dart |
| index 10592da32568f5d50d589c2458e2afefaf1fd067..711d5cff5c06b6734d88172c39c7907edd6f8466 100644 |
| --- a/pkg/unittest/test/matchers_test.dart |
| +++ b/pkg/unittest/test/matchers_test.dart |
| @@ -107,7 +107,7 @@ void main() { |
| var a = new Map(); |
| var b = new Map(); |
| shouldPass(a, same(a)); |
| - shouldFail(b, same(a), "Expected: same instance as <{}> but: was <{}>."); |
| + shouldFail(b, same(a), "Expected: same instance as {} but: was {}."); |
| }); |
| test('equals', () { |
| @@ -122,22 +122,27 @@ void main() { |
| shouldPass(0, anything); |
| shouldPass(null, anything); |
| shouldPass(a, anything); |
| - shouldFail(a, isNot(anything), "Expected: not anything but: was <{}>."); |
| + shouldFail(a, isNot(anything), "Expected: not anything but: was {}."); |
| }); |
| test('throws', () { |
| shouldFail(doesNotThrow, throws, |
| - "Expected: throws an exception but: no exception."); |
| + "Expected: throws an exception but: no exception. " |
| + "Actual: <Closure: (dynamic) => dynamic " |
| + "from Function 'doesNotThrow': static.>"); |
| shouldPass(doesThrow, throws); |
| shouldFail(true, throws, |
| - "Expected: throws an exception but: not a Function or Future."); |
| + "Expected: throws an exception but: not a Function or Future. " |
| + "Actual: <true>"); |
| }); |
| test('throwsA', () { |
| shouldPass(doesThrow, throwsA(equals('X'))); |
| shouldFail(doesThrow, throwsA(equals('Y')), |
| - "Expected: throws an exception which matches 'Y' " |
| - "but: exception 'X' does not match 'Y'."); |
| + "Expected: throws an exception which matches 'Y' " |
| + "but: exception 'X' does not match 'Y'. " |
| + "Actual: <Closure: (dynamic) => dynamic " |
| + "from Function 'doesThrow': static.>"); |
| }); |
| test('throwsFormatException', () { |
| @@ -145,8 +150,9 @@ void main() { |
| throwsFormatException); |
| shouldFail(() { throw new Exception(); }, |
| throwsFormatException, |
| - "Expected: throws an exception which matches FormatException " |
| - "but: exception <Exception> does not match FormatException."); |
| + "Expected: throws an exception which matches FormatException " |
| + "but: exception <Exception> does not match FormatException. " |
| + "Actual: <Closure: (dynamic) => dynamic>"); |
| }); |
| test('throwsArgumentError', () { |
| @@ -154,9 +160,10 @@ void main() { |
| throwsArgumentError); |
| shouldFail(() { throw new Exception(); }, |
| throwsArgumentError, |
| - "Expected: throws an exception which matches ArgumentError " |
| - "but: exception <Exception> does not match " |
| - "ArgumentError."); |
| + "Expected: throws an exception which matches ArgumentError " |
| + "but: exception <Exception> does not match " |
| + "ArgumentError. " |
| + "Actual: <Closure: (dynamic) => dynamic>"); |
| }); |
| test('throwsRangeError', () { |
| @@ -164,8 +171,9 @@ void main() { |
| throwsRangeError); |
| shouldFail(() { throw new Exception(); }, |
| throwsRangeError, |
| - "Expected: throws an exception which matches RangeError " |
| - "but: exception <Exception> does not match RangeError."); |
| + "Expected: throws an exception which matches RangeError " |
| + "but: exception <Exception> does not match RangeError. " |
| + "Actual: <Closure: (dynamic) => dynamic>"); |
| }); |
| test('throwsNoSuchMethodError', () { |
| @@ -173,9 +181,10 @@ void main() { |
| throwsNoSuchMethodError); |
| shouldFail(() { throw new Exception(); }, |
| throwsNoSuchMethodError, |
| - "Expected: throws an exception which matches NoSuchMethodError " |
| - "but: exception <Exception> does not match " |
| - "NoSuchMethodError."); |
| + "Expected: throws an exception which matches NoSuchMethodError " |
| + "but: exception <Exception> does not match " |
| + "NoSuchMethodError. " |
| + "Actual: <Closure: (dynamic) => dynamic>"); |
| }); |
| test('throwsUnimplementedError', () { |
| @@ -183,9 +192,10 @@ void main() { |
| throwsUnimplementedError); |
| shouldFail(() { throw new Exception(); }, |
| throwsUnimplementedError, |
| - "Expected: throws an exception which matches UnimplementedError " |
| - "but: exception <Exception> does not match " |
| - "UnimplementedError."); |
| + "Expected: throws an exception which matches UnimplementedError " |
| + "but: exception <Exception> does not match " |
| + "UnimplementedError. " |
| + "Actual: <Closure: (dynamic) => dynamic>"); |
| }); |
| test('throwsUnsupportedError', () { |
| @@ -193,9 +203,10 @@ void main() { |
| throwsUnsupportedError); |
| shouldFail(() { throw new Exception(); }, |
| throwsUnsupportedError, |
| - "Expected: throws an exception which matches UnsupportedError " |
| - "but: exception <Exception> does not match " |
| - "UnsupportedError."); |
| + "Expected: throws an exception which matches UnsupportedError " |
| + "but: exception <Exception> does not match " |
|
gram
2013/05/17 01:00:30
I think now that we have Expected and Actual both
nweiz
2013/05/17 19:50:56
Done.
|
| + "UnsupportedError. " |
| + "Actual: <Closure: (dynamic) => dynamic>"); |
| }); |
| test('throwsStateError', () { |
| @@ -203,15 +214,18 @@ void main() { |
| throwsStateError); |
| shouldFail(() { throw new Exception(); }, |
| throwsStateError, |
| - "Expected: throws an exception which matches StateError " |
| - "but: exception <Exception> does not match " |
| - "StateError."); |
| + "Expected: throws an exception which matches StateError " |
| + "but: exception <Exception> does not match " |
| + "StateError. " |
| + "Actual: <Closure: (dynamic) => dynamic>"); |
| }); |
| test('returnsNormally', () { |
| shouldPass(doesNotThrow, returnsNormally); |
| shouldFail(doesThrow, returnsNormally, |
| - "Expected: return normally but: threw 'X'."); |
| + "Expected: return normally but: threw 'X'. " |
| + "Actual: <Closure: (dynamic) => dynamic " |
| + "from Function 'doesThrow': static.>"); |
| }); |
| test('hasLength', () { |
| @@ -221,41 +235,44 @@ void main() { |
| shouldPass(b, hasLength(0)); |
| shouldPass('a', hasLength(1)); |
| shouldFail(0, hasLength(0), new PrefixMatcher( |
| - "Expected: an object with length of <0> " |
| - "but: was <0> has no length property.")); |
| + "Expected: an object with length of <0> " |
| + "but: had no length property." |
| + "Actual: <0>")); |
| b.add(0); |
| shouldPass(b, hasLength(1)); |
| shouldFail(b, hasLength(2), |
| - "Expected: an object with length of <2> " |
| - "but: was <[0]> with length of <1>."); |
| + "Expected: an object with length of <2> " |
| + "but: had length of <1>. " |
| + "Actual: [0]"); |
| b.add(0); |
| shouldFail(b, hasLength(1), |
| - "Expected: an object with length of <1> " |
| - "but: was <[0, 0]> with length of <2>."); |
| + "Expected: an object with length of <1> " |
| + "but: had length of <2>. " |
| + "Actual: [0, 0]"); |
| shouldPass(b, hasLength(2)); |
| }); |
| test('scalar type mismatch', () { |
| shouldFail('error', equals(5.1), |
| - matches("^Expected: <5\.1>" |
| - " but: was .*:'error' \\(not type .*\\)\.\$")); |
| + "Expected: <5.1> " |
| + "but: was 'error'."); |
| }); |
| test('nested type mismatch', () { |
| shouldFail(['error'], equals([5.1]), |
| - matches(r"^Expected: <\[5\.1\]>" |
| - " but: expected double:<5\.1> " |
| - "but was .*:'error' mismatch at position 0\.\$")); |
| + "Expected: [5.1] " |
| + "but: expected <5.1> but was 'error' mismatch at position 0. " |
| + "Actual: ['error']"); |
| }); |
| test('doubly-nested type mismatch', () { |
| shouldFail([['error']], equals([[5.1]]), |
| - matches(r"^Expected: <\[\[5\.1\]\]>" |
| - " but: expected double:<5\.1> " |
| - "but was .*:'error' mismatch at position 0 " |
| - "mismatch at position 0\.\$")); |
| + "Expected: [[5.1]] " |
| + "but: expected <5.1> but was 'error' " |
| + "mismatch at position 0 mismatch at position 0. " |
| + "Actual: [['error']]"); |
| }); |
| }); |
| @@ -330,10 +347,12 @@ void main() { |
| shouldPass(1, closeTo(0, 1)); |
| shouldFail(1.001, closeTo(0, 1), |
| "Expected: a numeric value within <1> of <0> " |
| - "but: <1.001> differed by <1.001>."); |
| + "but: differed by <1.001>. " |
| + "Actual: <1.001>"); |
| shouldFail(-1.001, closeTo(0, 1), |
| "Expected: a numeric value within <1> of <0> " |
| - "but: <-1.001> differed by <1.001>."); |
| + "but: differed by <1.001>. " |
| + "Actual: <-1.001>"); |
| }); |
| test('inInclusiveRange', () { |
| @@ -456,13 +475,15 @@ void main() { |
| var d = new SimpleIterable(0); |
| var e = new SimpleIterable(1); |
| shouldPass(d, isEmpty); |
| - shouldFail(e, isEmpty, "Expected: empty but: was <[1]>."); |
| + shouldFail(e, isEmpty, "Expected: empty but: was SimpleIterable:[1]."); |
| }); |
| test('contains', () { |
| var d = new SimpleIterable(3); |
| shouldPass(d, contains(2)); |
| - shouldFail(d, contains(5), "Expected: contains <5> but: was <[3]>."); |
| + shouldFail(d, contains(5), |
| + "Expected: contains <5> " |
| + "but: was SimpleIterable:[3, 2, 1]."); |
| }); |
| }); |
| @@ -470,19 +491,19 @@ void main() { |
| test('isEmpty', () { |
| shouldPass([], isEmpty); |
| - shouldFail([1], isEmpty, "Expected: empty but: was <[1]>."); |
| + shouldFail([1], isEmpty, "Expected: empty but: was [1]."); |
| }); |
| test('contains', () { |
| var d = [1, 2]; |
| shouldPass(d, contains(1)); |
| - shouldFail(d, contains(0), "Expected: contains <0> but: was <[1, 2]>."); |
| + shouldFail(d, contains(0), "Expected: contains <0> but: was [1, 2]."); |
| }); |
| test('isIn', () { |
| var d = [1, 2]; |
| shouldPass(1, isIn(d)); |
| - shouldFail(0, isIn(d), "Expected: is in <[1, 2]> but: was <0>."); |
| + shouldFail(0, isIn(d), "Expected: is in [1, 2] but: was <0>."); |
| }); |
| test('everyElement', () { |
| @@ -498,7 +519,7 @@ void main() { |
| var e = [1, 1, 1]; |
| shouldPass(d, someElement(2)); |
| shouldFail(e, someElement(2), |
| - "Expected: some element <2> but: was <[1, 1, 1]>."); |
| + "Expected: some element <2> but: was [1, 1, 1]."); |
| }); |
| test('orderedEquals', () { |
| @@ -506,22 +527,26 @@ void main() { |
| var d = [1, 2]; |
| shouldPass(d, orderedEquals([1, 2])); |
| shouldFail(d, orderedEquals([2, 1]), |
| - "Expected: equals <[2, 1]> ordered " |
| - "but: expected <2> but was <1> mismatch at position 0."); |
| + "Expected: equals [2, 1] ordered " |
| + "but: expected <2> but was <1> mismatch at position 0. " |
| + "Actual: [1, 2]"); |
| }); |
| test('unorderedEquals', () { |
| var d = [1, 2]; |
| shouldPass(d, unorderedEquals([2, 1])); |
| shouldFail(d, unorderedEquals([1]), |
| - "Expected: equals <[1]> unordered " |
| - "but: has too many elements (2 > 1)."); |
| + "Expected: equals [1] unordered " |
| + "but: has too many elements (2 > 1). " |
| + "Actual: [1, 2]"); |
| shouldFail(d, unorderedEquals([3, 2, 1]), |
| - "Expected: equals <[3, 2, 1]> unordered " |
| - "but: has too few elements (2 < 3)."); |
| + "Expected: equals [3, 2, 1] unordered " |
| + "but: has too few elements (2 < 3). " |
| + "Actual: [1, 2]"); |
| shouldFail(d, unorderedEquals([3, 1]), |
| - "Expected: equals <[3, 1]> unordered " |
| - "but: has no match for element <3> at position 0."); |
| + "Expected: equals [3, 1] unordered " |
| + "but: has no match for element <3> at position 0. " |
| + "Actual: [1, 2]"); |
| }); |
| test('pairwise compare', () { |
| @@ -530,19 +555,23 @@ void main() { |
| var e = [1, 4, 9]; |
| shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, |
| "less than or equal"), |
| - "Expected: pairwise less than or equal <[1, 4, 9]> but: " |
| - "not an Iterable."); |
| + "Expected: pairwise less than or equal [1, 4, 9] " |
| + "but: not an Iterable. " |
| + "Actual: 'x'"); |
| shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), |
| - "Expected: pairwise less than or equal <[1, 4, 9]> but: " |
| - "length was 2 instead of 3."); |
| + "Expected: pairwise less than or equal [1, 4, 9] " |
| + "but: length was 2 instead of 3. " |
| + "Actual: [1, 2]"); |
| shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); |
| shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), |
| - "Expected: pairwise less than <[1, 4, 9]> but: " |
| - "<1> not less than <1> at position 0."); |
| + "Expected: pairwise less than [1, 4, 9] " |
| + "but: <1> not less than <1> at position 0. " |
| + "Actual: [1, 2, 3]"); |
| shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); |
| shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), |
| - "Expected: pairwise double <[1, 4, 9]> but: " |
| - "<1> not double <1> at position 0."); |
| + "Expected: pairwise double [1, 4, 9] " |
| + "but: <1> not double <1> at position 0. " |
| + "Actual: [1, 2, 3]"); |
| }); |
| }); |
| @@ -553,7 +582,7 @@ void main() { |
| shouldPass({}, isEmpty); |
| shouldPass(a, isEmpty); |
| a['foo'] = 'bar'; |
| - shouldFail(a, isEmpty, "Expected: empty but: was <{foo: bar}>."); |
| + shouldFail(a, isEmpty, "Expected: empty but: was {'foo': 'bar'}."); |
| }); |
| test('equals', () { |
| @@ -565,7 +594,8 @@ void main() { |
| c['bar'] = 'foo'; |
| shouldPass(a, equals(b)); |
| shouldFail(b, equals(c), |
| - "Expected: <{bar: foo}> but: missing map key 'bar'."); |
| + "Expected: {'bar': 'foo'} but: missing map key 'bar'. " |
| + "Actual: {'foo': 'bar'}"); |
| }); |
| test('equals with different lengths', () { |
| @@ -578,23 +608,29 @@ void main() { |
| c['bar'] = 'foo'; |
| c['barrista'] = 'caffeine'; |
| shouldFail(a, equals(b), |
| - "Expected: <{foo: bar, bar: foo}> " |
| - "but: different map lengths; missing map key 'bar'."); |
| + "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| + "but: different map lengths; missing map key 'bar'. " |
| + "Actual: {'foo': 'bar'}"); |
| shouldFail(b, equals(a), |
| - "Expected: <{foo: bar}> " |
| - "but: different map lengths; extra map key 'bar'."); |
| + "Expected: {'foo': 'bar'} " |
| + "but: different map lengths; extra map key 'bar'. " |
| + "Actual: {'foo': 'bar', 'bar': 'foo'}"); |
| shouldFail(b, equals(c), |
| - "Expected: <{bar: foo, barrista: caffeine}> " |
| - "but: missing map key 'barrista'."); |
| + "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| + "but: missing map key 'barrista'. " |
| + "Actual: {'foo': 'bar', 'bar': 'foo'}"); |
| shouldFail(c, equals(b), |
| - "Expected: <{foo: bar, bar: foo}> " |
| - "but: missing map key 'foo'."); |
| + "Expected: {'foo': 'bar', 'bar': 'foo'} " |
| + "but: missing map key 'foo'. " |
| + "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); |
| shouldFail(a, equals(c), |
| - "Expected: <{bar: foo, barrista: caffeine}> " |
| - "but: different map lengths; missing map key 'bar'."); |
| + "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " |
| + "but: different map lengths; missing map key 'bar'. " |
| + "Actual: {'foo': 'bar'}"); |
| shouldFail(c, equals(a), |
| - "Expected: <{foo: bar}> " |
| - "but: different map lengths; missing map key 'foo'."); |
| + "Expected: {'foo': 'bar'} " |
| + "but: different map lengths; missing map key 'foo'. " |
| + "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); |
| }); |
| test('contains', () { |
| @@ -603,7 +639,7 @@ void main() { |
| var b = new Map(); |
| shouldPass(a, contains('foo')); |
| shouldFail(b, contains('foo'), |
| - "Expected: contains 'foo' but: was <{}>."); |
| + "Expected: contains 'foo' but: was {}."); |
| shouldFail(10, contains('foo'), |
| "Expected: contains 'foo' but: was <10>."); |
| }); |
| @@ -613,7 +649,7 @@ void main() { |
| a['foo'] = 'bar'; |
| shouldPass(a, containsValue('bar')); |
| shouldFail(a, containsValue('ba'), |
| - "Expected: contains value 'ba' but: was <{foo: bar}>."); |
| + "Expected: contains value 'ba' but: was {'foo': 'bar'}."); |
| }); |
|
gram
2013/05/17 01:00:30
You seem to have established a new pattern for out
nweiz
2013/05/17 19:50:56
It seems weird to me when the "But" clause would j
gram
2013/05/17 20:38:32
I agree with you that it could be weird, but havin
nweiz
2013/05/17 21:07:21
I think there's room to improve and normalize thes
|
| test('containsPair', () { |
| @@ -622,10 +658,12 @@ void main() { |
| shouldPass(a, containsPair('foo', 'bar')); |
| shouldFail(a, containsPair('foo', 'ba'), |
| "Expected: contains pair 'foo' => 'ba' " |
| - "but: contains key 'foo' but with value was 'bar'."); |
| + "but: contains key 'foo' but with value was 'bar'. " |
| + "Actual: {'foo': 'bar'}"); |
| shouldFail(a, containsPair('fo', 'bar'), |
| "Expected: contains pair 'fo' => 'bar' " |
| - "but: <{foo: bar}> doesn't contain key 'fo'."); |
| + "but: doesn't contain key 'fo'. " |
| + "Actual: {'foo': 'bar'}"); |
| }); |
| test('hasLength', () { |
| @@ -635,7 +673,8 @@ void main() { |
| shouldPass(a, hasLength(1)); |
| shouldFail(b, hasLength(1), |
| "Expected: an object with length of <1> " |
| - "but: was <{}> with length of <0>."); |
| + "but: had length of <0>. " |
| + "Actual: {}"); |
| }); |
| }); |
| @@ -651,7 +690,7 @@ void main() { |
| shouldPass(1, allOf([lessThan(10), greaterThan(0)])); |
| shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), |
| "Expected: (a value less than <10> and a value greater than <0>) " |
| - "but: a value greater than <0> was <-1>."); |
| + "but: was <-1> (a value greater than <0>)."); |
|
gram
2013/05/17 01:00:30
Another inconsistent case.
nweiz
2013/05/17 19:50:56
This case is weird. If all of the uses of [allOf]
|
| }); |
| }); |
| @@ -731,8 +770,9 @@ void main() { |
| shouldPass(w, new HasPrice(10)); |
| shouldPass(w, new HasPrice(greaterThan(0))); |
| shouldFail(w, new HasPrice(greaterThan(10)), |
| - 'Expected: Widget with a price that is a value greater than <10> ' |
| - 'but: price was <10>.'); |
| + "Expected: Widget with a price that is a value greater than <10> " |
| + "but: price was <10>. " |
| + "Actual: <Instance of 'Widget'>"); |
| }); |
| }); |
| } |