| 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 import 'dart:async'; | |
| 6 | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 | |
| 9 import '../utils.dart'; | |
| 10 | |
| 11 void main() { | |
| 12 group("synchronous", () { | |
| 13 test("passes with an expected print", () { | |
| 14 expect(() => print("Hello, world!"), prints("Hello, world!\n")); | |
| 15 }); | |
| 16 | |
| 17 test("combines multiple prints", () { | |
| 18 expect(() { | |
| 19 print("Hello"); | |
| 20 print("World!"); | |
| 21 }, prints("Hello\nWorld!\n")); | |
| 22 }); | |
| 23 | |
| 24 test("works with a Matcher", () { | |
| 25 expect(() => print("Hello, world!"), prints(contains("Hello"))); | |
| 26 }); | |
| 27 | |
| 28 test("describes a failure nicely", () { | |
| 29 return runTest(() { | |
| 30 expect(() => print("Hello, world!"), prints("Goodbye, world!\n")); | |
| 31 }).then((liveTest) { | |
| 32 expectTestFailed(liveTest, | |
| 33 "Expected: prints 'Goodbye, world!\\n'\n" | |
| 34 " ''\n" | |
| 35 " Actual: <Closure: () => dynamic>\n" | |
| 36 " Which: printed 'Hello, world!\\n'\n" | |
| 37 " ''\n" | |
| 38 " Which: is different.\n" | |
| 39 "Expected: Goodbye, w ...\n" | |
| 40 " Actual: Hello, wor ...\n" | |
| 41 " ^\n" | |
| 42 " Differ at offset 0\n"); | |
| 43 }); | |
| 44 }); | |
| 45 | |
| 46 test("describes a failure with a non-descriptive Matcher nicely", () { | |
| 47 return runTest(() { | |
| 48 expect(() => print("Hello, world!"), prints(contains("Goodbye"))); | |
| 49 }).then((liveTest) { | |
| 50 expectTestFailed(liveTest, | |
| 51 "Expected: prints contains 'Goodbye'\n" | |
| 52 " Actual: <Closure: () => dynamic>\n" | |
| 53 " Which: printed 'Hello, world!\\n'\n" | |
| 54 " ''\n"); | |
| 55 }); | |
| 56 }); | |
| 57 | |
| 58 test("describes a failure with no text nicely", () { | |
| 59 return runTest(() { | |
| 60 expect(() {}, prints(contains("Goodbye"))); | |
| 61 }).then((liveTest) { | |
| 62 expectTestFailed(liveTest, | |
| 63 "Expected: prints contains 'Goodbye'\n" | |
| 64 " Actual: <Closure: () => dynamic>\n" | |
| 65 " Which: printed nothing.\n"); | |
| 66 }); | |
| 67 }); | |
| 68 | |
| 69 test("with a non-function", () { | |
| 70 return runTest(() { | |
| 71 expect(10, prints(contains("Goodbye"))); | |
| 72 }).then((liveTest) { | |
| 73 expectTestFailed(liveTest, | |
| 74 "Expected: prints contains 'Goodbye'\n" | |
| 75 " Actual: <10>\n"); | |
| 76 }); | |
| 77 }); | |
| 78 }); | |
| 79 | |
| 80 group('asynchronous', () { | |
| 81 test("passes with an expected print", () { | |
| 82 expect(() => new Future(() => print("Hello, world!")), | |
| 83 prints("Hello, world!\n")); | |
| 84 }); | |
| 85 | |
| 86 test("combines multiple prints", () { | |
| 87 expect(() => new Future(() { | |
| 88 print("Hello"); | |
| 89 print("World!"); | |
| 90 }), prints("Hello\nWorld!\n")); | |
| 91 }); | |
| 92 | |
| 93 test("works with a Matcher", () { | |
| 94 expect(() => new Future(() => print("Hello, world!")), | |
| 95 prints(contains("Hello"))); | |
| 96 }); | |
| 97 | |
| 98 test("describes a failure nicely", () { | |
| 99 return runTest(() { | |
| 100 expect(() => new Future(() => print("Hello, world!")), | |
| 101 prints("Goodbye, world!\n")); | |
| 102 }).then((liveTest) { | |
| 103 expectTestFailed(liveTest, startsWith( | |
| 104 "Expected: prints 'Goodbye, world!\\n'\n" | |
| 105 " ''\n" | |
| 106 " Actual: <Closure: () => dynamic>\n" | |
| 107 " Which: printed 'Hello, world!\\n'\n" | |
| 108 " ''\n" | |
| 109 " Which: is different.\n" | |
| 110 "Expected: Goodbye, w ...\n" | |
| 111 " Actual: Hello, wor ...\n" | |
| 112 " ^\n" | |
| 113 " Differ at offset 0")); | |
| 114 }); | |
| 115 }); | |
| 116 | |
| 117 test("describes a failure with a non-descriptive Matcher nicely", () { | |
| 118 return runTest(() { | |
| 119 expect(() => new Future(() => print("Hello, world!")), | |
| 120 prints(contains("Goodbye"))); | |
| 121 }).then((liveTest) { | |
| 122 expectTestFailed(liveTest, startsWith( | |
| 123 "Expected: prints contains 'Goodbye'\n" | |
| 124 " Actual: <Closure: () => dynamic>\n" | |
| 125 " Which: printed 'Hello, world!\\n'\n" | |
| 126 " ''")); | |
| 127 }); | |
| 128 }); | |
| 129 | |
| 130 test("describes a failure with no text nicely", () { | |
| 131 return runTest(() { | |
| 132 expect(() => new Future.value(), prints(contains("Goodbye"))); | |
| 133 }).then((liveTest) { | |
| 134 expectTestFailed(liveTest, startsWith( | |
| 135 "Expected: prints contains 'Goodbye'\n" | |
| 136 " Actual: <Closure: () => dynamic>\n" | |
| 137 " Which: printed nothing.")); | |
| 138 }); | |
| 139 }); | |
| 140 | |
| 141 test("won't let the test end until the Future completes", () { | |
| 142 return expectTestBlocks(() { | |
| 143 var completer = new Completer(); | |
| 144 expect(() => completer.future, prints(isEmpty)); | |
| 145 return completer; | |
| 146 }, (completer) => completer.complete()); | |
| 147 }); | |
| 148 }); | |
| 149 } | |
| OLD | NEW |