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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:io';
6
7 import 'package:yaml/yaml.dart';
8
9 /// The version number of the test runner, or `null` if it couldn't be loaded.
10 ///
11 /// This is a semantic version, optionally followed by a space and additional
12 /// data about its source.
13 final String testVersion = (() {
14 var lockfile;
15 try {
16 lockfile = loadYaml(new File("pubspec.lock").readAsStringSync());
17 } on FormatException catch (_) {
18 return null;
19 } on IOException catch (_) {
20 return null;
21 }
22
23 if (lockfile is! Map) return null;
24 var packages = lockfile["packages"];
25 if (packages is! Map) return null;
26 var package = packages["test"];
27 if (package is! Map) return null;
28
29 var source = package["source"];
30 if (source is! String) return null;
31
32 switch (source) {
33 case "hosted":
34 var version = package["version"];
35 if (version is! String) return null;
36
37 return version;
38
39 case "git":
40 var version = package["version"];
41 if (version is! String) return null;
42 var description = package["description"];
43 if (description is! Map) return null;
44 var ref = description["resolved-ref"];
45 if (ref is! String) return null;
46
47 return "$version (${ref.substring(0, 7)})";
48
49 case "path":
50 var version = package["version"];
51 if (version is! String) return null;
52 var description = package["description"];
53 if (description is! Map) return null;
54 var path = description["path"];
55 if (path is! String) return null;
56
57 return "$version (from $path)";
58
59 default: return null;
60 }
61 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698