OLD | NEW |
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:async'; | 10 import 'dart:async'; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (transformer is String) return transformer == 'test/pub_serve'; | 67 if (transformer is String) return transformer == 'test/pub_serve'; |
68 if (transformer is! Map) return false; | 68 if (transformer is! Map) return false; |
69 if (transformer.keys.length != 1) return false; | 69 if (transformer.keys.length != 1) return false; |
70 return transformer.keys.single == 'test/pub_serve'; | 70 return transformer.keys.single == 'test/pub_serve'; |
71 }); | 71 }); |
72 } | 72 } |
73 | 73 |
74 void main(List<String> args) { | 74 void main(List<String> args) { |
75 _parser.addFlag("help", abbr: "h", negatable: false, | 75 _parser.addFlag("help", abbr: "h", negatable: false, |
76 help: "Shows this usage information."); | 76 help: "Shows this usage information."); |
| 77 _parser.addFlag("version", negatable: false, |
| 78 help: "Shows the package's version."); |
77 _parser.addOption("package-root", hide: true); | 79 _parser.addOption("package-root", hide: true); |
78 _parser.addOption("name", | 80 _parser.addOption("name", |
79 abbr: 'n', | 81 abbr: 'n', |
80 help: 'A substring of the name of the test to run.\n' | 82 help: 'A substring of the name of the test to run.\n' |
81 'Regular expression syntax is supported.'); | 83 'Regular expression syntax is supported.'); |
82 _parser.addOption("plain-name", | 84 _parser.addOption("plain-name", |
83 abbr: 'N', | 85 abbr: 'N', |
84 help: 'A plain-text substring of the name of the test to run.'); | 86 help: 'A plain-text substring of the name of the test to run.'); |
85 _parser.addOption("platform", | 87 _parser.addOption("platform", |
86 abbr: 'p', | 88 abbr: 'p', |
(...skipping 20 matching lines...) Expand all Loading... |
107 _printUsage(error.message); | 109 _printUsage(error.message); |
108 exitCode = exit_codes.usage; | 110 exitCode = exit_codes.usage; |
109 return; | 111 return; |
110 } | 112 } |
111 | 113 |
112 if (options["help"]) { | 114 if (options["help"]) { |
113 _printUsage(); | 115 _printUsage(); |
114 return; | 116 return; |
115 } | 117 } |
116 | 118 |
| 119 if (options["version"]) { |
| 120 if (!_printVersion()) { |
| 121 stderr.writeln("Couldn't find version number."); |
| 122 exitCode = exit_codes.data; |
| 123 } |
| 124 return; |
| 125 } |
| 126 |
117 var color = options["color"]; | 127 var color = options["color"]; |
118 if (color == null) color = canUseSpecialChars; | 128 if (color == null) color = canUseSpecialChars; |
119 | 129 |
120 var pubServeUrl; | 130 var pubServeUrl; |
121 if (options["pub-serve"] != null) { | 131 if (options["pub-serve"] != null) { |
122 pubServeUrl = Uri.parse("http://localhost:${options['pub-serve']}"); | 132 pubServeUrl = Uri.parse("http://localhost:${options['pub-serve']}"); |
123 if (!_usesTransformer) { | 133 if (!_usesTransformer) { |
124 stderr.write(''' | 134 stderr.write(''' |
125 When using --pub-serve, you must include the "test/pub_serve" transformer in | 135 When using --pub-serve, you must include the "test/pub_serve" transformer in |
126 your pubspec: | 136 your pubspec: |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 output = stderr; | 295 output = stderr; |
286 } | 296 } |
287 | 297 |
288 output.write("""$message | 298 output.write("""$message |
289 | 299 |
290 Usage: pub run test:test [files or directories...] | 300 Usage: pub run test:test [files or directories...] |
291 | 301 |
292 ${_parser.usage} | 302 ${_parser.usage} |
293 """); | 303 """); |
294 } | 304 } |
| 305 |
| 306 /// Prints the version number of the test package. |
| 307 /// |
| 308 /// This loads the version number from the current package's lockfile. It |
| 309 /// returns true if it successfully printed the version number and false if it |
| 310 /// couldn't be loaded. |
| 311 bool _printVersion() { |
| 312 var lockfile; |
| 313 try { |
| 314 lockfile = loadYaml(new File("pubspec.lock").readAsStringSync()); |
| 315 } on FormatException catch (_) { |
| 316 return false; |
| 317 } on IOException catch (_) { |
| 318 return false; |
| 319 } |
| 320 |
| 321 if (lockfile is! Map) return false; |
| 322 var packages = lockfile["packages"]; |
| 323 if (packages is! Map) return false; |
| 324 var package = packages["test"]; |
| 325 if (package is! Map) return false; |
| 326 |
| 327 var source = package["source"]; |
| 328 if (source is! String) return false; |
| 329 |
| 330 switch (source) { |
| 331 case "hosted": |
| 332 var version = package["version"]; |
| 333 if (version is! String) return false; |
| 334 |
| 335 print(version); |
| 336 return true; |
| 337 |
| 338 case "git": |
| 339 var version = package["version"]; |
| 340 if (version is! String) return false; |
| 341 var description = package["description"]; |
| 342 if (description is! Map) return false; |
| 343 var ref = description["resolved-ref"]; |
| 344 if (ref is! String) return false; |
| 345 |
| 346 print("$version (${ref.substring(0, 7)})"); |
| 347 return true; |
| 348 |
| 349 case "path": |
| 350 var version = package["version"]; |
| 351 if (version is! String) return false; |
| 352 var description = package["description"]; |
| 353 if (description is! Map) return false; |
| 354 var path = description["path"]; |
| 355 if (path is! String) return false; |
| 356 |
| 357 print("$version (from $path)"); |
| 358 return true; |
| 359 |
| 360 default: return false; |
| 361 } |
| 362 } |
OLD | NEW |