| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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.package_graph.transform.aggregate_test; | |
| 6 | |
| 7 import 'package:barback/src/utils.dart'; | |
| 8 import 'package:scheduled_test/scheduled_test.dart'; | |
| 9 | |
| 10 import '../../utils.dart'; | |
| 11 | |
| 12 main() { | |
| 13 initConfig(); | |
| 14 test("an aggregate transformer can read from multiple primary inputs", () { | |
| 15 var sources = [ | |
| 16 "app|dir/foo.txt", | |
| 17 "app|dir/bar.txt", | |
| 18 "app|dir/baz.jpg", | |
| 19 "app|dir/subdir/bang.txt", | |
| 20 "app|dir/subdir/qux.txt", | |
| 21 "app|dir/subdir/zap.png" | |
| 22 ]; | |
| 23 | |
| 24 initGraph(sources, {"app": [ | |
| 25 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 26 ]}); | |
| 27 | |
| 28 updateSources(sources); | |
| 29 expectAsset("app|dir/out.txt", "bar\nfoo"); | |
| 30 expectAsset("app|dir/subdir/out.txt", "bang\nqux"); | |
| 31 buildShouldSucceed(); | |
| 32 }); | |
| 33 | |
| 34 test("an aggregate transformer isn't run if there are no primary inputs", () { | |
| 35 var transformer = new AggregateManyToOneTransformer("txt", "out.txt"); | |
| 36 initGraph(["app|foo.zip", "app|bar.zap"], {"app": [ | |
| 37 [transformer] | |
| 38 ]}); | |
| 39 | |
| 40 updateSources(["app|foo.zip", "app|bar.zap"]); | |
| 41 expectNoAsset("app|out.txt"); | |
| 42 buildShouldSucceed(); | |
| 43 | |
| 44 expect(transformer.numRuns, completion(equals(0))); | |
| 45 }); | |
| 46 | |
| 47 test("an aggregate transformer is re-run if a primary input changes", () { | |
| 48 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [ | |
| 49 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 50 ]}); | |
| 51 | |
| 52 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 53 expectAsset("app|out.txt", "bar\nfoo"); | |
| 54 buildShouldSucceed(); | |
| 55 | |
| 56 modifyAsset("app|foo.txt", "new foo"); | |
| 57 updateSources(["app|foo.txt"]); | |
| 58 expectAsset("app|out.txt", "bar\nnew foo"); | |
| 59 buildShouldSucceed(); | |
| 60 }); | |
| 61 | |
| 62 test("an aggregate transformer is re-run if a primary input is removed", () { | |
| 63 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [ | |
| 64 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 65 ]}); | |
| 66 | |
| 67 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 68 expectAsset("app|out.txt", "bar\nfoo"); | |
| 69 buildShouldSucceed(); | |
| 70 | |
| 71 removeSources(["app|foo.txt"]); | |
| 72 expectAsset("app|out.txt", "bar"); | |
| 73 buildShouldSucceed(); | |
| 74 }); | |
| 75 | |
| 76 test("an aggregate transformer is re-run if a primary input is added", () { | |
| 77 initGraph(["app|foo.txt", "app|bar.txt", "app|baz.txt"], {"app": [ | |
| 78 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 79 ]}); | |
| 80 | |
| 81 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 82 expectAsset("app|out.txt", "bar\nfoo"); | |
| 83 buildShouldSucceed(); | |
| 84 | |
| 85 updateSources(["app|baz.txt"]); | |
| 86 expectAsset("app|out.txt", "bar\nbaz\nfoo"); | |
| 87 buildShouldSucceed(); | |
| 88 }); | |
| 89 | |
| 90 test("an aggregate transformer ceases to run if all primary inputs are " | |
| 91 "removed", () { | |
| 92 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [ | |
| 93 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 94 ]}); | |
| 95 | |
| 96 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 97 expectAsset("app|out.txt", "bar\nfoo"); | |
| 98 buildShouldSucceed(); | |
| 99 | |
| 100 removeSources(["app|foo.txt", "app|bar.txt"]); | |
| 101 expectNoAsset("app|out.txt"); | |
| 102 buildShouldSucceed(); | |
| 103 }); | |
| 104 | |
| 105 test("an aggregate transformer starts to run if new primary inputs are " | |
| 106 "added", () { | |
| 107 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [ | |
| 108 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 109 ]}); | |
| 110 | |
| 111 updateSources([]); | |
| 112 expectNoAsset("app|out.txt"); | |
| 113 buildShouldSucceed(); | |
| 114 | |
| 115 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 116 expectAsset("app|out.txt", "bar\nfoo"); | |
| 117 buildShouldSucceed(); | |
| 118 }); | |
| 119 | |
| 120 group("pass-through", () { | |
| 121 test("an aggregate transformer passes through its primary inputs by " | |
| 122 "default", () { | |
| 123 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [ | |
| 124 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 125 ]}); | |
| 126 | |
| 127 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 128 expectAsset("app|foo.txt", "foo"); | |
| 129 expectAsset("app|bar.txt", "bar"); | |
| 130 buildShouldSucceed(); | |
| 131 | |
| 132 modifyAsset("app|foo.txt", "new foo"); | |
| 133 updateSources(["app|foo.txt"]); | |
| 134 expectAsset("app|foo.txt", "new foo"); | |
| 135 buildShouldSucceed(); | |
| 136 }); | |
| 137 | |
| 138 test("an aggregate transformer can overwrite its primary inputs", () { | |
| 139 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [ | |
| 140 [new AggregateManyToManyTransformer("txt")] | |
| 141 ]}); | |
| 142 | |
| 143 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 144 expectAsset("app|foo.txt", "modified foo"); | |
| 145 expectAsset("app|bar.txt", "modified bar"); | |
| 146 buildShouldSucceed(); | |
| 147 }); | |
| 148 | |
| 149 test("an aggregate transformer can consume its primary inputs", () { | |
| 150 var transformer = new AggregateManyToOneTransformer("txt", "out.txt"); | |
| 151 transformer.consumePrimaries | |
| 152 ..add("app|foo.txt") | |
| 153 ..add("app|bar.txt"); | |
| 154 | |
| 155 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [[transformer]]}); | |
| 156 | |
| 157 updateSources(["app|foo.txt", "app|bar.txt"]); | |
| 158 expectNoAsset("app|foo.txt"); | |
| 159 expectNoAsset("app|bar.txt"); | |
| 160 buildShouldSucceed(); | |
| 161 }); | |
| 162 | |
| 163 test("an aggregate transformer passes through non-primary inputs", () { | |
| 164 initGraph(["app|foo.jpg", "app|bar.png"], {"app": [ | |
| 165 [new AggregateManyToManyTransformer("txt")] | |
| 166 ]}); | |
| 167 | |
| 168 updateSources(["app|foo.jpg", "app|bar.png"]); | |
| 169 expectAsset("app|foo.jpg", "foo"); | |
| 170 expectAsset("app|bar.png", "bar"); | |
| 171 buildShouldSucceed(); | |
| 172 | |
| 173 modifyAsset("app|foo.jpg", "new foo"); | |
| 174 updateSources(["app|foo.jpg"]); | |
| 175 expectAsset("app|foo.jpg", "new foo"); | |
| 176 buildShouldSucceed(); | |
| 177 }); | |
| 178 }); | |
| 179 | |
| 180 group("apply() transform stream", () { | |
| 181 test("the primary input stream doesn't close if a previous phase is still " | |
| 182 "running", () { | |
| 183 var rewrite = new RewriteTransformer("a", "b"); | |
| 184 initGraph(["app|foo.txt", "app|bar.a"], {"app": [ | |
| 185 [rewrite], | |
| 186 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 187 ]}); | |
| 188 | |
| 189 rewrite.pauseApply(); | |
| 190 updateSources(["app|foo.txt", "app|bar.a"]); | |
| 191 expectAssetDoesNotComplete("app|out.txt"); | |
| 192 | |
| 193 rewrite.resumeApply(); | |
| 194 expectAsset("app|out.txt", "foo"); | |
| 195 buildShouldSucceed(); | |
| 196 }); | |
| 197 | |
| 198 test("the primary input stream doesn't close if a previous phase is " | |
| 199 "materializing a primary input", () { | |
| 200 var rewrite = new DeclaringRewriteTransformer("in", "txt"); | |
| 201 initGraph(["app|foo.txt", "app|bar.in"], {"app": [ | |
| 202 [rewrite], | |
| 203 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 204 ]}); | |
| 205 | |
| 206 rewrite.pauseApply(); | |
| 207 updateSources(["app|foo.txt", "app|bar.in"]); | |
| 208 expectAssetDoesNotComplete("app|out.txt"); | |
| 209 | |
| 210 rewrite.resumeApply(); | |
| 211 expectAsset("app|out.txt", "bar.txt\nfoo"); | |
| 212 buildShouldSucceed(); | |
| 213 }); | |
| 214 | |
| 215 test("the primary input stream closes if a previous phase is only " | |
| 216 "materializing non-primary inputs", () { | |
| 217 var rewrite = new DeclaringRewriteTransformer("a", "b"); | |
| 218 initGraph(["app|foo.txt", "app|bar.a"], {"app": [ | |
| 219 [rewrite], | |
| 220 [new AggregateManyToOneTransformer("txt", "out.txt")] | |
| 221 ]}); | |
| 222 | |
| 223 rewrite.pauseApply(); | |
| 224 updateSources(["app|foo.txt", "app|bar.a"]); | |
| 225 expectAsset("app|out.txt", "foo"); | |
| 226 | |
| 227 rewrite.resumeApply(); | |
| 228 buildShouldSucceed(); | |
| 229 }); | |
| 230 | |
| 231 test("a new primary input that arrives before the stream closes doesn't " | |
| 232 "cause apply to restart", () { | |
| 233 var rewrite = new RewriteTransformer("a", "b"); | |
| 234 var aggregate = new AggregateManyToOneTransformer("txt", "out.txt"); | |
| 235 initGraph(["app|foo.txt", "app|bar.txt", "app|baz.a"], {"app": [ | |
| 236 [rewrite], | |
| 237 [aggregate] | |
| 238 ]}); | |
| 239 | |
| 240 // The stream won't close until [rewrite] finishes running `apply()`. | |
| 241 rewrite.pauseApply(); | |
| 242 | |
| 243 updateSources(["app|foo.txt", "app|baz.a"]); | |
| 244 expectAssetDoesNotComplete("app|out.txt"); | |
| 245 | |
| 246 updateSources(["app|bar.txt"]); | |
| 247 expectAssetDoesNotComplete("app|out.txt"); | |
| 248 | |
| 249 rewrite.resumeApply(); | |
| 250 expectAsset("app|out.txt", "bar\nfoo"); | |
| 251 buildShouldSucceed(); | |
| 252 | |
| 253 expect(aggregate.numRuns, completion(equals(1))); | |
| 254 }); | |
| 255 | |
| 256 test("a new primary input that arrives after the stream closes causes " | |
| 257 "apply to restart", () { | |
| 258 var aggregate = new AggregateManyToOneTransformer("txt", "out.txt"); | |
| 259 initGraph(["app|foo.txt", "app|bar.txt"], {"app": [[aggregate]]}); | |
| 260 | |
| 261 aggregate.pauseApply(); | |
| 262 updateSources(["app|foo.txt"]); | |
| 263 expectAssetDoesNotComplete("app|out.txt"); | |
| 264 | |
| 265 updateSources(["app|bar.txt"]); | |
| 266 expectAssetDoesNotComplete("app|out.txt"); | |
| 267 | |
| 268 aggregate.resumeApply(); | |
| 269 expectAsset("app|out.txt", "bar\nfoo"); | |
| 270 buildShouldSucceed(); | |
| 271 | |
| 272 expect(aggregate.numRuns, completion(equals(2))); | |
| 273 }); | |
| 274 | |
| 275 test("a primary input that's modified before the stream closes causes " | |
| 276 "apply to restart", () { | |
| 277 var rewrite = new RewriteTransformer("a", "b"); | |
| 278 var aggregate = new AggregateManyToOneTransformer("txt", "out.txt"); | |
| 279 initGraph(["app|foo.txt", "app|bar.a"], {"app": [ | |
| 280 [rewrite], | |
| 281 [aggregate] | |
| 282 ]}); | |
| 283 | |
| 284 // The stream won't close until [rewrite] finishes running `apply()`. | |
| 285 rewrite.pauseApply(); | |
| 286 | |
| 287 updateSources(["app|foo.txt", "app|bar.a"]); | |
| 288 expectAssetDoesNotComplete("app|out.txt"); | |
| 289 | |
| 290 modifyAsset("app|foo.txt", "new foo"); | |
| 291 updateSources(["app|foo.txt"]); | |
| 292 expectAssetDoesNotComplete("app|out.txt"); | |
| 293 | |
| 294 rewrite.resumeApply(); | |
| 295 expectAsset("app|out.txt", "new foo"); | |
| 296 buildShouldSucceed(); | |
| 297 | |
| 298 expect(aggregate.numRuns, completion(equals(2))); | |
| 299 }); | |
| 300 | |
| 301 test("a primary input that's removed before the stream closes causes apply " | |
| 302 "to restart", () { | |
| 303 var rewrite = new RewriteTransformer("a", "b"); | |
| 304 var aggregate = new AggregateManyToOneTransformer("txt", "out.txt"); | |
| 305 initGraph(["app|foo.txt", "app|bar.txt", "app|baz.a"], {"app": [ | |
| 306 [rewrite], | |
| 307 [aggregate] | |
| 308 ]}); | |
| 309 | |
| 310 // The stream won't close until [rewrite] finishes running `apply()`. | |
| 311 rewrite.pauseApply(); | |
| 312 | |
| 313 updateSources(["app|foo.txt", "app|bar.txt", "app|baz.a"]); | |
| 314 expectAssetDoesNotComplete("app|out.txt"); | |
| 315 | |
| 316 removeSources(["app|bar.txt"]); | |
| 317 expectAssetDoesNotComplete("app|out.txt"); | |
| 318 | |
| 319 rewrite.resumeApply(); | |
| 320 expectAsset("app|out.txt", "foo"); | |
| 321 buildShouldSucceed(); | |
| 322 | |
| 323 expect(aggregate.numRuns, completion(equals(2))); | |
| 324 }); | |
| 325 }); | |
| 326 } | |
| OLD | NEW |