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

Side by Side Diff: tests/language_strong/assert_with_message_test.dart

Issue 2568313002: Implement messages in assert() in dev_compiler. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 import "package:expect/expect.dart";
6
7 main() {
8 var assertsEnabled = false;
9 assert((assertsEnabled = true));
10 if (!assertsEnabled) return;
11
12 // TODO(rnystrom): Test cases where the first argument to assert() is a
13 // function.
14
15 testAssertFails();
16 testAssertDoesNotFail();
17 testDoesNotEvaluateMessageIfAssertSucceeds();
18 testCallsToStringOnMessageLazily();
19 }
20
21 /// A class with a custom toString() that tracks when it is called.
22 class ToString {
23 bool calledToString = false;
24
25 String toString() {
26 calledToString = true;
27 return "toString!";
28 }
29 }
30
31 testAssertFails() {
32 try {
33 assert(false, "Oops");
34 Expect.fail("Assert should throw.");
35 } catch (e) {
36 Expect.isTrue(e.toString().contains("Oops"));
37 }
38 }
39
40 testAssertDoesNotFail() {
41 try {
42 assert(true, "Oops");
43 } catch (e) {
44 Expect.fail("Assert should not throw.");
45 }
46 }
47
48 testDoesNotEvaluateMessageIfAssertSucceeds() {
49 try {
50 var evaluated = false;
51 assert(true, evaluated = true);
52 Expect.isFalse(evaluated);
53 } catch (e) {
54 Expect.fail("Assert should not throw.");
55 }
56 }
57
58 testCallsToStringOnMessageLazily() {
59 var toString = new ToString();
60 try {
61 assert(false, toString);
62 Expect.fail("Assert should throw.");
63 } catch (e) {
64 Expect.isFalse(toString.calledToString);
65 Expect.isTrue(e.toString().contains("toString!"));
66 Expect.isTrue(toString.calledToString);
67 }
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698