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

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

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

Powered by Google App Engine
This is Rietveld 408576698