| Index: tests/language_strong/assert_with_message_test.dart
|
| diff --git a/tests/language_strong/assert_with_message_test.dart b/tests/language_strong/assert_with_message_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ccf676e0e1b2b66ee346bf34983c418bd5bc768e
|
| --- /dev/null
|
| +++ b/tests/language_strong/assert_with_message_test.dart
|
| @@ -0,0 +1,68 @@
|
| +// Copyright (c) 2016, 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 "package:expect/expect.dart";
|
| +
|
| +main() {
|
| + var assertsEnabled = false;
|
| + assert((assertsEnabled = true));
|
| + if (!assertsEnabled) return;
|
| +
|
| + // TODO(rnystrom): Test cases where the first argument to assert() is a
|
| + // function.
|
| +
|
| + testAssertFails();
|
| + testAssertDoesNotFail();
|
| + testDoesNotEvaluateMessageIfAssertSucceeds();
|
| + testCallsToStringOnMessageLazily();
|
| +}
|
| +
|
| +/// A class with a custom toString() that tracks when it is called.
|
| +class ToString {
|
| + bool calledToString = false;
|
| +
|
| + String toString() {
|
| + calledToString = true;
|
| + return "toString!";
|
| + }
|
| +}
|
| +
|
| +testAssertFails() {
|
| + try {
|
| + assert(false, "Oops");
|
| + Expect.fail("Assert should throw.");
|
| + } catch (e) {
|
| + Expect.isTrue(e.toString().contains("Oops"));
|
| + }
|
| +}
|
| +
|
| +testAssertDoesNotFail() {
|
| + try {
|
| + assert(true, "Oops");
|
| + } catch (e) {
|
| + Expect.fail("Assert should not throw.");
|
| + }
|
| +}
|
| +
|
| +testDoesNotEvaluateMessageIfAssertSucceeds() {
|
| + try {
|
| + var evaluated = false;
|
| + assert(true, evaluated = true);
|
| + Expect.isFalse(evaluated);
|
| + } catch (e) {
|
| + Expect.fail("Assert should not throw.");
|
| + }
|
| +}
|
| +
|
| +testCallsToStringOnMessageLazily() {
|
| + var toString = new ToString();
|
| + try {
|
| + assert(false, toString);
|
| + Expect.fail("Assert should throw.");
|
| + } catch (e) {
|
| + Expect.isFalse(toString.calledToString);
|
| + Expect.isTrue(e.toString().contains("toString!"));
|
| + Expect.isTrue(toString.calledToString);
|
| + }
|
| +}
|
|
|