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

Unified Diff: lib/src/runner/version.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/runner/version.dart
diff --git a/lib/src/runner/version.dart b/lib/src/runner/version.dart
new file mode 100644
index 0000000000000000000000000000000000000000..261764b664cb6fb4648600200c297dde971e2747
--- /dev/null
+++ b/lib/src/runner/version.dart
@@ -0,0 +1,61 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+
+import 'package:yaml/yaml.dart';
+
+/// The version number of the test runner, or `null` if it couldn't be loaded.
+///
+/// This is a semantic version, optionally followed by a space and additional
+/// data about its source.
+final String testVersion = (() {
+ var lockfile;
+ try {
+ lockfile = loadYaml(new File("pubspec.lock").readAsStringSync());
+ } on FormatException catch (_) {
+ return null;
+ } on IOException catch (_) {
+ return null;
+ }
+
+ if (lockfile is! Map) return null;
+ var packages = lockfile["packages"];
+ if (packages is! Map) return null;
+ var package = packages["test"];
+ if (package is! Map) return null;
+
+ var source = package["source"];
+ if (source is! String) return null;
+
+ switch (source) {
+ case "hosted":
+ var version = package["version"];
+ if (version is! String) return null;
+
+ return version;
+
+ case "git":
+ var version = package["version"];
+ if (version is! String) return null;
+ var description = package["description"];
+ if (description is! Map) return null;
+ var ref = description["resolved-ref"];
+ if (ref is! String) return null;
+
+ return "$version (${ref.substring(0, 7)})";
+
+ case "path":
+ var version = package["version"];
+ if (version is! String) return null;
+ var description = package["description"];
+ if (description is! Map) return null;
+ var path = description["path"];
+ if (path is! String) return null;
+
+ return "$version (from $path)";
+
+ default: return null;
+ }
+})();

Powered by Google App Engine
This is Rietveld 408576698