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