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