Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2502)

Unified Diff: mojo/public/dart/third_party/test/test/frontend/matcher/throws_test.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/dart/third_party/test/test/frontend/matcher/throws_test.dart
diff --git a/mojo/public/dart/third_party/test/test/frontend/matcher/throws_test.dart b/mojo/public/dart/third_party/test/test/frontend/matcher/throws_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5b3e099aa0154795cce1fe40ea962e5e121032d7
--- /dev/null
+++ b/mojo/public/dart/third_party/test/test/frontend/matcher/throws_test.dart
@@ -0,0 +1,163 @@
+// Copyright (c) 2015, 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.
+
+import 'dart:async';
+
+import 'package:test/test.dart';
+
+import '../../utils.dart';
+
+void main() {
+ group("synchronous", () {
+ group("[throws]", () {
+ test("with a function that throws an error", () {
+ expect(() => throw 'oh no', throws);
+ });
+
+ test("with a function that doesn't throw", () async {
+ var closure = () {};
+ var liveTest = await runTestBody(() {
+ expect(closure, throws);
+ });
+
+ expectTestFailed(liveTest, allOf([
+ startsWith(
+ "Expected: throws\n"
+ " Actual: <"),
+ endsWith(">\n"
+ " Which: did not throw\n")
+ ]));
+ });
+
+ test("with a non-function", () async {
+ var liveTest = await runTestBody(() {
+ expect(10, throws);
+ });
+
+ expectTestFailed(liveTest,
+ "Expected: throws\n"
+ " Actual: <10>\n"
+ " Which: is not a Function or Future\n");
+ });
+ });
+
+ group("[throwsA]", () {
+ test("with a function that throws an identical error", () {
+ expect(() => throw 'oh no', throwsA('oh no'));
+ });
+
+ test("with a function that throws a matching error", () {
+ expect(() => throw new FormatException("bad"),
+ throwsA(isFormatException));
+ });
+
+ test("with a function that doesn't throw", () async {
+ var closure = () {};
+ var liveTest = await runTestBody(() {
+ expect(closure, throwsA('oh no'));
+ });
+
+ expectTestFailed(liveTest, allOf([
+ startsWith(
+ "Expected: throws 'oh no'\n"
+ " Actual: <"),
+ endsWith(">\n"
+ " Which: did not throw\n")
+ ]));
+ });
+
+ test("with a non-function", () async {
+ var liveTest = await runTestBody(() {
+ expect(10, throwsA('oh no'));
+ });
+
+ expectTestFailed(liveTest,
+ "Expected: throws 'oh no'\n"
+ " Actual: <10>\n"
+ " Which: is not a Function or Future\n");
+ });
+
+ test("with a function that throws the wrong error", () async {
+ var liveTest = await runTestBody(() {
+ expect(() => throw 'aw dang', throwsA('oh no'));
+ });
+
+ expectTestFailed(liveTest, allOf([
+ startsWith(
+ "Expected: throws 'oh no'\n"
+ " Actual: <"),
+ endsWith(">\n"
+ " Which: threw 'aw dang'\n")
+ ]));
+ });
+ });
+ });
+
+ group("asynchronous", () {
+ group("[throws]", () {
+ test("with a Future that throws an error", () {
+ expect(new Future.error('oh no'), throws);
+ });
+
+ test("with a Future that doesn't throw", () async {
+ var liveTest = await runTestBody(() {
+ expect(new Future.value(), throws);
+ });
+
+ expectTestFailed(liveTest,
+ "Expected future to fail, but succeeded with 'null'.");
+ });
+
+ test("won't let the test end until the Future completes", () {
+ return expectTestBlocks(() {
+ var completer = new Completer();
+ expect(completer.future, throws);
+ return completer;
+ }, (completer) => completer.completeError('oh no'));
+ });
+ });
+
+ group("[throwsA]", () {
+ test("with a Future that throws an identical error", () {
+ expect(new Future.error('oh no'), throwsA('oh no'));
+ });
+
+ test("with a Future that throws a matching error", () {
+ expect(new Future.error(new FormatException("bad")),
+ throwsA(isFormatException));
+ });
+
+ test("with a Future that doesn't throw", () async {
+ var liveTest = await runTestBody(() {
+ expect(new Future.value(), throwsA('oh no'));
+ });
+
+ expectTestFailed(liveTest,
+ "Expected future to fail, but succeeded with 'null'.");
+ });
+
+ test("with a Future that throws the wrong error", () async {
+ var liveTest = await runTestBody(() {
+ expect(new Future.error('aw dang'), throwsA('oh no'));
+ });
+
+ expectTestFailed(liveTest, allOf([
+ startsWith(
+ "Expected: throws 'oh no'\n"
+ " Actual: <"),
+ contains(">\n"
+ " Which: threw 'aw dang'\n")
+ ]));
+ });
+
+ test("won't let the test end until the Future completes", () {
+ return expectTestBlocks(() {
+ var completer = new Completer();
+ expect(completer.future, throwsA('oh no'));
+ return completer;
+ }, (completer) => completer.completeError('oh no'));
+ });
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698