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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/executable.dart
diff --git a/lib/src/executable.dart b/lib/src/executable.dart
index 29c4dd33c4599a0fffdf5435d2ac32cef22e15a4..1156acf99cdce57253d5ae30df5ffaa84b1c6a4f 100644
--- a/lib/src/executable.dart
+++ b/lib/src/executable.dart
@@ -15,6 +15,7 @@ import 'package:yaml/yaml.dart';
import 'runner.dart';
import 'runner/application_exception.dart';
import 'runner/configuration.dart';
+import 'runner/version.dart';
import 'util/exit_codes.dart' as exit_codes;
import 'util/io.dart';
import 'utils.dart';
@@ -75,9 +76,12 @@ main(List<String> args) async {
}
if (configuration.version) {
- if (!_printVersion()) {
+ var version = testVersion;
+ if (version == null) {
stderr.writeln("Couldn't find version number.");
exitCode = exit_codes.data;
+ } else {
+ print(version);
}
return;
}
@@ -154,61 +158,3 @@ Usage: pub run test:test [files or directories...]
${Configuration.usage}
""");
}
-
-/// Prints the version number of the test package.
-///
-/// This loads the version number from the current package's lockfile. It
-/// returns true if it successfully printed the version number and false if it
-/// couldn't be loaded.
-bool _printVersion() {
- var lockfile;
- try {
- lockfile = loadYaml(new File("pubspec.lock").readAsStringSync());
- } on FormatException catch (_) {
- return false;
- } on IOException catch (_) {
- return false;
- }
-
- if (lockfile is! Map) return false;
- var packages = lockfile["packages"];
- if (packages is! Map) return false;
- var package = packages["test"];
- if (package is! Map) return false;
-
- var source = package["source"];
- if (source is! String) return false;
-
- switch (source) {
- case "hosted":
- var version = package["version"];
- if (version is! String) return false;
-
- print(version);
- return true;
-
- case "git":
- var version = package["version"];
- if (version is! String) return false;
- var description = package["description"];
- if (description is! Map) return false;
- var ref = description["resolved-ref"];
- if (ref is! String) return false;
-
- print("$version (${ref.substring(0, 7)})");
- return true;
-
- case "path":
- var version = package["version"];
- if (version is! String) return false;
- var description = package["description"];
- if (description is! Map) return false;
- var path = description["path"];
- if (path is! String) return false;
-
- print("$version (from $path)");
- return true;
-
- default: return false;
- }
-}

Powered by Google App Engine
This is Rietveld 408576698