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

Side by Side Diff: pkg/fletchc/lib/src/message_examples.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: Created 4 years, 10 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
(Empty)
1 // Copyright (c) 2015, the Dartino 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.md file.
4
5 library fletchc.message_examples;
6
7 import 'messages.dart' show
8 DiagnosticKind;
9
10 /// According to
11 /// http://stackoverflow.com/questions/10456044/what-is-a-good-invalid-ip-addres s-to-use-for-unit-tests,
12 /// any IP address starting with 0 is unroutable.
13 const String invalidIP = '0.42.42.42';
14
15 const String invalidAddress = '$invalidIP:61366';
16
17 const String exampleAddress = 'example.com:54321';
18
19 const List<Example> untestable = const <Example>[const Untestable()];
20
21 List<Example> getExamples(DiagnosticKind kind) {
22 switch (kind) {
23 case DiagnosticKind.internalError:
24 return untestable;
25
26 case DiagnosticKind.verbRequiresNoSession:
27 return <Example>[
28 new CommandLineExample(
29 <String>['create', 'session', 'foo'],
30 <String>['create', 'session', 'bar', 'in', 'session', 'foo']),
31 new CommandLineExample(
32 <String>['create', 'session', 'foo'],
33 <String>['help', 'all', 'in', 'session', 'foo'])];
34
35 case DiagnosticKind.verbRequiresSessionTarget:
36 return <Example>[
37 new CommandLineExample(
38 <String>['create']),
39 new CommandLineExample(
40 <String>['x-end'])];
41
42 case DiagnosticKind.verbRequiresFileTarget:
43 return <Example>[new CommandLineExample(
44 <String>['create', 'session', 'foo'],
45 <String>['compile', 'session', 'foo', 'in', 'session', 'foo'])];
46
47 case DiagnosticKind.verbRequiresSocketTarget:
48 return <Example>[
49 new CommandLineExample(
50 <String>['create', 'session', 'foo'],
51 <String>['attach', 'in', 'session', 'foo', 'file', 'fisk']),
52 new CommandLineExample(
53 // Same as previous example, except with an implict file target.
54 <String>['create', 'session', 'foo'],
55 <String>['attach', 'in', 'session', 'foo', 'fisk.dart'])];
56
57 case DiagnosticKind.verbDoesNotSupportTarget:
58 return <Example>[new CommandLineExample(
59 <String>['create', 'session', 'foo'],
60 <String>['debug', 'sessions', 'in', 'session', 'foo'])];
61
62 case DiagnosticKind.noSuchSession:
63 return <Example>[
64 new CommandLineExample(
65 <String>['x-end', 'session', 'foo'])];
66
67 case DiagnosticKind.sessionAlreadyExists:
68 return <Example>[new CommandLineExample(
69 <String>['create', 'session', 'foo'],
70 <String>['create', 'session', 'foo'])];
71
72 case DiagnosticKind.sessionInvalidState:
73 // TODO(wibling): figure out a way to test this.
74 // Basically we need to have a fletch-vm that is
75 // explicitly attached to via 'fletch attach' and
76 // have it in a state where it has thrown an uncaught
77 // exception and then call e.g. 'fletch run foo.dart'.
78 return untestable;
79
80 case DiagnosticKind.noFileTarget:
81 return <Example>[
82 new CommandLineExample(
83 <String>['create', 'session', 'foo'],
84 <String>['compile', 'in', 'session', 'foo'])];
85
86 case DiagnosticKind.noTcpSocketTarget:
87 return <Example>[new CommandLineExample(
88 <String>['create', 'session', 'foo'],
89 <String>['attach', 'in', 'session', 'foo'])];
90
91 case DiagnosticKind.expectedAPortNumber:
92 return <Example>[
93 new CommandLineExample(
94 <String>['create', 'session', 'foo'],
95 <String>['attach', 'in', 'session', 'foo',
96 'tcp_socket', ':fisk']),
97
98 new CommandLineExample(
99 <String>['create', 'session', 'foo'],
100 <String>['attach', 'in', 'session', 'foo',
101 'tcp_socket', '$invalidIP:fisk'])];
102
103 case DiagnosticKind.noAgentFound:
104 // TODO(karlklose,268): We want to write a test similar to the following,
105 // but it records the error in the wrong isolate. We need a way to
106 // test this.
107 // return <Example>[new CommandLineExample(
108 // <String>['create', 'session', 'foo'],
109 // <String>['x-upgrade', 'agent',
110 // 'with', 'file', 'fletch-agent_v1_platform.deb',
111 // 'in', 'session', 'foo'
112 // ])];
113 return untestable;
114
115 case DiagnosticKind.upgradeInvalidPackageName:
116 // TODO(karlklose,268): We want to write a test similar to the following,
117 // but it records the error in the wrong isolate. We need a way to
118 // test this.
119 // return <Example>[new CommandLineExample(
120 // <String>['x-upgrade', 'agent', 'with', 'file',
121 // 'invalid-file-name'])];
122 return untestable;
123
124 case DiagnosticKind.socketAgentConnectError:
125 // TODO(wibling,268): figure out how to test fletch agent failures to
126 // exercise this error.
127 return untestable;
128
129 case DiagnosticKind.socketAgentReplyError:
130 // TODO(wibling,268): figure out how to test fletch agent failures to
131 // exercise this error.
132 return untestable;
133
134 case DiagnosticKind.socketVmConnectError:
135 return <Example>[new CommandLineExample(
136 <String>['create', 'session', 'foo'],
137 <String>['attach', 'in', 'session', 'foo',
138 'tcp_socket', invalidAddress])];
139
140 case DiagnosticKind.socketVmReplyError:
141 // TODO(wibling): figure out how to simulate fletch vm failures to
142 // exercise this error.
143 return untestable;
144
145 case DiagnosticKind.attachToVmBeforeRun:
146 return <Example>[
147 new CommandLineExample(
148 <String>['create', 'session', 'foo'],
149 <String>['debug', 'in', 'session', 'foo']),
150 new CommandLineExample(
151 <String>['create', 'session', 'foo'],
152 <String>['debug', 'run-to-main', 'in', 'session', 'foo']),
153 new CommandLineExample(
154 <String>['create', 'session', 'foo'],
155 <String>['debug', 'backtrace', 'in', 'session', 'foo'])];
156
157 case DiagnosticKind.compileBeforeRun:
158 var examples = <Example>[
159 new CommandLineExample(
160 <String>['create', 'session', 'foo'],
161 <String>['attach', 'in', 'session', 'foo',
162 'tcp_socket', exampleAddress],
163 <String>['debug', 'in', 'session', 'foo']),
164 new CommandLineExample(
165 <String>['create', 'session', 'foo'],
166 <String>['attach', 'in', 'session', 'foo',
167 'tcp_socket', exampleAddress],
168 <String>['debug', 'attach', 'in', 'session', 'foo'])];
169 // TODO(ahe): Need to mock up a VM socket to test this. But hopefully
170 // we'll get rid of this message before then, most commands should
171 // support auto-compiling.
172 return untestable;
173
174 case DiagnosticKind.missingToFile:
175 return <Example>[
176 new CommandLineExample(
177 <String>['export'])];
178
179 case DiagnosticKind.missingSessionName:
180 return <Example>[new CommandLineExample(
181 <String>['create', 'session'])];
182
183 case DiagnosticKind.unknownOption:
184 return <Example>[
185 new CommandLineExample(<String>['help', '--fisk']),
186 new CommandLineExample(<String>['--compile-and-run', 'test.dart'])];
187
188 case DiagnosticKind.unsupportedPlatform:
189 return untestable;
190
191 case DiagnosticKind.missingRequiredArgument:
192 return <Example>[new CommandLineExample(
193 <String>['run', '--test-debugger'])];
194
195 case DiagnosticKind.unexpectedArgument:
196 return <Example>[new CommandLineExample(
197 <String>['help', '--version=fisk'])];
198
199 case DiagnosticKind.settingsCompileTimeConstantAsOption:
200 return <Example>[new SettingsExample('{"options":["-Dfoo=bar"]}')];
201
202 case DiagnosticKind.settingsConstantsNotAMap:
203 return <Example>[new SettingsExample('{"constants":[]}')];
204
205 case DiagnosticKind.settingsNotAMap:
206 return <Example>[
207 new SettingsExample('""'),
208 new SettingsExample('null'),
209 new SettingsExample('1'),
210 new SettingsExample('[]')];
211
212 case DiagnosticKind.settingsNotJson:
213 return <Example>[
214 new SettingsExample(''),
215 new SettingsExample('{1:null}'),
216 new SettingsExample('...')];
217
218 case DiagnosticKind.settingsOptionNotAString:
219 return <Example>[new SettingsExample('{"options":[1]}')];
220
221 case DiagnosticKind.settingsOptionsNotAList:
222 return <Example>[new SettingsExample('{"options":1}')];
223
224 case DiagnosticKind.settingsPackagesNotAString:
225 return <Example>[new SettingsExample('{"packages":1}')];
226
227 case DiagnosticKind.settingsUnrecognizedConstantValue:
228 return <Example>[new SettingsExample('{"constants":{"key": []}}')];
229
230 case DiagnosticKind.settingsUnrecognizedKey:
231 return <Example>[new SettingsExample('{"fisk":null}')];
232
233 case DiagnosticKind.settingsDeviceAddressNotAString:
234 return <Example>[new SettingsExample('{"device_address":1}')];
235
236 case DiagnosticKind.settingsDeviceTypeNotAString:
237 return <Example>[new SettingsExample('{"device_type":1}')];
238
239 case DiagnosticKind.settingsDeviceTypeUnrecognized:
240 return <Example>[new SettingsExample('{"device_type":"fisk"}')];
241
242 case DiagnosticKind.settingsIncrementalModeNotAString:
243 return <Example>[new SettingsExample('{"incremental_mode":1}')];
244
245 case DiagnosticKind.settingsIncrementalModeUnrecognized:
246 return <Example>[new SettingsExample('{"incremental_mode":"fisk"}')];
247
248 case DiagnosticKind.unknownAction:
249 return <Example>[
250 new CommandLineExample(<String>['blah']),
251 new CommandLineExample(<String>['test.dart'])];
252
253 case DiagnosticKind.extraArguments:
254 return <Example>[
255 new CommandLineExample(<String>['create', 'fisk']),
256 new CommandLineExample(<String>['x-upgrade', 'hest']),
257 ];
258
259 case DiagnosticKind.cantPerformVerbIn:
260 return <Example>[
261 new CommandLineExample(<String>['create', 'in', 'classes'])];
262
263 case DiagnosticKind.cantPerformVerbTo:
264 return <Example>[
265 new CommandLineExample(<String>['create', 'to', 'classes'])];
266
267 case DiagnosticKind.cantPerformVerbWith:
268 return <Example>[
269 new CommandLineExample(<String>['create', 'with', 'classes'])];
270
271 case DiagnosticKind.duplicatedIn:
272 return <Example>[new CommandLineExample(
273 <String>['run', 'in', 'session', 'foo', 'in', 'session', 'foo'])];
274
275 case DiagnosticKind.duplicatedTo:
276 return <Example>[new CommandLineExample(
277 <String>['export', 'to', 'foo.dart', 'to', 'foo.dart'])];
278
279 case DiagnosticKind.duplicatedWith:
280 return <Example>[new CommandLineExample(
281 <String>['create', 'with', 'foo.txt', 'with', 'foo.txt'])];
282
283 case DiagnosticKind.verbDoesntSupportTarget:
284 // Though the quit verb is not a real verb it can still be used to provoke
285 // this failure as part of sentence parsing.
286 return <Example>[new CommandLineExample(
287 <String>['quit', 'foo.txt'])];
288
289 case DiagnosticKind.verbRequiresNoToFile:
290 // Though the quit verb is not a real verb it can still be used to provoke
291 // this failure as part of sentence parsing.
292 return <Example>[
293 new CommandLineExample(
294 <String>['quit', 'to', 'foo.txt']),
295 new CommandLineExample(
296 <String>['x-upgrade', 'agent', 'foo.txt']),
297 ];
298
299 case DiagnosticKind.verbRequiresNoWithFile:
300 // Though the quit verb is not a real verb it can still be used to provoke
301 // this failure as part of sentence parsing.
302 return <Example>[new CommandLineExample(
303 <String>['quit', 'with', 'foo.txt'])];
304
305 case DiagnosticKind.verbRequiresTarget:
306 return <Example>[new CommandLineExample(
307 <String>['show'])];
308
309 case DiagnosticKind.verbRequiresSpecificTarget:
310 return <Example>[new CommandLineExample(
311 <String>['x-upgrade'])];
312
313 case DiagnosticKind.verbRequiresSpecificTargetButGot:
314 return <Example>[new CommandLineExample(
315 <String>['x-upgrade', 'file', 'foo'])];
316
317 case DiagnosticKind.expectedTargetButGot:
318 return <Example>[new CommandLineExample(
319 <String>['export', 'hello.dart', 'to', 'hello'])];
320
321 case DiagnosticKind.quitTakesNoArguments:
322 return <Example>[new CommandLineExample(<String>['quit', '-v'])];
323
324 case DiagnosticKind.illegalDefine:
325 return <Example>[new CommandLineExample(<String>['-Dfoo=1=2', 'run'])];
326
327 case DiagnosticKind.busySession:
328 // TODO(ahe): Add test for this.
329 return untestable;
330
331 case DiagnosticKind.terminatedSession:
332 // TODO(ahe): Add test for this.
333 return untestable;
334
335 case DiagnosticKind.handShakeFailed:
336 // TODO(ager): We could probably test this with a mock VM.
337 return untestable;
338
339 case DiagnosticKind.versionMismatch:
340 // TODO(ager): We could probably test this with a mock VM.
341 return untestable;
342
343 case DiagnosticKind.agentVersionMismatch:
344 // TODO(wibling): Add test for this
345 return untestable;
346
347 case DiagnosticKind.compilerVersionMismatch:
348 // TODO(wibling): Add test for this
349 return untestable;
350 }
351 }
352
353 abstract class Example {
354 const Example();
355 }
356
357 class CommandLineExample extends Example {
358 final List<String> line1;
359
360 final List<String> line2;
361
362 final List<String> line3;
363
364 const CommandLineExample(this.line1, [this.line2, this.line3]);
365 }
366
367 class SettingsExample extends Example {
368 final String data;
369
370 const SettingsExample(this.data);
371 }
372
373 class Untestable extends Example {
374 const Untestable();
375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698