OLD | NEW |
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.package_graph.source_test; | 5 library barback.test.package_graph.source_test; |
6 | 6 |
7 import 'package:barback/src/utils.dart'; | 7 import 'package:barback/src/utils.dart'; |
8 import 'package:scheduled_test/scheduled_test.dart'; | 8 import 'package:scheduled_test/scheduled_test.dart'; |
9 | 9 |
10 import '../utils.dart'; | 10 import '../utils.dart'; |
11 | 11 |
12 main() { | 12 main() { |
13 initConfig(); | 13 initConfig(); |
14 | 14 |
15 test("errors if two transformers output the same file", () { | 15 test("errors if two transformers output the same file", () { |
16 initGraph(["app|foo.a"], {"app": [ | 16 initGraph([ |
17 [ | 17 "app|foo.a" |
18 new RewriteTransformer("a", "b"), | 18 ], { |
19 new RewriteTransformer("a", "b") | 19 "app": [ |
| 20 [new RewriteTransformer("a", "b"), new RewriteTransformer("a", "b")] |
20 ] | 21 ] |
21 ]}); | 22 }); |
22 updateSources(["app|foo.a"]); | 23 updateSources(["app|foo.a"]); |
23 | 24 |
24 buildShouldFail([isAssetCollisionException("app|foo.b")]); | 25 buildShouldFail([isAssetCollisionException("app|foo.b")]); |
25 }); | 26 }); |
26 | 27 |
27 test("errors if a new transformer outputs the same file as an old " | 28 test( |
| 29 "errors if a new transformer outputs the same file as an old " |
28 "transformer", () { | 30 "transformer", () { |
29 initGraph(["app|foo.a", "app|foo.b"], {"app": [ | 31 initGraph([ |
30 [ | 32 "app|foo.a", |
31 new RewriteTransformer("a", "c"), | 33 "app|foo.b" |
32 new RewriteTransformer("b", "c") | 34 ], { |
| 35 "app": [ |
| 36 [new RewriteTransformer("a", "c"), new RewriteTransformer("b", "c")] |
33 ] | 37 ] |
34 ]}); | 38 }); |
35 updateSources(["app|foo.a"]); | 39 updateSources(["app|foo.a"]); |
36 expectAsset("app|foo.c", "foo.c"); | 40 expectAsset("app|foo.c", "foo.c"); |
37 buildShouldSucceed(); | 41 buildShouldSucceed(); |
38 | 42 |
39 updateSources(["app|foo.b"]); | 43 updateSources(["app|foo.b"]); |
40 buildShouldFail([isAssetCollisionException("app|foo.c")]); | 44 buildShouldFail([isAssetCollisionException("app|foo.c")]); |
41 }); | 45 }); |
42 | 46 |
43 test("a collision returns the first-produced output", () { | 47 test("a collision returns the first-produced output", () { |
44 var rewrite1 = new RewriteTransformer("one", "out"); | 48 var rewrite1 = new RewriteTransformer("one", "out"); |
45 var rewrite2 = new RewriteTransformer("two", "out"); | 49 var rewrite2 = new RewriteTransformer("two", "out"); |
46 initGraph({ | 50 initGraph({ |
47 "app|foo.one": "one", | 51 "app|foo.one": "one", |
48 "app|foo.two": "two" | 52 "app|foo.two": "two" |
49 }, {"app": [[rewrite1, rewrite2]]}); | 53 }, { |
| 54 "app": [ |
| 55 [rewrite1, rewrite2] |
| 56 ] |
| 57 }); |
50 | 58 |
51 rewrite1.pauseApply(); | 59 rewrite1.pauseApply(); |
52 updateSources(["app|foo.one", "app|foo.two"]); | 60 updateSources(["app|foo.one", "app|foo.two"]); |
53 // Wait long enough to ensure that rewrite2 has completed. | 61 // Wait long enough to ensure that rewrite2 has completed. |
54 schedule(pumpEventQueue); | 62 schedule(pumpEventQueue); |
55 | 63 |
56 rewrite1.resumeApply(); | 64 rewrite1.resumeApply(); |
57 expectAsset("app|foo.out", "two.out"); | 65 expectAsset("app|foo.out", "two.out"); |
58 buildShouldFail([isAssetCollisionException("app|foo.out")]); | 66 buildShouldFail([isAssetCollisionException("app|foo.out")]); |
59 | 67 |
60 // Even after the collision is discovered, the first-produced output should | 68 // Even after the collision is discovered, the first-produced output should |
61 // be returned. | 69 // be returned. |
62 expectAsset("app|foo.out", "two.out"); | 70 expectAsset("app|foo.out", "two.out"); |
63 | 71 |
64 // Even if the other output is updated more recently, the first output | 72 // Even if the other output is updated more recently, the first output |
65 // should continue to take precedence. | 73 // should continue to take precedence. |
66 updateSources(["app|foo.one"]); | 74 updateSources(["app|foo.one"]); |
67 expectAsset("app|foo.out", "two.out"); | 75 expectAsset("app|foo.out", "two.out"); |
68 }); | 76 }); |
69 | 77 |
70 test("a collision that is later resolved produces an output", () { | 78 test("a collision that is later resolved produces an output", () { |
71 initGraph({ | 79 initGraph({ |
72 "app|foo.one": "one", | 80 "app|foo.one": "one", |
73 "app|foo.two": "two" | 81 "app|foo.two": "two" |
74 }, {"app": [ | 82 }, { |
75 [ | 83 "app": [ |
76 new RewriteTransformer("one", "out"), | 84 [ |
77 new RewriteTransformer("two", "out") | 85 new RewriteTransformer("one", "out"), |
| 86 new RewriteTransformer("two", "out") |
| 87 ] |
78 ] | 88 ] |
79 ]}); | 89 }); |
80 | 90 |
81 updateSources(["app|foo.one"]); | 91 updateSources(["app|foo.one"]); |
82 expectAsset("app|foo.out", "one.out"); | 92 expectAsset("app|foo.out", "one.out"); |
83 buildShouldSucceed(); | 93 buildShouldSucceed(); |
84 | 94 |
85 updateSources(["app|foo.two"]); | 95 updateSources(["app|foo.two"]); |
86 expectAsset("app|foo.out", "one.out"); | 96 expectAsset("app|foo.out", "one.out"); |
87 buildShouldFail([isAssetCollisionException("app|foo.out")]); | 97 buildShouldFail([isAssetCollisionException("app|foo.out")]); |
88 | 98 |
89 removeSources(["app|foo.one"]); | 99 removeSources(["app|foo.one"]); |
90 expectAsset("app|foo.out", "two.out"); | 100 expectAsset("app|foo.out", "two.out"); |
91 buildShouldSucceed(); | 101 buildShouldSucceed(); |
92 }); | 102 }); |
93 | 103 |
94 test("a collision that is later resolved runs transforms", () { | 104 test("a collision that is later resolved runs transforms", () { |
95 initGraph({ | 105 initGraph({ |
96 "app|foo.one": "one", | 106 "app|foo.one": "one", |
97 "app|foo.two": "two" | 107 "app|foo.two": "two" |
98 }, {"app": [ | 108 }, { |
99 [ | 109 "app": [ |
100 new RewriteTransformer("one", "mid"), | 110 [ |
101 new RewriteTransformer("two", "mid") | 111 new RewriteTransformer("one", "mid"), |
102 ], | 112 new RewriteTransformer("two", "mid") |
103 [new RewriteTransformer("mid", "out")] | 113 ], |
104 ]}); | 114 [new RewriteTransformer("mid", "out")] |
| 115 ] |
| 116 }); |
105 | 117 |
106 updateSources(["app|foo.one"]); | 118 updateSources(["app|foo.one"]); |
107 expectAsset("app|foo.out", "one.mid.out"); | 119 expectAsset("app|foo.out", "one.mid.out"); |
108 buildShouldSucceed(); | 120 buildShouldSucceed(); |
109 | 121 |
110 updateSources(["app|foo.two"]); | 122 updateSources(["app|foo.two"]); |
111 expectAsset("app|foo.out", "one.mid.out"); | 123 expectAsset("app|foo.out", "one.mid.out"); |
112 buildShouldFail([isAssetCollisionException("app|foo.mid")]); | 124 buildShouldFail([isAssetCollisionException("app|foo.mid")]); |
113 | 125 |
114 removeSources(["app|foo.one"]); | 126 removeSources(["app|foo.one"]); |
115 expectAsset("app|foo.out", "two.mid.out"); | 127 expectAsset("app|foo.out", "two.mid.out"); |
116 buildShouldSucceed(); | 128 buildShouldSucceed(); |
117 }); | 129 }); |
118 | 130 |
119 test("a collision that is partially resolved returns the second completed " | 131 test( |
| 132 "a collision that is partially resolved returns the second completed " |
120 "output", () { | 133 "output", () { |
121 var rewrite1 = new RewriteTransformer("one", "out"); | 134 var rewrite1 = new RewriteTransformer("one", "out"); |
122 var rewrite2 = new RewriteTransformer("two", "out"); | 135 var rewrite2 = new RewriteTransformer("two", "out"); |
123 var rewrite3 = new RewriteTransformer("three", "out"); | 136 var rewrite3 = new RewriteTransformer("three", "out"); |
124 initGraph({ | 137 initGraph({ |
125 "app|foo.one": "one", | 138 "app|foo.one": "one", |
126 "app|foo.two": "two", | 139 "app|foo.two": "two", |
127 "app|foo.three": "three" | 140 "app|foo.three": "three" |
128 }, {"app": [[rewrite1, rewrite2, rewrite3]]}); | 141 }, { |
| 142 "app": [ |
| 143 [rewrite1, rewrite2, rewrite3] |
| 144 ] |
| 145 }); |
129 | 146 |
130 // Make rewrite3 the most-recently-completed transformer from the first run. | 147 // Make rewrite3 the most-recently-completed transformer from the first run. |
131 rewrite2.pauseApply(); | 148 rewrite2.pauseApply(); |
132 rewrite3.pauseApply(); | 149 rewrite3.pauseApply(); |
133 updateSources(["app|foo.one", "app|foo.two", "app|foo.three"]); | 150 updateSources(["app|foo.one", "app|foo.two", "app|foo.three"]); |
134 schedule(pumpEventQueue); | 151 schedule(pumpEventQueue); |
135 rewrite2.resumeApply(); | 152 rewrite2.resumeApply(); |
136 schedule(pumpEventQueue); | 153 schedule(pumpEventQueue); |
137 rewrite3.resumeApply(); | 154 rewrite3.resumeApply(); |
138 buildShouldFail([ | 155 buildShouldFail([ |
(...skipping 11 matching lines...) Expand all Loading... |
150 removeSources(["app|foo.one"]); | 167 removeSources(["app|foo.one"]); |
151 expectAsset("app|foo.out", "two.out"); | 168 expectAsset("app|foo.out", "two.out"); |
152 buildShouldFail([isAssetCollisionException("app|foo.out")]); | 169 buildShouldFail([isAssetCollisionException("app|foo.out")]); |
153 }); | 170 }); |
154 | 171 |
155 test("a collision with a pass-through asset returns the pass-through asset", | 172 test("a collision with a pass-through asset returns the pass-through asset", |
156 () { | 173 () { |
157 initGraph([ | 174 initGraph([ |
158 "app|foo.txt", | 175 "app|foo.txt", |
159 "app|foo.in" | 176 "app|foo.in" |
160 ], {"app": [ | 177 ], { |
161 [new RewriteTransformer("in", "txt")] | 178 "app": [ |
162 ]}); | 179 [new RewriteTransformer("in", "txt")] |
| 180 ] |
| 181 }); |
163 | 182 |
164 updateSources(["app|foo.txt", "app|foo.in"]); | 183 updateSources(["app|foo.txt", "app|foo.in"]); |
165 expectAsset("app|foo.txt", "foo"); | 184 expectAsset("app|foo.txt", "foo"); |
166 buildShouldFail([isAssetCollisionException("app|foo.txt")]); | 185 buildShouldFail([isAssetCollisionException("app|foo.txt")]); |
167 }); | 186 }); |
168 | 187 |
169 test("a new pass-through asset that collides returns the previous asset", () { | 188 test("a new pass-through asset that collides returns the previous asset", () { |
170 initGraph([ | 189 initGraph([ |
171 "app|foo.txt", | 190 "app|foo.txt", |
172 "app|foo.in" | 191 "app|foo.in" |
173 ], {"app": [ | 192 ], { |
174 [new RewriteTransformer("in", "txt")] | 193 "app": [ |
175 ]}); | 194 [new RewriteTransformer("in", "txt")] |
| 195 ] |
| 196 }); |
176 | 197 |
177 updateSources(["app|foo.in"]); | 198 updateSources(["app|foo.in"]); |
178 expectAsset("app|foo.txt", "foo.txt"); | 199 expectAsset("app|foo.txt", "foo.txt"); |
179 buildShouldSucceed(); | 200 buildShouldSucceed(); |
180 | 201 |
181 updateSources(["app|foo.txt"]); | 202 updateSources(["app|foo.txt"]); |
182 expectAsset("app|foo.txt", "foo.txt"); | 203 expectAsset("app|foo.txt", "foo.txt"); |
183 buildShouldFail([isAssetCollisionException("app|foo.txt")]); | 204 buildShouldFail([isAssetCollisionException("app|foo.txt")]); |
184 }); | 205 }); |
185 | 206 |
186 test("a new transform output that collides with a pass-through asset returns " | 207 test( |
| 208 "a new transform output that collides with a pass-through asset returns " |
187 "the pass-through asset", () { | 209 "the pass-through asset", () { |
188 initGraph([ | 210 initGraph([ |
189 "app|foo.txt", | 211 "app|foo.txt", |
190 "app|foo.in" | 212 "app|foo.in" |
191 ], {"app": [ | 213 ], { |
192 [new RewriteTransformer("in", "txt")] | 214 "app": [ |
193 ]}); | 215 [new RewriteTransformer("in", "txt")] |
| 216 ] |
| 217 }); |
194 | 218 |
195 updateSources(["app|foo.txt"]); | 219 updateSources(["app|foo.txt"]); |
196 expectAsset("app|foo.txt", "foo"); | 220 expectAsset("app|foo.txt", "foo"); |
197 buildShouldSucceed(); | 221 buildShouldSucceed(); |
198 | 222 |
199 updateSources(["app|foo.in"]); | 223 updateSources(["app|foo.in"]); |
200 expectAsset("app|foo.txt", "foo"); | 224 expectAsset("app|foo.txt", "foo"); |
201 buildShouldFail([isAssetCollisionException("app|foo.txt")]); | 225 buildShouldFail([isAssetCollisionException("app|foo.txt")]); |
202 }); | 226 }); |
203 } | 227 } |
OLD | NEW |