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

Side by Side Diff: tests/compiler/dart2js/js_spec_string_test.dart

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Unit test of the [NativeBehavior.processSpecString] method. 5 // Unit test of the [NativeBehavior.processSpecString] method.
6 6
7 import 'package:expect/expect.dart'; 7 import 'package:expect/expect.dart';
8 import 'package:compiler/src/native/native.dart'; 8 import 'package:compiler/src/native/native.dart';
9 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; 9 import 'package:compiler/src/diagnostics/diagnostic_listener.dart';
10 import 'package:compiler/src/diagnostics/messages.dart'; 10 import 'package:compiler/src/diagnostics/messages.dart';
11 import 'package:compiler/src/universe/side_effects.dart' 11 import 'package:compiler/src/universe/side_effects.dart' show SideEffects;
12 show SideEffects;
13 12
14 const OBJECT = 'Object'; 13 const OBJECT = 'Object';
15 const NULL = 'Null'; 14 const NULL = 'Null';
16 15
17 class Listener extends DiagnosticReporter { 16 class Listener extends DiagnosticReporter {
18 String errorMessage; 17 String errorMessage;
19 internalError(spannable, message) { 18 internalError(spannable, message) {
20 errorMessage = message; 19 errorMessage = message;
21 throw "error"; 20 throw "error";
22 } 21 }
23 22
24 reportError(message, [infos = const <DiagnosticMessage>[]]) { 23 reportError(message, [infos = const <DiagnosticMessage>[]]) {
25 errorMessage = 24 errorMessage =
26 '${message.message.arguments}'; // E.g. "{text: Duplicate tag 'new'.}" 25 '${message.message.arguments}'; // E.g. "{text: Duplicate tag 'new'.}"
27 throw "error"; 26 throw "error";
28 } 27 }
29 28
30 @override 29 @override
31 DiagnosticMessage createMessage(spannable, messageKind, 30 DiagnosticMessage createMessage(spannable, messageKind,
32 [arguments = const {}]) { 31 [arguments = const {}]) {
33 return new DiagnosticMessage(null, spannable, 32 return new DiagnosticMessage(null, spannable,
34 MessageTemplate.TEMPLATES[messageKind].message(arguments)); 33 MessageTemplate.TEMPLATES[messageKind].message(arguments));
35 } 34 }
36 35
37 noSuchMethod(_) => null; 36 noSuchMethod(_) => null;
38 } 37 }
39 38
40 void test(String specString, 39 void test(String specString,
41 {List returns, 40 {List returns,
42 List creates, 41 List creates,
43 SideEffects expectedSideEffects, 42 SideEffects expectedSideEffects,
44 NativeThrowBehavior expectedThrows, 43 NativeThrowBehavior expectedThrows,
45 bool expectedNew, 44 bool expectedNew,
46 bool expectedGvn, 45 bool expectedGvn,
47 bool expectError: false}) { 46 bool expectError: false}) {
48 List actualReturns = []; 47 List actualReturns = [];
49 List actualCreates = []; 48 List actualCreates = [];
50 SideEffects actualSideEffects; 49 SideEffects actualSideEffects;
51 NativeThrowBehavior actualThrows; 50 NativeThrowBehavior actualThrows;
52 bool actualNew; 51 bool actualNew;
53 bool actualGvn; 52 bool actualGvn;
54 Listener listener = new Listener(); 53 Listener listener = new Listener();
55 try { 54 try {
56 NativeBehavior.processSpecString( 55 NativeBehavior.processSpecString(listener, null, specString,
57 listener, 56 setSideEffects: (effects) => actualSideEffects = effects,
58 null, 57 setThrows: (b) => actualThrows = b,
59 specString, 58 setIsAllocation: (b) => actualNew = b,
60 setSideEffects: (effects) { actualSideEffects = effects; }, 59 setUseGvn: (b) => actualGvn = b,
61 setThrows: (b) { actualThrows = b; },
62 setIsAllocation: (b) { actualNew = b; },
63 setUseGvn: (b) { actualGvn = b; },
64 resolveType: (t) => t, 60 resolveType: (t) => t,
65 typesReturned: actualReturns, typesInstantiated: actualCreates, 61 typesReturned: actualReturns,
66 objectType: OBJECT, nullType: NULL); 62 typesInstantiated: actualCreates,
63 objectType: OBJECT,
64 nullType: NULL);
67 } catch (e) { 65 } catch (e) {
68 Expect.isTrue(expectError, 'Unexpected error "$specString"'); 66 Expect.isTrue(expectError, 'Unexpected error "$specString"');
69 Expect.isNotNull(listener.errorMessage, 'Error message expected.'); 67 Expect.isNotNull(listener.errorMessage, 'Error message expected.');
70 return; 68 return;
71 } 69 }
72 Expect.isFalse(expectError, 'Missing error for "$specString".'); 70 Expect.isFalse(expectError, 'Missing error for "$specString".');
73 Expect.isNull(listener.errorMessage, 'Unexpected error.'); 71 Expect.isNull(listener.errorMessage, 'Unexpected error.');
74 if (returns != null) { 72 if (returns != null) {
75 Expect.listEquals(returns, actualReturns, 'Unexpected returns.'); 73 Expect.listEquals(returns, actualReturns, 'Unexpected returns.');
76 } 74 }
77 if (creates != null) { 75 if (creates != null) {
78 Expect.listEquals(creates, actualCreates, 'Unexpected creates.'); 76 Expect.listEquals(creates, actualCreates, 'Unexpected creates.');
79 } 77 }
80 Expect.equals(expectedSideEffects, actualSideEffects); 78 Expect.equals(expectedSideEffects, actualSideEffects);
81 Expect.equals(expectedThrows, actualThrows); 79 Expect.equals(expectedThrows, actualThrows);
82 Expect.equals(expectedNew, actualNew); 80 Expect.equals(expectedNew, actualNew);
83 Expect.equals(expectedGvn, actualGvn); 81 Expect.equals(expectedGvn, actualGvn);
84 } 82 }
85 83
86 void testWithSideEffects(String specString, 84 void testWithSideEffects(String specString,
87 {List returns, 85 {List returns, List creates, bool expectError: false}) {
88 List creates,
89 bool expectError: false}) {
90
91 void sideEffectsTest(String newSpecString, SideEffects expectedSideEffects, 86 void sideEffectsTest(String newSpecString, SideEffects expectedSideEffects,
92 {bool sideEffectsExpectError}) { 87 {bool sideEffectsExpectError}) {
93 test(newSpecString, 88 test(newSpecString,
94 returns: returns, 89 returns: returns,
95 creates: creates, 90 creates: creates,
96 expectedSideEffects: expectedSideEffects, 91 expectedSideEffects: expectedSideEffects,
97 expectError: sideEffectsExpectError == null 92 expectError: sideEffectsExpectError == null
98 ? expectError 93 ? expectError
99 : sideEffectsExpectError); 94 : sideEffectsExpectError);
100 } 95 }
101 96
102 SideEffects emptySideEffects = new SideEffects.empty(); 97 SideEffects emptySideEffects = new SideEffects.empty();
103 sideEffectsTest(specString + "effects:none;depends:none;", 98 sideEffectsTest(specString + "effects:none;depends:none;", emptySideEffects);
104 emptySideEffects); 99 sideEffectsTest(specString + "depends:none;effects:none;", emptySideEffects);
105 sideEffectsTest(specString + "depends:none;effects:none;", 100 sideEffectsTest("effects:none;depends:none;" + specString, emptySideEffects);
106 emptySideEffects); 101 sideEffectsTest("depends:none;effects:none;" + specString, emptySideEffects);
107 sideEffectsTest("effects:none;depends:none;" + specString,
108 emptySideEffects);
109 sideEffectsTest("depends:none;effects:none;" + specString,
110 emptySideEffects);
111 102
112 SideEffects effects = new SideEffects(); 103 SideEffects effects = new SideEffects();
113 effects.clearChangesIndex(); 104 effects.clearChangesIndex();
114 effects.clearAllDependencies(); 105 effects.clearAllDependencies();
115 sideEffectsTest(specString + "effects:no-index;depends:none;", effects); 106 sideEffectsTest(specString + "effects:no-index;depends:none;", effects);
116 107
117 effects = new SideEffects(); 108 effects = new SideEffects();
118 effects.clearAllSideEffects(); 109 effects.clearAllSideEffects();
119 effects.clearDependsOnIndexStore(); 110 effects.clearDependsOnIndexStore();
120 sideEffectsTest(specString + "effects:none;depends:no-index;", effects); 111 sideEffectsTest(specString + "effects:none;depends:no-index;", effects);
121 112
122 effects = new SideEffects(); 113 effects = new SideEffects();
123 effects.clearChangesInstanceProperty(); 114 effects.clearChangesInstanceProperty();
124 effects.clearChangesStaticProperty(); 115 effects.clearChangesStaticProperty();
125 effects.clearAllDependencies(); 116 effects.clearAllDependencies();
126 sideEffectsTest(specString + "effects:no-instance,no-static;depends:none;", 117 sideEffectsTest(
127 effects); 118 specString + "effects:no-instance,no-static;depends:none;", effects);
128 119
129 effects = new SideEffects(); 120 effects = new SideEffects();
130 effects.clearAllSideEffects(); 121 effects.clearAllSideEffects();
131 effects.clearDependsOnInstancePropertyStore(); 122 effects.clearDependsOnInstancePropertyStore();
132 effects.clearDependsOnStaticPropertyStore(); 123 effects.clearDependsOnStaticPropertyStore();
133 sideEffectsTest(specString + "effects:none;depends:no-instance,no-static;", 124 sideEffectsTest(
134 effects); 125 specString + "effects:none;depends:no-instance,no-static;", effects);
135 126
136 effects = new SideEffects(); 127 effects = new SideEffects();
137 effects.clearChangesInstanceProperty(); 128 effects.clearChangesInstanceProperty();
138 effects.clearChangesStaticProperty(); 129 effects.clearChangesStaticProperty();
139 effects.clearDependsOnIndexStore(); 130 effects.clearDependsOnIndexStore();
140 sideEffectsTest( 131 sideEffectsTest(
141 specString + "effects:no-instance,no-static;depends:no-index;", effects); 132 specString + "effects:no-instance,no-static;depends:no-index;", effects);
142 133
143 effects = new SideEffects(); 134 effects = new SideEffects();
144 effects.clearChangesIndex(); 135 effects.clearChangesIndex();
145 effects.clearDependsOnInstancePropertyStore(); 136 effects.clearDependsOnInstancePropertyStore();
146 effects.clearDependsOnStaticPropertyStore(); 137 effects.clearDependsOnStaticPropertyStore();
147 sideEffectsTest( 138 sideEffectsTest(
148 specString + "effects:no-index;depends:no-instance,no-static;", effects); 139 specString + "effects:no-index;depends:no-instance,no-static;", effects);
149 140
150 effects = new SideEffects(); 141 effects = new SideEffects();
151 effects.clearChangesIndex(); 142 effects.clearChangesIndex();
152 sideEffectsTest(specString + "effects:no-index;depends:all;", effects); 143 sideEffectsTest(specString + "effects:no-index;depends:all;", effects);
153 144
154 effects = new SideEffects(); 145 effects = new SideEffects();
155 effects.clearDependsOnIndexStore(); 146 effects.clearDependsOnIndexStore();
156 sideEffectsTest(specString + "effects:all;depends:no-index;", effects); 147 sideEffectsTest(specString + "effects:all;depends:no-index;", effects);
157 148
158 effects = new SideEffects(); 149 effects = new SideEffects();
159 effects.clearChangesInstanceProperty(); 150 effects.clearChangesInstanceProperty();
160 effects.clearChangesStaticProperty(); 151 effects.clearChangesStaticProperty();
161 sideEffectsTest(specString + "effects:no-instance,no-static;depends:all;", 152 sideEffectsTest(
162 effects); 153 specString + "effects:no-instance,no-static;depends:all;", effects);
163 154
164 effects = new SideEffects(); 155 effects = new SideEffects();
165 effects.clearDependsOnInstancePropertyStore(); 156 effects.clearDependsOnInstancePropertyStore();
166 effects.clearDependsOnStaticPropertyStore(); 157 effects.clearDependsOnStaticPropertyStore();
167 sideEffectsTest(specString + "effects:all;depends:no-instance,no-static;", 158 sideEffectsTest(
168 effects); 159 specString + "effects:all;depends:no-instance,no-static;", effects);
169 160
170 sideEffectsTest(specString + "effects:no-instance,no-static;", 161 sideEffectsTest(specString + "effects:no-instance,no-static;", effects,
171 effects, 162 sideEffectsExpectError: true);
172 sideEffectsExpectError: true);
173 163
174 sideEffectsTest(specString + "depends:no-instance,no-static;", 164 sideEffectsTest(specString + "depends:no-instance,no-static;", effects,
175 effects, 165 sideEffectsExpectError: true);
176 sideEffectsExpectError: true);
177 166
178 sideEffectsTest(specString + "effects:none;", 167 sideEffectsTest(specString + "effects:none;", effects,
179 effects, 168 sideEffectsExpectError: true);
180 sideEffectsExpectError: true);
181 169
182 sideEffectsTest(specString + "depends:all;", 170 sideEffectsTest(specString + "depends:all;", effects,
183 effects, 171 sideEffectsExpectError: true);
184 sideEffectsExpectError: true);
185 172
186 sideEffectsTest(specString + "effects:no-instance,no-static;depends:foo;", 173 sideEffectsTest(
187 effects, 174 specString + "effects:no-instance,no-static;depends:foo;", effects,
188 sideEffectsExpectError: true); 175 sideEffectsExpectError: true);
189 176
190 sideEffectsTest(specString + "effects:foo;depends:no-instance,no-static;", 177 sideEffectsTest(
191 effects, 178 specString + "effects:foo;depends:no-instance,no-static;", effects,
192 sideEffectsExpectError: true); 179 sideEffectsExpectError: true);
193 180
194 sideEffectsTest(specString + "effects:all;depends:foo", 181 sideEffectsTest(specString + "effects:all;depends:foo", effects,
195 effects, 182 sideEffectsExpectError: true);
196 sideEffectsExpectError: true);
197 183
198 sideEffectsTest(specString + "effects:foo;depends:none;", 184 sideEffectsTest(specString + "effects:foo;depends:none;", effects,
199 effects, 185 sideEffectsExpectError: true);
200 sideEffectsExpectError: true);
201 186
202 sideEffectsTest(specString + "effects:;depends:none;", 187 sideEffectsTest(specString + "effects:;depends:none;", effects,
203 effects, 188 sideEffectsExpectError: true);
204 sideEffectsExpectError: true);
205 189
206 sideEffectsTest(specString + "effects:all;depends:;", 190 sideEffectsTest(specString + "effects:all;depends:;", effects,
207 effects, 191 sideEffectsExpectError: true);
208 sideEffectsExpectError: true);
209 } 192 }
210 193
211 void main() { 194 void main() {
212 test('void', returns: [], creates: []); 195 test('void', returns: [], creates: []);
213 test('', returns: [OBJECT, NULL], creates: []); 196 test('', returns: [OBJECT, NULL], creates: []);
214 test('var', returns: [OBJECT, NULL], creates: []); 197 test('var', returns: [OBJECT, NULL], creates: []);
215 test('A', returns: ['A'], creates: ['A']); 198 test('A', returns: ['A'], creates: ['A']);
216 test('A|B', returns: ['A', 'B'], creates: ['A', 'B']); 199 test('A|B', returns: ['A', 'B'], creates: ['A', 'B']);
217 test('A|B|C', returns: ['A', 'B', 'C'], creates: ['A', 'B', 'C']); 200 test('A|B|C', returns: ['A', 'B', 'C'], creates: ['A', 'B', 'C']);
218 201
(...skipping 16 matching lines...) Expand all
235 test('returns:var;creates:', returns: [OBJECT, NULL], creates: []); 218 test('returns:var;creates:', returns: [OBJECT, NULL], creates: []);
236 test('returns:A;creates:', returns: ['A'], creates: []); 219 test('returns:A;creates:', returns: ['A'], creates: []);
237 test('returns:A|B;creates:;', returns: ['A', 'B'], creates: []); 220 test('returns:A|B;creates:;', returns: ['A', 'B'], creates: []);
238 test('returns:A|B|C;creates:;', returns: ['A', 'B', 'C'], creates: []); 221 test('returns:A|B|C;creates:;', returns: ['A', 'B', 'C'], creates: []);
239 222
240 test('returns:void;creates:A;', returns: [], creates: ['A']); 223 test('returns:void;creates:A;', returns: [], creates: ['A']);
241 test('returns:;creates:A|B;', returns: [OBJECT, NULL], creates: ['A', 'B']); 224 test('returns:;creates:A|B;', returns: [OBJECT, NULL], creates: ['A', 'B']);
242 test('returns:var;creates:A|B|C;', 225 test('returns:var;creates:A|B|C;',
243 returns: [OBJECT, NULL], creates: ['A', 'B', 'C']); 226 returns: [OBJECT, NULL], creates: ['A', 'B', 'C']);
244 test('returns:A; creates:A|B|C; ', returns: ['A'], creates: ['A', 'B', 'C']); 227 test('returns:A; creates:A|B|C; ', returns: ['A'], creates: ['A', 'B', 'C']);
245 test(' returns:A|B; creates:A|C;', 228 test(' returns:A|B; creates:A|C;', returns: ['A', 'B'], creates: ['A', 'C']);
246 returns: ['A', 'B'], creates: ['A', 'C']);
247 test(' returns:A|B|C; creates:A; ', 229 test(' returns:A|B|C; creates:A; ',
248 returns: ['A', 'B', 'C'], creates: ['A']); 230 returns: ['A', 'B', 'C'], creates: ['A']);
249 231
250 testWithSideEffects('returns:void;', returns: [], creates: []); 232 testWithSideEffects('returns:void;', returns: [], creates: []);
251 testWithSideEffects('returns:void;', returns: [], creates: []); 233 testWithSideEffects('returns:void;', returns: [], creates: []);
252 testWithSideEffects('returns:;', returns: [OBJECT, NULL], creates: []); 234 testWithSideEffects('returns:;', returns: [OBJECT, NULL], creates: []);
253 testWithSideEffects('returns:var;', returns: [OBJECT, NULL], creates: []); 235 testWithSideEffects('returns:var;', returns: [OBJECT, NULL], creates: []);
254 testWithSideEffects('returns:A;', returns: ['A'], creates: ['A']); 236 testWithSideEffects('returns:A;', returns: ['A'], creates: ['A']);
255 testWithSideEffects('returns:A|B;', 237 testWithSideEffects('returns:A|B;', returns: ['A', 'B'], creates: ['A', 'B']);
256 returns: ['A', 'B'], creates: ['A', 'B']);
257 testWithSideEffects('returns:A|B|C;', 238 testWithSideEffects('returns:A|B|C;',
258 returns: ['A', 'B', 'C'], creates: ['A', 'B', 'C']); 239 returns: ['A', 'B', 'C'], creates: ['A', 'B', 'C']);
259 testWithSideEffects('returns: A| B |C ;', 240 testWithSideEffects('returns: A| B |C ;',
260 returns: ['A', 'B', 'C'], creates: ['A', 'B', 'C']); 241 returns: ['A', 'B', 'C'], creates: ['A', 'B', 'C']);
261 242
262 testWithSideEffects('creates:void;', expectError: true); 243 testWithSideEffects('creates:void;', expectError: true);
263 testWithSideEffects('creates:;', creates: []); 244 testWithSideEffects('creates:;', creates: []);
264 testWithSideEffects('creates:var;', creates: []); 245 testWithSideEffects('creates:var;', creates: []);
265 testWithSideEffects('creates:A;', returns: [], creates: ['A']); 246 testWithSideEffects('creates:A;', returns: [], creates: ['A']);
266 testWithSideEffects('creates:A|B;', returns: [], creates: ['A', 'B']); 247 testWithSideEffects('creates:A|B;', returns: [], creates: ['A', 'B']);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 test('gvn:false', expectedGvn: false); 287 test('gvn:false', expectedGvn: false);
307 test('returns:A;gvn:true', returns: ['A'], expectedGvn: true); 288 test('returns:A;gvn:true', returns: ['A'], expectedGvn: true);
308 test(' gvn : true ; returns:A;', returns: ['A'], expectedGvn: true); 289 test(' gvn : true ; returns:A;', returns: ['A'], expectedGvn: true);
309 test('gvn:true;returns:A;gvn:true', expectError: true); 290 test('gvn:true;returns:A;gvn:true', expectError: true);
310 291
311 test('gvn: true; new: true', expectError: true); 292 test('gvn: true; new: true', expectError: true);
312 test('gvn: true; new: false', expectedGvn: true, expectedNew: false); 293 test('gvn: true; new: false', expectedGvn: true, expectedNew: false);
313 test('gvn: false; new: true', expectedGvn: false, expectedNew: true); 294 test('gvn: false; new: true', expectedGvn: false, expectedNew: true);
314 test('gvn: false; new: false', expectedGvn: false, expectedNew: false); 295 test('gvn: false; new: false', expectedGvn: false, expectedNew: false);
315 } 296 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/js_spec_optimization_test.dart ('k') | tests/compiler/dart2js/js_throw_behavior_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698