| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library matcher.prints_matchers_test; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:matcher/matcher.dart'; | |
| 10 import 'package:unittest/unittest.dart'; | |
| 11 | |
| 12 import 'test_utils.dart'; | |
| 13 | |
| 14 /// The VM and dart2js have different toStrings for closures. | |
| 15 final closureToString = (() {}).toString(); | |
| 16 | |
| 17 void main() { | |
| 18 initUtils(); | |
| 19 | |
| 20 group('synchronous', () { | |
| 21 test("passes with an expected print", () { | |
| 22 shouldPass(() => print("Hello, world!"), prints("Hello, world!\n")); | |
| 23 }); | |
| 24 | |
| 25 test("combines multiple prints", () { | |
| 26 shouldPass(() { | |
| 27 print("Hello"); | |
| 28 print("World!"); | |
| 29 }, prints("Hello\nWorld!\n")); | |
| 30 }); | |
| 31 | |
| 32 test("works with a Matcher", () { | |
| 33 shouldPass(() => print("Hello, world!"), prints(contains("Hello"))); | |
| 34 }); | |
| 35 | |
| 36 test("describes a failure nicely", () { | |
| 37 shouldFail(() => print("Hello, world!"), prints("Goodbye, world!\n"), | |
| 38 "Expected: prints 'Goodbye, world!\\n' ''" | |
| 39 " Actual: <$closureToString> " | |
| 40 " Which: printed 'Hello, world!\\n' ''" | |
| 41 " Which: is different. " | |
| 42 "Expected: Goodbye, w ... " | |
| 43 " Actual: Hello, wor ... " | |
| 44 " ^ Differ at offset 0"); | |
| 45 }); | |
| 46 | |
| 47 test("describes a failure with a non-descriptive Matcher nicely", () { | |
| 48 shouldFail(() => print("Hello, world!"), prints(contains("Goodbye")), | |
| 49 "Expected: prints contains 'Goodbye'" | |
| 50 " Actual: <$closureToString> " | |
| 51 " Which: printed 'Hello, world!\\n' ''"); | |
| 52 }); | |
| 53 | |
| 54 test("describes a failure with no text nicely", () { | |
| 55 shouldFail(() {}, prints(contains("Goodbye")), | |
| 56 "Expected: prints contains 'Goodbye'" | |
| 57 " Actual: <$closureToString> " | |
| 58 " Which: printed nothing."); | |
| 59 }); | |
| 60 }); | |
| 61 | |
| 62 group('asynchronous', () { | |
| 63 test("passes with an expected print", () { | |
| 64 shouldPass(() => new Future(() => print("Hello, world!")), | |
| 65 prints("Hello, world!\n")); | |
| 66 }); | |
| 67 | |
| 68 test("combines multiple prints", () { | |
| 69 shouldPass(() => new Future(() { | |
| 70 print("Hello"); | |
| 71 print("World!"); | |
| 72 }), prints("Hello\nWorld!\n")); | |
| 73 }); | |
| 74 | |
| 75 test("works with a Matcher", () { | |
| 76 shouldPass(() => new Future(() => print("Hello, world!")), | |
| 77 prints(contains("Hello"))); | |
| 78 }); | |
| 79 | |
| 80 test("describes a failure nicely", () { | |
| 81 shouldFail(() => new Future(() => print("Hello, world!")), | |
| 82 prints("Goodbye, world!\n"), | |
| 83 "Expected: 'Goodbye, world!\\n' ''" | |
| 84 " Actual: 'Hello, world!\\n' ''" | |
| 85 " Which: is different. " | |
| 86 "Expected: Goodbye, w ... " | |
| 87 " Actual: Hello, wor ... " | |
| 88 " ^ Differ at offset 0", | |
| 89 isAsync: true); | |
| 90 }); | |
| 91 | |
| 92 test("describes a failure with a non-descriptive Matcher nicely", () { | |
| 93 shouldFail(() => new Future(() => print("Hello, world!")), | |
| 94 prints(contains("Goodbye")), | |
| 95 "Expected: contains 'Goodbye'" | |
| 96 " Actual: 'Hello, world!\\n' ''", | |
| 97 isAsync: true); | |
| 98 }); | |
| 99 | |
| 100 test("describes a failure with no text nicely", () { | |
| 101 shouldFail(() => new Future.value(), prints(contains("Goodbye")), | |
| 102 "Expected: contains 'Goodbye'" | |
| 103 " Actual: ''", | |
| 104 isAsync: true); | |
| 105 }); | |
| 106 }); | |
| 107 } | |
| OLD | NEW |