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

Side by Side Diff: lib/src/executable.dart

Issue 1461293005: Add a JSON reporter. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 1 month 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 4
5 // TODO(nweiz): This is under lib so that it can be used by the unittest dummy 5 // TODO(nweiz): This is under lib so that it can be used by the unittest dummy
6 // package. Once that package is no longer being updated, move this back into 6 // package. Once that package is no longer being updated, move this back into
7 // bin. 7 // bin.
8 library test.executable; 8 library test.executable;
9 9
10 import 'dart:io'; 10 import 'dart:io';
11 11
12 import 'package:stack_trace/stack_trace.dart'; 12 import 'package:stack_trace/stack_trace.dart';
13 import 'package:yaml/yaml.dart'; 13 import 'package:yaml/yaml.dart';
14 14
15 import 'runner.dart'; 15 import 'runner.dart';
16 import 'runner/application_exception.dart'; 16 import 'runner/application_exception.dart';
17 import 'runner/configuration.dart'; 17 import 'runner/configuration.dart';
18 import 'runner/version.dart';
18 import 'util/exit_codes.dart' as exit_codes; 19 import 'util/exit_codes.dart' as exit_codes;
19 import 'util/io.dart'; 20 import 'util/io.dart';
20 import 'utils.dart'; 21 import 'utils.dart';
21 22
22 /// A merged stream of all signals that tell the test runner to shut down 23 /// A merged stream of all signals that tell the test runner to shut down
23 /// gracefully. 24 /// gracefully.
24 /// 25 ///
25 /// Signals will only be captured as long as this has an active subscription. 26 /// Signals will only be captured as long as this has an active subscription.
26 /// Otherwise, they'll be handled by Dart's default signal handler, which 27 /// Otherwise, they'll be handled by Dart's default signal handler, which
27 /// terminates the program immediately. 28 /// terminates the program immediately.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 exitCode = exit_codes.usage; 69 exitCode = exit_codes.usage;
69 return; 70 return;
70 } 71 }
71 72
72 if (configuration.help) { 73 if (configuration.help) {
73 _printUsage(); 74 _printUsage();
74 return; 75 return;
75 } 76 }
76 77
77 if (configuration.version) { 78 if (configuration.version) {
78 if (!_printVersion()) { 79 var version = testVersion;
80 if (version == null) {
79 stderr.writeln("Couldn't find version number."); 81 stderr.writeln("Couldn't find version number.");
80 exitCode = exit_codes.data; 82 exitCode = exit_codes.data;
83 } else {
84 print(version);
81 } 85 }
82 return; 86 return;
83 } 87 }
84 88
85 if (configuration.pubServeUrl != null && !_usesTransformer) { 89 if (configuration.pubServeUrl != null && !_usesTransformer) {
86 stderr.write(''' 90 stderr.write('''
87 When using --pub-serve, you must include the "test/pub_serve" transformer in 91 When using --pub-serve, you must include the "test/pub_serve" transformer in
88 your pubspec: 92 your pubspec:
89 93
90 transformers: 94 transformers:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 output = stderr; 151 output = stderr;
148 } 152 }
149 153
150 output.write("""$message 154 output.write("""$message
151 155
152 Usage: pub run test:test [files or directories...] 156 Usage: pub run test:test [files or directories...]
153 157
154 ${Configuration.usage} 158 ${Configuration.usage}
155 """); 159 """);
156 } 160 }
157
158 /// Prints the version number of the test package.
159 ///
160 /// This loads the version number from the current package's lockfile. It
161 /// returns true if it successfully printed the version number and false if it
162 /// couldn't be loaded.
163 bool _printVersion() {
164 var lockfile;
165 try {
166 lockfile = loadYaml(new File("pubspec.lock").readAsStringSync());
167 } on FormatException catch (_) {
168 return false;
169 } on IOException catch (_) {
170 return false;
171 }
172
173 if (lockfile is! Map) return false;
174 var packages = lockfile["packages"];
175 if (packages is! Map) return false;
176 var package = packages["test"];
177 if (package is! Map) return false;
178
179 var source = package["source"];
180 if (source is! String) return false;
181
182 switch (source) {
183 case "hosted":
184 var version = package["version"];
185 if (version is! String) return false;
186
187 print(version);
188 return true;
189
190 case "git":
191 var version = package["version"];
192 if (version is! String) return false;
193 var description = package["description"];
194 if (description is! Map) return false;
195 var ref = description["resolved-ref"];
196 if (ref is! String) return false;
197
198 print("$version (${ref.substring(0, 7)})");
199 return true;
200
201 case "path":
202 var version = package["version"];
203 if (version is! String) return false;
204 var description = package["description"];
205 if (description is! Map) return false;
206 var path = description["path"];
207 if (path is! String) return false;
208
209 print("$version (from $path)");
210 return true;
211
212 default: return false;
213 }
214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698