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

Unified Diff: tests/language_strong/assert_with_message_test.dart

Issue 2568313002: Implement messages in assert() in dev_compiler. (Closed)
Patch Set: Format. Created 4 years 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
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/js_helper.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..878bd712627091f9300f30579c70df4939992358
--- /dev/null
+++ b/tests/language_strong/assert_with_message_test.dart
@@ -0,0 +1,88 @@
+// 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();
+ testNullMessage();
+ testDoesNotEvaluateMessageIfAssertSucceeds();
+ testMessageExpressionThatThrows();
+ 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.");
+ }
+}
+
+testNullMessage() {
+ try {
+ assert(false, null);
+ Expect.fail("Assert should throw.");
+ } catch (e) {
+ Expect.isTrue(e.toString().contains("null"));
+ }
+}
+
+testDoesNotEvaluateMessageIfAssertSucceeds() {
+ try {
+ var evaluated = false;
+ assert(true, evaluated = true);
+ Expect.isFalse(evaluated);
+ } catch (e) {
+ Expect.fail("Assert should not throw.");
+ }
+}
+
+testMessageExpressionThatThrows() {
+ try {
+ assert(false, throw "dang");
+ Expect.fail("Should throw");
+ } catch (e) {
+ Expect.equals(e, "dang");
+ }
+}
+
+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);
+ }
+}
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/js_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698