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

Side by Side Diff: runtime/observatory/tests/service/command_test.dart

Issue 2759973004: Fix observatory tests broken by running dartfmt. Temporarily reverted formatting for evaluate_activ… (Closed)
Patch Set: Created 3 years, 9 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) 2015, the Dart project authors. Please see the AUTHORS file 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 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 // VMOptions=--error_on_bad_type --error_on_bad_override 4 // VMOptions=--error_on_bad_type --error_on_bad_override
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 7
8 import 'package:observatory/cli.dart'; 8 import 'package:observatory/cli.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 17 matching lines...) Expand all
28 possibles.where((possible) => possible.startsWith(args[0])).toList()); 28 possibles.where((possible) => possible.startsWith(args[0])).toList());
29 } 29 }
30 30
31 Future run(List<String> args) { 31 Future run(List<String> args) {
32 out.write('executing ${name}(${args})\n'); 32 out.write('executing ${name}(${args})\n');
33 return new Future.value(null); 33 return new Future.value(null);
34 } 34 }
35 } 35 }
36 36
37 void testCommandComplete() { 37 void testCommandComplete() {
38 RootCommand cmd = 38 RootCommand cmd = new RootCommand([
39 new RootCommand([new TestCommand(null, 'alpha', []), 39 new TestCommand(null, 'alpha', []),
40 40 new TestCommand(null, 'game', [
41 new TestCommand(null, 'game', [ 41 new TestCommand(null, 'checkers', []),
42 new TestCommand(null, 'checkers', []), 42 new TestCommand(null, 'chess', [])
43 new TestCommand(null, 'chess', [])]), 43 ]),
44 44 new TestCommand(null, 'gamera', [
45 new TestCommand(null, 'gamera', [ 45 new TestCommand(null, 'london', []),
46 new TestCommand(null, 'london', []), 46 new TestCommand(null, 'tokyo', []),
47 new TestCommand(null, 'tokyo', []), 47 new TestCommand(null, 'topeka', [])
48 new TestCommand(null, 'topeka', [])]), 48 ]),
49 49 new TestCompleteCommand(
50 new TestCompleteCommand(null, 'count', [ 50 null, 'count', [new TestCommand(null, 'chocula', [])])
51 new TestCommand(null, 'chocula', [])])]); 51 ]);
52 52
53 // Show all commands. 53 // Show all commands.
54 cmd.completeCommand('').then((result) { 54 cmd.completeCommand('').then((result) {
55 expect(result, equals(['alpha ', 'game ', 'gamera ', 'count '])); 55 expect(result, equals(['alpha ', 'game ', 'gamera ', 'count ']));
56 }); 56 });
57 57
58 // Substring completion. 58 // Substring completion.
59 cmd.completeCommand('al').then((result) { 59 cmd.completeCommand('al').then((result) {
60 expect(result, equals(['alpha '])); 60 expect(result, equals(['alpha ']));
61 }); 61 });
(...skipping 13 matching lines...) Expand all
75 expect(result, equals(['game ', 'gamera '])); 75 expect(result, equals(['game ', 'gamera ']));
76 }); 76 });
77 77
78 // Ambiguous completion, exact match not preferred. 78 // Ambiguous completion, exact match not preferred.
79 cmd.completeCommand('game').then((result) { 79 cmd.completeCommand('game').then((result) {
80 expect(result, equals(['game ', 'gamera '])); 80 expect(result, equals(['game ', 'gamera ']));
81 }); 81 });
82 82
83 // Show all subcommands. 83 // Show all subcommands.
84 cmd.completeCommand('gamera ').then((result) { 84 cmd.completeCommand('gamera ').then((result) {
85 expect(result, equals(['gamera london ', 'gamera tokyo ', 'gamera topeka ']) ); 85 expect(
86 result, equals(['gamera london ', 'gamera tokyo ', 'gamera topeka ']));
86 }); 87 });
87 88
88 // Subcommand completion. 89 // Subcommand completion.
89 cmd.completeCommand('gamera l').then((result) { 90 cmd.completeCommand('gamera l').then((result) {
90 expect(result, equals(['gamera london '])); 91 expect(result, equals(['gamera london ']));
91 }); 92 });
92 93
93 // Extra space, with subcommand. 94 // Extra space, with subcommand.
94 cmd.completeCommand('gamera london ').then((result) { 95 cmd.completeCommand('gamera london ').then((result) {
95 expect(result, equals(['gamera london '])); 96 expect(result, equals(['gamera london ']));
(...skipping 15 matching lines...) Expand all
111 expect(result, equals(['game checkers '])); 112 expect(result, equals(['game checkers ']));
112 }); 113 });
113 114
114 // Ambiguous non-exact prefix means no matches. 115 // Ambiguous non-exact prefix means no matches.
115 cmd.completeCommand('gam chec').then((result) { 116 cmd.completeCommand('gam chec').then((result) {
116 expect(result, equals([])); 117 expect(result, equals([]));
117 }); 118 });
118 119
119 // Locals + subcommands, show all. 120 // Locals + subcommands, show all.
120 cmd.completeCommand('count ').then((result) { 121 cmd.completeCommand('count ').then((result) {
121 expect(result, equals(['count chocula ', 122 expect(result,
122 'count one ', 123 equals(['count chocula ', 'count one ', 'count two ', 'count three ']));
123 'count two ',
124 'count three ']));
125 }); 124 });
126 125
127 // Locals + subcommands, single local match. 126 // Locals + subcommands, single local match.
128 cmd.completeCommand('count th').then((result) { 127 cmd.completeCommand('count th').then((result) {
129 expect(result, equals(['count three '])); 128 expect(result, equals(['count three ']));
130 }); 129 });
131 130
132 // Locals + subcommands, ambiguous local match. 131 // Locals + subcommands, ambiguous local match.
133 cmd.completeCommand('count t').then((result) { 132 cmd.completeCommand('count t').then((result) {
134 expect(result, equals(['count two ', 'count three '])); 133 expect(result, equals(['count two ', 'count three ']));
(...skipping 10 matching lines...) Expand all
145 }); 144 });
146 } 145 }
147 146
148 void testCommandRunSimple() { 147 void testCommandRunSimple() {
149 // Run a simple command. 148 // Run a simple command.
150 StringBuffer out = new StringBuffer(); 149 StringBuffer out = new StringBuffer();
151 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]); 150 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]);
152 151
153 // Full name dispatch works. Argument passing works. 152 // Full name dispatch works. Argument passing works.
154 cmd.runCommand('alpha dog').then(expectAsync((_) { 153 cmd.runCommand('alpha dog').then(expectAsync((_) {
155 expect(out.toString(), contains('executing alpha([dog])\n')); 154 expect(out.toString(), contains('executing alpha([dog])\n'));
156 out.clear(); 155 out.clear();
157 // Substring dispatch works. 156 // Substring dispatch works.
158 cmd.runCommand('al cat mouse').then(expectAsync((_) { 157 cmd.runCommand('al cat mouse').then(expectAsync((_) {
159 expect(out.toString(), contains('executing alpha([cat , mouse])\n')); 158 expect(out.toString(), contains('executing alpha([cat , mouse])\n'));
160 })); 159 }));
161 })); 160 }));
162 } 161 }
163 162
164 void testCommandRunSubcommand() { 163 void testCommandRunSubcommand() {
165 // Run a simple command. 164 // Run a simple command.
166 StringBuffer out = new StringBuffer(); 165 StringBuffer out = new StringBuffer();
167 RootCommand cmd = 166 RootCommand cmd = new RootCommand([
168 new RootCommand([ 167 new TestCommand(out, 'alpha',
169 new TestCommand(out, 'alpha', [ 168 [new TestCommand(out, 'beta', []), new TestCommand(out, 'gamma', [])])
170 new TestCommand(out, 'beta', []), 169 ]);
171 new TestCommand(out, 'gamma', [])])]);
172 170
173 cmd.runCommand('a b').then(expectAsync((_) { 171 cmd.runCommand('a b').then(expectAsync((_) {
174 expect(out.toString(), equals('executing beta([])\n')); 172 expect(out.toString(), equals('executing beta([])\n'));
175 out.clear(); 173 out.clear();
176 cmd.runCommand('alpha g ').then(expectAsync((_) { 174 cmd.runCommand('alpha g ').then(expectAsync((_) {
177 expect(out.toString(), equals('executing gamma([])\n')); 175 expect(out.toString(), equals('executing gamma([])\n'));
178 })); 176 }));
179 })); 177 }));
180 } 178 }
181 179
182 void testCommandRunNotFound() { 180 void testCommandRunNotFound() {
183 // Run a simple command. 181 // Run a simple command.
184 StringBuffer out = new StringBuffer(); 182 StringBuffer out = new StringBuffer();
185 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]); 183 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]);
186 184
187 cmd.runCommand('goose').catchError(expectAsync((e) { 185 cmd.runCommand('goose').catchError(expectAsync((e) {
188 expect(e.toString(), equals("No such command: 'goose'")); 186 expect(e.toString(), equals("No such command: 'goose'"));
189 })); 187 }));
190 } 188 }
191 189
192 void testCommandRunAmbiguous() { 190 void testCommandRunAmbiguous() {
193 // Run a simple command. 191 // Run a simple command.
194 StringBuffer out = new StringBuffer(); 192 StringBuffer out = new StringBuffer();
195 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', []), 193 RootCommand cmd = new RootCommand(
196 new TestCommand(out, 'ankle', [])]); 194 [new TestCommand(out, 'alpha', []), new TestCommand(out, 'ankle', [])]);
197 195
198 cmd.runCommand('a 55').catchError(expectAsync((e) { 196 cmd.runCommand('a 55').catchError(expectAsync((e) {
199 expect(e.toString(), 197 expect(e.toString(), equals("Command 'a 55' is ambiguous: [alpha, ankle]"));
200 equals("Command 'a 55' is ambiguous: [alpha, ankle]")); 198 out.clear();
201 out.clear(); 199 cmd.runCommand('ankl 55').then(expectAsync((_) {
202 cmd.runCommand('ankl 55').then(expectAsync((_) { 200 expect(out.toString(), equals('executing ankle([55])\n'));
203 expect(out.toString(), equals('executing ankle([55])\n')); 201 }));
204 }));
205 })); 202 }));
206 } 203 }
207 204
208 void testCommandRunAlias() { 205 void testCommandRunAlias() {
209 // Run a simple command. 206 // Run a simple command.
210 StringBuffer out = new StringBuffer(); 207 StringBuffer out = new StringBuffer();
211 var aliasCmd = new TestCommand(out, 'alpha', []); 208 var aliasCmd = new TestCommand(out, 'alpha', []);
212 aliasCmd.alias = 'a'; 209 aliasCmd.alias = 'a';
213 RootCommand cmd = new RootCommand([aliasCmd, 210 RootCommand cmd =
214 new TestCommand(out, 'ankle', [])]); 211 new RootCommand([aliasCmd, new TestCommand(out, 'ankle', [])]);
215 212
216 cmd.runCommand('a 55').then(expectAsync((_) { 213 cmd.runCommand('a 55').then(expectAsync((_) {
217 expect(out.toString(), equals('executing alpha([55])\n')); 214 expect(out.toString(), equals('executing alpha([55])\n'));
218 })); 215 }));
219 } 216 }
220 217
221 main() { 218 main() {
222 test('command completion test suite', testCommandComplete); 219 test('command completion test suite', testCommandComplete);
223 test('run a simple command', testCommandRunSimple); 220 test('run a simple command', testCommandRunSimple);
224 test('run a subcommand', testCommandRunSubcommand); 221 test('run a subcommand', testCommandRunSubcommand);
225 test('run a command which is not found', testCommandRunNotFound); 222 test('run a command which is not found', testCommandRunNotFound);
226 test('run a command which is ambiguous', testCommandRunAmbiguous); 223 test('run a command which is ambiguous', testCommandRunAmbiguous);
227 test('run a command using an alias', testCommandRunAlias); 224 test('run a command using an alias', testCommandRunAlias);
228 } 225 }
229
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/code_test.dart ('k') | runtime/observatory/tests/service/complex_reload/v1/main.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698