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

Side by Side Diff: pkg/barback/test/asset_graph/errors_test.dart

Issue 16854005: First pass at build dependency graph for barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 6 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) 2013, 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 library barback.test.asset_graph.source_test;
6
7 import 'dart:async';
8
9 import 'package:barback/barback.dart';
10 import 'package:barback/src/asset_graph.dart';
11 import 'package:scheduled_test/scheduled_test.dart';
12
13 import '../utils.dart';
14
15 main() {
16 initConfig();
17
18 test("errors if two transformers output the same file", () {
19 var provider = new MockProvider(["app|foo.a"]);
20 var graph = new AssetGraph(provider, [
21 [
22 new RewriteTransformer("a", "b"),
23 new RewriteTransformer("a", "b")
24 ]
25 ]);
26 graph.updateSources([new AssetId.parse("app|foo.a")]);
27
28 expectCollision(graph, "app|foo.b");
29 });
30
31 test("reports asset not found errors in results", () {
32 var provider = new MockProvider([]);
33 var graph = new AssetGraph(provider, []);
34
35 // TODO(rnystrom): This is verbose and ugly. Better would be to have
36 // utils.dart register this on the graph and then have functions to expect
37 // certain build results.
38 var numResults = 0;
39 var gotError = false;
40 graph.results.listen(wrapAsync((result) {
41 numResults++;
42 expect(numResults, lessThan(3));
43
44 if (numResults == 1) {
45 // Should complete the build first.
46 expect(result.error, isNull);
47 } else if (numResults == 2) {
48 // Then have the error.
49 expect(result.error, new isInstanceOf<AssetNotFoundException>());
50 expect(result.error.id, equals(new AssetId.parse("app|foo.txt")));
51 gotError = true;
52 }
53 }));
54
55 expectNoAsset(graph, "app|foo.txt");
56
57 schedule(() {
58 expect(gotError, isTrue);
59 });
60 });
61
62 test("reports missing input errors in results", () {
63 var provider = new MockProvider({"app|a.txt": "a.inc"});
64
65 var graph = new AssetGraph(provider, [
66 [new ManyToOneTransformer("txt")]
67 ]);
68
69 var gotError = false;
70 graph.results.listen(wrapAsync((result) {
71 expect(result.error is MissingInputException, isTrue);
72 expect(result.error.id, equals(new AssetId.parse("app|a.inc")));
73 gotError = true;
74 }));
75
76 graph.updateSources([new AssetId.parse("app|a.txt")]);
77
78 expectNoAsset(graph, "app|a.out");
79
80 schedule(() {
81 expect(gotError, isTrue);
82 });
83 });
84
85 test("fails if a non-primary input is removed", () {
86 var provider = new MockProvider({
87 "app|a.txt": "a.inc,b.inc,c.inc",
88 "app|a.inc": "a",
89 "app|b.inc": "b",
90 "app|c.inc": "c"
91 });
92
93 var graph = new AssetGraph(provider, [
94 [new ManyToOneTransformer("txt")]
95 ]);
96
97 // TODO(rnystrom): This is verbose and ugly. Better would be to have
98 // utils.dart register this on the graph and then have functions to expect
99 // certain build results.
100 var numResults = 0;
101 var gotError = false;
102 graph.results.listen(wrapAsync((result) {
103 numResults++;
104 expect(numResults, lessThan(3));
105
106 if (numResults == 1) {
107 // Should complete the build first.
108 expect(result.error, isNull);
109 } else if (numResults == 2) {
110 // Then have the error.
111 expect(result.error is MissingInputException, isTrue);
112 expect(result.error.id, equals(new AssetId.parse("app|b.inc")));
113 gotError = true;
114 }
115 }));
116
117 graph.updateSources([
118 new AssetId.parse("app|a.txt"),
119 new AssetId.parse("app|a.inc"),
120 new AssetId.parse("app|b.inc"),
121 new AssetId.parse("app|c.inc")
122 ]);
123
124 expectAsset(graph, "app|a.out", "abc");
125
126 schedule(() {
127 graph.removeSources([new AssetId.parse("app|b.inc")]);
128 });
129
130 expectNoAsset(graph, "app|a.out");
131
132 schedule(() {
133 expect(gotError, isTrue);
134 });
135 });
136
137 test("catches transformer exceptions and reports them", () {
138 var provider = new MockProvider(["app|foo.txt"]);
139 var graph = new AssetGraph(provider, [
140 [new BadTransformer(["app|foo.out"])]
141 ]);
142
143 var gotError = false;
144 graph.results.listen(wrapAsync((result) {
145 expect(result.error, equals(BadTransformer.ERROR));
146 gotError = true;
147 }));
148
149 schedule(() {
150 graph.updateSources([new AssetId.parse("app|foo.txt")]);
151 });
152
153 expectNoAsset(graph, "app|foo.out");
154
155 schedule(() {
156 expect(gotError, isTrue);
157 });
158 });
159
160 // TODO(rnystrom): Is this the behavior we expect? If a transformer fails
161 // to transform a file, should we just skip past it to the source?
162 test("yields a source if a transform fails on it", () {
163 var provider = new MockProvider(["app|foo.txt"]);
164 var graph = new AssetGraph(provider, [
165 [new BadTransformer(["app|foo.txt"])]
166 ]);
167
168 schedule(() {
169 graph.updateSources([new AssetId.parse("app|foo.txt")]);
170 });
171
172 expectAsset(graph, "app|foo.txt");
173 });
174
175 test("catches errors even if nothing is waiting for process results", () {
176 var provider = new MockProvider(["app|foo.txt"]);
177 var graph = new AssetGraph(provider, [[new BadTransformer([])]]);
178 var resultFuture = graph.results.first;
179
180 schedule(() {
181 graph.updateSources([new AssetId.parse("app|foo.txt")]);
182 });
183
184 // Note: No asset requests here.
185
186 schedule(() {
187 return resultFuture.then((result) {
188 expect(result.error, equals(BadTransformer.ERROR));
189 });
190 });
191 });
192
193 test("discards outputs from failed transforms", () {
194 var provider = new MockProvider(["app|foo.txt"]);
195 var graph = new AssetGraph(provider, [
196 [new BadTransformer(["a.out", "b.out"])]
197 ]);
198
199 schedule(() {
200 graph.updateSources([new AssetId.parse("app|foo.txt")]);
201 });
202
203 expectNoAsset(graph, "app|a.out");
204 });
205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698