OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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.md file. |
| 4 |
| 5 library testing.test_root; |
| 6 |
| 7 import 'dart:async' show |
| 8 Future; |
| 9 |
| 10 import 'dart:convert' show |
| 11 JSON; |
| 12 |
| 13 import 'dart:io' show |
| 14 File; |
| 15 |
| 16 import '../testing.dart' show |
| 17 Chain; |
| 18 |
| 19 import 'analyze.dart' show |
| 20 Analyze; |
| 21 |
| 22 import 'suite.dart' show |
| 23 Dart, |
| 24 Suite; |
| 25 |
| 26 /// Records properties of a test root. The information is read from a JSON file. |
| 27 /// |
| 28 /// Example with comments: |
| 29 /// { |
| 30 /// # Path to the `.packages` file used. |
| 31 /// "packages": "test/.packages", |
| 32 /// # A list of test suites (collection of tests). |
| 33 /// "suites": [ |
| 34 /// # A list of suite objects. See the subclasses of [Suite] below. |
| 35 /// ], |
| 36 /// "analyze": { |
| 37 /// # Uris to analyze. |
| 38 /// "uris": [ |
| 39 /// "lib/", |
| 40 /// "bin/dartk.dart", |
| 41 /// "bin/repl.dart", |
| 42 /// "test/log_analyzer.dart", |
| 43 /// "third_party/testing/lib/" |
| 44 /// ], |
| 45 /// # Regular expressions of file names to ignore when analyzing. |
| 46 /// "exclude": [ |
| 47 /// "/third_party/dart-sdk/pkg/compiler/", |
| 48 /// "/third_party/kernel/" |
| 49 /// ] |
| 50 /// } |
| 51 /// } |
| 52 class TestRoot { |
| 53 final Uri packages; |
| 54 |
| 55 final List<Suite> suites; |
| 56 |
| 57 TestRoot(this.packages, this.suites); |
| 58 |
| 59 Analyze get analyze => suites.last; |
| 60 |
| 61 List<Uri> get urisToAnalyze => analyze.uris; |
| 62 |
| 63 List<RegExp> get excludedFromAnalysis => analyze.exclude; |
| 64 |
| 65 Iterable<Dart> get dartSuites { |
| 66 return new List<Dart>.from( |
| 67 suites.where((Suite suite) => suite is Dart)); |
| 68 } |
| 69 |
| 70 Iterable<Chain> get toolChains { |
| 71 return new List<Chain>.from( |
| 72 suites.where((Suite suite) => suite is Chain)); |
| 73 } |
| 74 |
| 75 String toString() { |
| 76 return "TestRoot($suites, $urisToAnalyze)"; |
| 77 } |
| 78 |
| 79 static Future<TestRoot> fromUri(Uri uri) async { |
| 80 String json = await new File.fromUri(uri).readAsString(); |
| 81 Map data = JSON.decode(json); |
| 82 |
| 83 addDefaults(data); |
| 84 |
| 85 Uri packages = uri.resolve(data["packages"]); |
| 86 |
| 87 List<Suite> suites = new List<Suite>.from( |
| 88 data["suites"].map((Map json) => new Suite.fromJsonMap(uri, json))); |
| 89 |
| 90 Analyze analyze = await Analyze.fromJsonMap(uri, data["analyze"], suites); |
| 91 |
| 92 suites.add(analyze); |
| 93 |
| 94 return new TestRoot(packages, suites); |
| 95 } |
| 96 |
| 97 static void addDefaults(Map data) { |
| 98 data.putIfAbsent("packages", () => ".packages"); |
| 99 data.putIfAbsent("suites", () => []); |
| 100 Map analyze = data.putIfAbsent("analyze", () => {}); |
| 101 analyze.putIfAbsent("uris", () => []); |
| 102 analyze.putIfAbsent("exclude", () => []); |
| 103 } |
| 104 } |
OLD | NEW |