OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub_tests; | 5 library pub_tests; |
6 | 6 |
| 7 import 'package:barback/barback.dart'; |
7 import 'package:path/path.dart' as p; | 8 import 'package:path/path.dart' as p; |
8 import 'package:scheduled_test/scheduled_test.dart'; | 9 import 'package:scheduled_test/scheduled_test.dart'; |
9 | 10 |
10 import '../../lib/src/barback/cycle_exception.dart'; | 11 import '../../lib/src/barback/cycle_exception.dart'; |
11 import '../../lib/src/barback/transformers_needed_by_transformers.dart'; | 12 import '../../lib/src/barback/dependency_computer.dart'; |
12 import '../../lib/src/entrypoint.dart'; | 13 import '../../lib/src/entrypoint.dart'; |
13 import '../../lib/src/io.dart'; | 14 import '../../lib/src/io.dart'; |
14 import '../../lib/src/package.dart'; | 15 import '../../lib/src/package.dart'; |
15 import '../../lib/src/package_graph.dart'; | 16 import '../../lib/src/package_graph.dart'; |
16 import '../../lib/src/source/path.dart'; | 17 import '../../lib/src/source/path.dart'; |
17 import '../../lib/src/system_cache.dart'; | 18 import '../../lib/src/system_cache.dart'; |
18 import '../../lib/src/utils.dart'; | 19 import '../../lib/src/utils.dart'; |
19 import '../test_pub.dart'; | 20 import '../test_pub.dart'; |
20 | 21 |
21 /// Expects that [computeTransformersNeededByTransformers] will return a graph | 22 /// Expects that [DependencyComputer.transformersNeededByTransformers] will |
22 /// matching [expected] when run on the package graph defined by packages in | 23 /// return a graph matching [expected] when run on the package graph defined by |
23 /// the sandbox. | 24 /// packages in the sandbox. |
24 void expectDependencies(Map<String, Iterable<String>> expected) { | 25 void expectDependencies(Map<String, Iterable<String>> expected) { |
25 expected = mapMap(expected, value: (_, ids) => ids.toSet()); | 26 expected = mapMap(expected, value: (_, ids) => ids.toSet()); |
26 | 27 |
27 schedule(() { | 28 schedule(() { |
| 29 var computer = new DependencyComputer(_loadPackageGraph()); |
28 var result = mapMap( | 30 var result = mapMap( |
29 computeTransformersNeededByTransformers(_loadPackageGraph()), | 31 computer.transformersNeededByTransformers(), |
30 key: (id, _) => id.toString(), | 32 key: (id, _) => id.toString(), |
31 value: (_, ids) => ids.map((id) => id.toString()).toSet()); | 33 value: (_, ids) => ids.map((id) => id.toString()).toSet()); |
32 expect(result, equals(expected)); | 34 expect(result, equals(expected)); |
33 }, "expect dependencies to match $expected"); | 35 }, "expect dependencies to match $expected"); |
34 } | 36 } |
35 | 37 |
36 /// Expects that [computeTransformersNeededByTransformers] will throw an | 38 /// Expects that [computeTransformersNeededByTransformers] will throw an |
37 /// exception matching [matcher] when run on the package graph defiend by | 39 /// exception matching [matcher] when run on the package graph defiend by |
38 /// packages in the sandbox. | 40 /// packages in the sandbox. |
39 void expectException(matcher) { | 41 void expectException(matcher) { |
40 schedule(() { | 42 schedule(() { |
41 expect(() => computeTransformersNeededByTransformers(_loadPackageGraph()), | 43 expect(() { |
42 throwsA(matcher)); | 44 var computer = new DependencyComputer(_loadPackageGraph()); |
| 45 computer.transformersNeededByTransformers(); |
| 46 }, throwsA(matcher)); |
43 }, "expect an exception: $matcher"); | 47 }, "expect an exception: $matcher"); |
44 } | 48 } |
45 | 49 |
46 /// Expects that [computeTransformersNeededByTransformers] will throw a | 50 /// Expects that [computeTransformersNeededByTransformers] will throw a |
47 /// [CycleException] with the given [steps] when run on the package graph | 51 /// [CycleException] with the given [steps] when run on the package graph |
48 /// defiend by packages in the sandbox. | 52 /// defiend by packages in the sandbox. |
49 void expectCycleException(Iterable<String> steps) { | 53 void expectCycleException(Iterable<String> steps) { |
50 expectException(predicate((error) { | 54 expectException(predicate((error) { |
51 expect(error, new isInstanceOf<CycleException>()); | 55 expect(error, new isInstanceOf<CycleException>()); |
52 expect(error.steps, equals(steps)); | 56 expect(error.steps, equals(steps)); |
53 return true; | 57 return true; |
54 }, "cycle exception:\n${steps.map((step) => " $step").join("\n")}")); | 58 }, "cycle exception:\n${steps.map((step) => " $step").join("\n")}")); |
55 } | 59 } |
56 | 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(new AssetId.parse(id)) |
| 70 .map((id) => id.toString()).toSet(); |
| 71 expect(result, equals(expected)); |
| 72 }, "expect dependencies to match $expected"); |
| 73 } |
| 74 |
57 /// Loads a [PackageGraph] from the packages in the sandbox. | 75 /// Loads a [PackageGraph] from the packages in the sandbox. |
58 /// | 76 /// |
59 /// This graph will also include barback and its transitive dependencies from | 77 /// This graph will also include barback and its transitive dependencies from |
60 /// the repo. | 78 /// the repo. |
61 PackageGraph _loadPackageGraph() { | 79 PackageGraph _loadPackageGraph() { |
62 // Load the sandbox packages. | 80 // Load the sandbox packages. |
63 var packages = {}; | 81 var packages = {}; |
64 | 82 |
65 var systemCache = new SystemCache(p.join(sandboxDir, cachePath)); | 83 var systemCache = new SystemCache(p.join(sandboxDir, cachePath)); |
66 systemCache.sources | 84 systemCache.sources |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 120 |
103 buffer.writeln(""" | 121 buffer.writeln(""" |
104 NoOpTransformer extends Transformer { | 122 NoOpTransformer extends Transformer { |
105 bool isPrimary(AssetId id) => true; | 123 bool isPrimary(AssetId id) => true; |
106 void apply(Transform transform) {} | 124 void apply(Transform transform) {} |
107 } | 125 } |
108 """); | 126 """); |
109 | 127 |
110 return buffer.toString(); | 128 return buffer.toString(); |
111 } | 129 } |
OLD | NEW |