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

Side by Side Diff: sdk/lib/_internal/pub_generated/test/dependency_computer/utils.dart

Issue 937243002: Revert "Revert "Use native async/await support in pub."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.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 library pub_tests;
6
7 import 'package:barback/barback.dart';
8 import 'package:path/path.dart' as p;
9 import 'package:scheduled_test/scheduled_test.dart';
10
11 import '../../lib/src/barback/cycle_exception.dart';
12 import '../../lib/src/barback/dependency_computer.dart';
13 import '../../lib/src/entrypoint.dart';
14 import '../../lib/src/io.dart';
15 import '../../lib/src/package.dart';
16 import '../../lib/src/package_graph.dart';
17 import '../../lib/src/source/path.dart';
18 import '../../lib/src/system_cache.dart';
19 import '../../lib/src/utils.dart';
20 import '../test_pub.dart';
21
22 /// Expects that [DependencyComputer.transformersNeededByTransformers] will
23 /// return a graph matching [expected] when run on the package graph defined by
24 /// packages in the sandbox.
25 void expectDependencies(Map<String, Iterable<String>> expected) {
26 expected = mapMap(expected, value: (_, ids) => ids.toSet());
27
28 schedule(() {
29 var computer = new DependencyComputer(_loadPackageGraph());
30 var result = mapMap(
31 computer.transformersNeededByTransformers(),
32 key: (id, _) => id.toString(),
33 value: (_, ids) => ids.map((id) => id.toString()).toSet());
34 expect(result, equals(expected));
35 }, "expect dependencies to match $expected");
36 }
37
38 /// Expects that [computeTransformersNeededByTransformers] will throw an
39 /// exception matching [matcher] when run on the package graph defiend by
40 /// packages in the sandbox.
41 void expectException(matcher) {
42 schedule(() {
43 expect(() {
44 var computer = new DependencyComputer(_loadPackageGraph());
45 computer.transformersNeededByTransformers();
46 }, throwsA(matcher));
47 }, "expect an exception: $matcher");
48 }
49
50 /// Expects that [computeTransformersNeededByTransformers] will throw a
51 /// [CycleException] with the given [steps] when run on the package graph
52 /// defiend by packages in the sandbox.
53 void expectCycleException(Iterable<String> steps) {
54 expectException(predicate((error) {
55 expect(error, new isInstanceOf<CycleException>());
56 expect(error.steps, equals(steps));
57 return true;
58 }, "cycle exception:\n${steps.map((step) => " $step").join("\n")}"));
59 }
60
61 /// Expects that [DependencyComputer.transformersNeededByLibrary] will return
62 /// transformer ids matching [expected] when run on the library identified by
63 /// [id].
64 void expectLibraryDependencies(String id, Iterable<String> expected) {
65 expected = expected.toSet();
66
67 schedule(() {
68 var computer = new DependencyComputer(_loadPackageGraph());
69 var result = computer.transformersNeededByLibrary(
70 new AssetId.parse(id)).map((id) => id.toString()).toSet();
71 expect(result, equals(expected));
72 }, "expect dependencies to match $expected");
73 }
74
75 /// Loads a [PackageGraph] from the packages in the sandbox.
76 ///
77 /// This graph will also include barback and its transitive dependencies from
78 /// the repo.
79 PackageGraph _loadPackageGraph() {
80 // Load the sandbox packages.
81 var packages = {};
82
83 var systemCache = new SystemCache(p.join(sandboxDir, cachePath));
84 systemCache.sources
85 ..register(new PathSource())
86 ..setDefault('path');
87 var entrypoint = new Entrypoint(p.join(sandboxDir, appPath), systemCache);
88
89 for (var package in listDir(sandboxDir)) {
90 if (!fileExists(p.join(package, 'pubspec.yaml'))) continue;
91 var packageName = p.basename(package);
92 packages[packageName] =
93 new Package.load(packageName, package, systemCache.sources);
94 }
95
96 loadPackage(packageName) {
97 if (packages.containsKey(packageName)) return;
98 packages[packageName] =
99 new Package.load(packageName, packagePath(packageName), systemCache.sour ces);
100 for (var dep in packages[packageName].dependencies) {
101 loadPackage(dep.name);
102 }
103 }
104
105 loadPackage('barback');
106
107 return new PackageGraph(entrypoint, null, packages);
108 }
109
110 /// Returns the contents of a no-op transformer that imports each URL in
111 /// [imports].
112 String transformer([Iterable<String> imports]) {
113 if (imports == null) imports = [];
114
115 var buffer =
116 new StringBuffer()..writeln('import "package:barback/barback.dart";');
117 for (var import in imports) {
118 buffer.writeln('import "$import";');
119 }
120
121 buffer.writeln("""
122 NoOpTransformer extends Transformer {
123 bool isPrimary(AssetId id) => true;
124 void apply(Transform transform) {}
125 }
126 """);
127
128 return buffer.toString();
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698