Chromium Code Reviews| Index: pkg/matcher/test/prints_matcher_test.dart |
| diff --git a/pkg/matcher/test/prints_matcher_test.dart b/pkg/matcher/test/prints_matcher_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..183d4ef35b7a911aab37db8045c3c37efd4b8acb |
| --- /dev/null |
| +++ b/pkg/matcher/test/prints_matcher_test.dart |
| @@ -0,0 +1,104 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library matcher.prints_matchers_test; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:matcher/matcher.dart'; |
| +import 'package:unittest/unittest.dart'; |
| + |
| +import 'test_utils.dart'; |
| + |
| +void main() { |
| + initUtils(); |
| + |
| + group('synchronous', () { |
| + test("passes with an expected print", () { |
| + shouldPass(() => print("Hello, world!"), prints("Hello, world!\n")); |
| + }); |
| + |
| + test("combines multiple prints", () { |
| + shouldPass(() { |
| + print("Hello"); |
| + print("World!"); |
| + }, prints("Hello\nWorld!\n")); |
|
Bob Nystrom
2014/12/05 18:14:53
Are the line endings the same on Windows?
nweiz
2014/12/09 01:01:01
I think so. I figure it's easier to test on the bo
|
| + }); |
| + |
| + test("works with a Matcher", () { |
| + shouldPass(() => print("Hello, world!"), prints(contains("Hello"))); |
| + }); |
| + |
| + test("describes a failure nicely", () { |
| + shouldFail(() => print("Hello, world!"), prints("Goodbye, world!\n"), |
| + "Expected: prints 'Goodbye, world!\\n' ''" |
| + " Actual: <Closure: () => dynamic> " |
| + " Which: printed 'Hello, world!\\n' ''" |
| + " Which: is different. " |
| + "Expected: Goodbye, w ... " |
| + " Actual: Hello, wor ... " |
| + " ^ Differ at offset 0"); |
| + }); |
| + |
| + test("describes a failure with a non-descriptive Matcher nicely", () { |
| + shouldFail(() => print("Hello, world!"), prints(contains("Goodbye")), |
| + "Expected: prints contains 'Goodbye'" |
| + " Actual: <Closure: () => dynamic> " |
| + " Which: printed 'Hello, world!\\n' ''"); |
| + }); |
| + |
| + test("describes a failure with no text nicely", () { |
| + shouldFail(() {}, prints(contains("Goodbye")), |
| + "Expected: prints contains 'Goodbye'" |
| + " Actual: <Closure: () => dynamic> " |
| + " Which: printed nothing."); |
| + }); |
| + }); |
| + |
| + group('asynchronous', () { |
| + test("passes with an expected print", () { |
| + shouldPass(() => new Future(() => print("Hello, world!")), |
| + prints("Hello, world!\n")); |
| + }); |
| + |
| + test("combines multiple prints", () { |
| + shouldPass(() => new Future(() { |
| + print("Hello"); |
| + print("World!"); |
| + }), prints("Hello\nWorld!\n")); |
| + }); |
| + |
| + test("works with a Matcher", () { |
| + shouldPass(() => new Future(() => print("Hello, world!")), |
| + prints(contains("Hello"))); |
| + }); |
| + |
| + test("describes a failure nicely", () { |
| + shouldFail(() => new Future(() => print("Hello, world!")), |
| + prints("Goodbye, world!\n"), |
| + "Expected: 'Goodbye, world!\\n' ''" |
| + " Actual: 'Hello, world!\\n' ''" |
| + " Which: is different. " |
| + "Expected: Goodbye, w ... " |
| + " Actual: Hello, wor ... " |
| + " ^ Differ at offset 0", |
| + isAsync: true); |
| + }); |
| + |
| + test("describes a failure with a non-descriptive Matcher nicely", () { |
| + shouldFail(() => new Future(() => print("Hello, world!")), |
| + prints(contains("Goodbye")), |
| + "Expected: contains 'Goodbye'" |
| + " Actual: 'Hello, world!\\n' ''", |
| + isAsync: true); |
| + }); |
| + |
| + test("describes a failure with no text nicely", () { |
| + shouldFail(() => new Future.value(), prints(contains("Goodbye")), |
| + "Expected: contains 'Goodbye'" |
| + " Actual: ''", |
| + isAsync: true); |
| + }); |
| + }); |
| +} |