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

Side by Side Diff: tests/compiler/dart2js_extra/assert_with_message_test.dart

Issue 1342213003: Add optional message to assert in Dart2js - continued (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add --assert-message flag 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 unified diff | Download patch
« no previous file with comments | « tests/compiler/dart2js/type_inference7_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 // SharedOptions=--assert-message
5
6 import "package:expect/expect.dart";
7
8 @AssumeDynamic() @NoInline()
9 confuse(x) => x;
10
11
12 testFalse(name, fault) {
13 try {
14 fault();
15 } catch (e) {
16 Expect.isTrue(e is AssertionError, '$name: is AssertionError');
17 Expect.isTrue('$e'.contains('Mumble'), '$name: <<$e>> contains "Mumble"');
18 return;
19 }
20 Expect.fail('Expected assert to throw');
21 }
22
23 test1() {
24 testFalse('constant false', () { assert(false, 'Mumble'); });
25 }
26
27 test2() {
28 testFalse('constant function', () { assert(() => false, 'Mumble'); });
29 }
30
31 test3() {
32 testFalse('variable false', () { assert(confuse(false), 'Mumble'); });
33 }
34
35 test4() {
36 testFalse('variable function',
37 () { assert(confuse(() => false), 'Mumble'); });
38 }
39
40 testTypeErrors() {
41 check(name, fault) {
42 try {
43 fault();
44 } catch (e) {
45 Expect.isTrue(e is TypeError,
46 'name: <<$e>> (${e.runtimeType}) is TypeError');
47 return;
48 }
49 Expect.fail('Expected assert to throw');
50 }
51
52 check('constant type error', () { assert(null, 'Mumble'); });
53 check('variable type error', () { assert(confuse(null), 'Mumble'); });
54 check('function type error', () { assert(confuse(() => null), 'Mumble'); });
55 }
56
57 testMessageEffect1() {
58 var v = 1;
59 // Message is not evaluated on succeeding assert.
60 assert(confuse(true), '${v = 123}');
61 Expect.equals(1, v);
62 }
63
64 testMessageEffect2() {
65 var v = 1;
66 try {
67 // Message is evaluated to produce AssertionError argument on failing
68 // assert.
69 assert(confuse(false), '${v = 123}');
70 } catch (e) {
71 Expect.equals(123, v);
72 Expect.isTrue('$e'.contains('123'), '<<$e>> contains "123"');
73 return;
74 }
75 Expect.fail('Expected assert to throw');
76 }
77
78 testMessageEffect3() {
79 var v = 1;
80 try {
81 // Message is evaluated to produce AssertionError argument on failing
82 // assert.
83 assert(confuse(() => ++v > 100), '${++v}');
84 } catch (e) {
85 Expect.equals(3, v);
86 Expect.isTrue('$e'.contains('3'), '<<$e>> contains "3"');
87 return;
88 }
89 Expect.fail('Expected assert to throw');
90 }
91
92 bool get checkedMode {
93 bool b = false;
94 assert((b = true));
95 return b;
96 }
97
98 main() {
99 if (!checkedMode) return;
100
101 test1();
102 test2();
103 test3();
104 test4();
105 testTypeErrors();
106 testMessageEffect1();
107 testMessageEffect2();
108 testMessageEffect3();
109 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/type_inference7_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698