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

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: Handle unprovided sources and errors a bit better. 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
« no previous file with comments | « pkg/barback/pubspec.yaml ('k') | pkg/barback/test/asset_graph/source_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 an error for an unprovided source", () {
63 var provider = new MockProvider([]);
64 var graph = new AssetGraph(provider, []);
65 var resultFuture = graph.results.first;
66
67 graph.updateSources([new AssetId.parse("app|unknown.txt")]);
68
69 schedule(() {
70 return resultFuture.then((result) {
71 expect(result.error, new isInstanceOf<AssetNotFoundException>());
72 expect(result.error.id, equals(new AssetId.parse("app|unknown.txt")));
73 });
74 });
75 });
76
77 test("reports missing input errors in results", () {
78 var provider = new MockProvider({"app|a.txt": "a.inc"});
79
80 var graph = new AssetGraph(provider, [
81 [new ManyToOneTransformer("txt")]
82 ]);
83
84 var gotError = false;
85 graph.results.listen(wrapAsync((result) {
86 expect(result.error is MissingInputException, isTrue);
87 expect(result.error.id, equals(new AssetId.parse("app|a.inc")));
88 gotError = true;
89 }));
90
91 graph.updateSources([new AssetId.parse("app|a.txt")]);
92
93 expectNoAsset(graph, "app|a.out");
94
95 schedule(() {
96 expect(gotError, isTrue);
97 });
98 });
99
100 test("fails if a non-primary input is removed", () {
101 var provider = new MockProvider({
102 "app|a.txt": "a.inc,b.inc,c.inc",
103 "app|a.inc": "a",
104 "app|b.inc": "b",
105 "app|c.inc": "c"
106 });
107
108 var graph = new AssetGraph(provider, [
109 [new ManyToOneTransformer("txt")]
110 ]);
111
112 // TODO(rnystrom): This is verbose and ugly. Better would be to have
113 // utils.dart register this on the graph and then have functions to expect
114 // certain build results.
115 var numResults = 0;
116 var gotError = false;
117 graph.results.listen(wrapAsync((result) {
118 numResults++;
119 expect(numResults, lessThan(3));
120
121 if (numResults == 1) {
122 // Should complete the build first.
123 expect(result.error, isNull);
124 } else if (numResults == 2) {
125 // Then have the error.
126 expect(result.error is MissingInputException, isTrue);
127 expect(result.error.id, equals(new AssetId.parse("app|b.inc")));
128 gotError = true;
129 }
130 }));
131
132 graph.updateSources([
133 new AssetId.parse("app|a.txt"),
134 new AssetId.parse("app|a.inc"),
135 new AssetId.parse("app|b.inc"),
136 new AssetId.parse("app|c.inc")
137 ]);
138
139 expectAsset(graph, "app|a.out", "abc");
140
141 schedule(() {
142 graph.removeSources([new AssetId.parse("app|b.inc")]);
143 });
144
145 expectNoAsset(graph, "app|a.out");
146
147 schedule(() {
148 expect(gotError, isTrue);
149 });
150 });
151
152 test("catches transformer exceptions and reports them", () {
153 var provider = new MockProvider(["app|foo.txt"]);
154 var graph = new AssetGraph(provider, [
155 [new BadTransformer(["app|foo.out"])]
156 ]);
157
158 var gotError = false;
159 graph.results.listen(wrapAsync((result) {
160 expect(result.error, equals(BadTransformer.ERROR));
161 gotError = true;
162 }));
163
164 schedule(() {
165 graph.updateSources([new AssetId.parse("app|foo.txt")]);
166 });
167
168 expectNoAsset(graph, "app|foo.out");
169
170 schedule(() {
171 expect(gotError, isTrue);
172 });
173 });
174
175 // TODO(rnystrom): Is this the behavior we expect? If a transformer fails
176 // to transform a file, should we just skip past it to the source?
177 test("yields a source if a transform fails on it", () {
178 var provider = new MockProvider(["app|foo.txt"]);
179 var graph = new AssetGraph(provider, [
180 [new BadTransformer(["app|foo.txt"])]
181 ]);
182
183 schedule(() {
184 graph.updateSources([new AssetId.parse("app|foo.txt")]);
185 });
186
187 expectAsset(graph, "app|foo.txt");
188 });
189
190 test("catches errors even if nothing is waiting for process results", () {
191 var provider = new MockProvider(["app|foo.txt"]);
192 var graph = new AssetGraph(provider, [[new BadTransformer([])]]);
193 var resultFuture = graph.results.first;
194
195 schedule(() {
196 graph.updateSources([new AssetId.parse("app|foo.txt")]);
197 });
198
199 // Note: No asset requests here.
200
201 schedule(() {
202 return resultFuture.then((result) {
203 expect(result.error, equals(BadTransformer.ERROR));
204 });
205 });
206 });
207
208 test("discards outputs from failed transforms", () {
209 var provider = new MockProvider(["app|foo.txt"]);
210 var graph = new AssetGraph(provider, [
211 [new BadTransformer(["a.out", "b.out"])]
212 ]);
213
214 schedule(() {
215 graph.updateSources([new AssetId.parse("app|foo.txt")]);
216 });
217
218 expectNoAsset(graph, "app|a.out");
219 });
220 }
OLDNEW
« no previous file with comments | « pkg/barback/pubspec.yaml ('k') | pkg/barback/test/asset_graph/source_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698