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.declaring_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 group("a declaring aggregate transformer", () { |
| 15 test("is eager by default", () { |
| 16 var transformer = new DeclaringAggregateManyToOneTransformer( |
| 17 "txt", "out.txt"); |
| 18 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 19 |
| 20 updateSources(["app|foo.txt"]); |
| 21 buildShouldSucceed(); |
| 22 |
| 23 expect(transformer.numRuns, completion(equals(1))); |
| 24 }); |
| 25 |
| 26 test("is deferred if any primary input is deferred", () { |
| 27 var rewrite = new LazyRewriteTransformer("in", "txt"); |
| 28 var aggregate = new DeclaringAggregateManyToOneTransformer( |
| 29 "txt", "out.txt"); |
| 30 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [ |
| 31 [rewrite] |
| 32 ]}); |
| 33 |
| 34 updateSources(["app|foo.in", "app|bar.txt", "app|baz.txt"]); |
| 35 buildShouldSucceed(); |
| 36 |
| 37 // Add [aggregate] to the graph after a build has been completed so that |
| 38 // all its inputs are available immediately. Otherwise it could start |
| 39 // applying eagerly before receiving its lazy input. |
| 40 updateTransformers("app", [[rewrite], [aggregate]]); |
| 41 buildShouldSucceed(); |
| 42 expect(aggregate.numRuns, completion(equals(0))); |
| 43 |
| 44 expectAsset("app|out.txt", "bar\nbaz\nfoo.txt"); |
| 45 buildShouldSucceed(); |
| 46 expect(aggregate.numRuns, completion(equals(1))); |
| 47 }); |
| 48 |
| 49 test("switches from eager to deferred if a deferred primary input is added", |
| 50 () { |
| 51 var transformer = new DeclaringAggregateManyToOneTransformer( |
| 52 "txt", "out.txt"); |
| 53 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [ |
| 54 [new LazyRewriteTransformer("in", "txt")], |
| 55 [transformer] |
| 56 ]}); |
| 57 |
| 58 updateSources(["app|bar.txt", "app|baz.txt"]); |
| 59 buildShouldSucceed(); |
| 60 expect(transformer.numRuns, completion(equals(1))); |
| 61 |
| 62 updateSources(["app|foo.in"]); |
| 63 buildShouldSucceed(); |
| 64 expect(transformer.numRuns, completion(equals(1))); |
| 65 |
| 66 expectAsset("app|out.txt", "bar\nbaz\nfoo.txt"); |
| 67 buildShouldSucceed(); |
| 68 expect(transformer.numRuns, completion(equals(2))); |
| 69 }); |
| 70 |
| 71 test("switches from deferred to eager if its last deferred primary input " |
| 72 "is removed", () { |
| 73 var rewrite = new LazyRewriteTransformer("in", "txt"); |
| 74 var aggregate = new DeclaringAggregateManyToOneTransformer( |
| 75 "txt", "out.txt"); |
| 76 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [ |
| 77 [rewrite] |
| 78 ]}); |
| 79 |
| 80 updateSources(["app|foo.in", "app|bar.txt", "app|baz.txt"]); |
| 81 buildShouldSucceed(); |
| 82 |
| 83 // Add [aggregate] to the graph after a build has been completed so that |
| 84 // all its inputs are available immediately. Otherwise it could start |
| 85 // applying eagerly before receiving its lazy input. |
| 86 updateTransformers("app", [[rewrite], [aggregate]]); |
| 87 buildShouldSucceed(); |
| 88 expect(aggregate.numRuns, completion(equals(0))); |
| 89 |
| 90 removeSources(["app|foo.in"]); |
| 91 buildShouldSucceed(); |
| 92 expect(aggregate.numRuns, completion(equals(1))); |
| 93 }); |
| 94 |
| 95 test("begins running eagerly when all its deferred primary inputs become " |
| 96 "available", () { |
| 97 var lazyPhase = [ |
| 98 new LazyAssetsTransformer(["app|foo.txt", "app|foo.x"], |
| 99 input: "app|foo.in"), |
| 100 new LazyAssetsTransformer(["app|bar.txt", "app|bar.x"], |
| 101 input: "app|bar.in") |
| 102 ]; |
| 103 var transformer = new DeclaringAggregateManyToOneTransformer( |
| 104 "txt", "out.txt"); |
| 105 initGraph(["app|foo.in", "app|bar.in", "app|baz.txt"], {"app": [ |
| 106 lazyPhase, |
| 107 ]}); |
| 108 |
| 109 updateSources(["app|foo.in", "app|bar.in", "app|baz.txt"]); |
| 110 buildShouldSucceed(); |
| 111 |
| 112 // Add [transformer] to the graph after a build has been completed so that |
| 113 // all its inputs are available immediately. Otherwise it could start |
| 114 // applying eagerly before receiving its lazy inputs. |
| 115 updateTransformers("app", [lazyPhase, [transformer]]); |
| 116 buildShouldSucceed(); |
| 117 expect(transformer.numRuns, completion(equals(0))); |
| 118 |
| 119 // Now "app|foo.txt" will be available, but "app|bar.txt" won't, so the |
| 120 // [transformer] shouldn't run. |
| 121 expectAsset("app|foo.x", "app|foo.x"); |
| 122 buildShouldSucceed(); |
| 123 expect(transformer.numRuns, completion(equals(0))); |
| 124 |
| 125 // Now "app|foo.txt" and "app|bar.txt" will both be available, so the |
| 126 // [transformer] should run. |
| 127 expectAsset("app|bar.x", "app|bar.x"); |
| 128 buildShouldSucceed(); |
| 129 expect(transformer.numRuns, completion(equals(1))); |
| 130 }); |
| 131 |
| 132 test("stops running eagerly when any of its deferred primary inputs become " |
| 133 "unavailable", () { |
| 134 var lazyPhase = [ |
| 135 new LazyAssetsTransformer(["app|foo.txt", "app|foo.x"], |
| 136 input: "app|foo.in"), |
| 137 new LazyAssetsTransformer(["app|bar.txt", "app|bar.x"], |
| 138 input: "app|bar.in") |
| 139 ]; |
| 140 var transformer = new DeclaringAggregateManyToOneTransformer( |
| 141 "txt", "out.txt"); |
| 142 initGraph(["app|foo.in", "app|bar.in", "app|baz.txt"], {"app": [ |
| 143 lazyPhase |
| 144 ]}); |
| 145 |
| 146 updateSources(["app|foo.in", "app|bar.in", "app|baz.txt"]); |
| 147 expectAsset("app|foo.x", "app|foo.x"); |
| 148 expectAsset("app|bar.x", "app|bar.x"); |
| 149 buildShouldSucceed(); |
| 150 |
| 151 // Add [transformer] to the graph after a build has been completed so that |
| 152 // all its inputs are available immediately. Otherwise it could start |
| 153 // applying eagerly before receiving its lazy inputs. |
| 154 updateTransformers("app", [lazyPhase, [transformer]]); |
| 155 buildShouldSucceed(); |
| 156 expect(transformer.numRuns, completion(equals(1))); |
| 157 |
| 158 // Now "app|foo.txt" is unavailable, so the [transformer] shouldn't run. |
| 159 updateSources(["app|foo.in"]); |
| 160 buildShouldSucceed(); |
| 161 expect(transformer.numRuns, completion(equals(1))); |
| 162 }); |
| 163 |
| 164 test("re-declares its outputs for a new primary input", () { |
| 165 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [ |
| 166 [new LazyRewriteTransformer("in", "txt")], |
| 167 [new DeclaringAggregateManyToManyTransformer("txt")] |
| 168 ]}); |
| 169 |
| 170 updateSources(["app|foo.in", "app|bar.txt"]); |
| 171 buildShouldSucceed(); |
| 172 |
| 173 updateSources(["app|baz.txt"]); |
| 174 buildShouldSucceed(); |
| 175 |
| 176 // If the aggregate transformer didn't re-declare its outputs upon getting |
| 177 // a new primary input, getting "baz.txt" wouldn't trigger an apply and |
| 178 // would just return the unmodified baz. |
| 179 expectAsset("app|baz.txt", "modified baz"); |
| 180 }); |
| 181 |
| 182 test("re-declares its outputs for a new primary input received while " |
| 183 "applying", () { |
| 184 var transformer = new DeclaringAggregateManyToManyTransformer("txt"); |
| 185 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [ |
| 186 [new LazyRewriteTransformer("in", "txt")], |
| 187 [transformer] |
| 188 ]}); |
| 189 |
| 190 transformer.pauseApply(); |
| 191 updateSources(["app|foo.in", "app|bar.txt"]); |
| 192 |
| 193 // Ensure we're waiting on `apply()`. |
| 194 schedule(pumpEventQueue); |
| 195 |
| 196 updateSources(["app|baz.txt"]); |
| 197 transformer.resumeApply(); |
| 198 buildShouldSucceed(); |
| 199 |
| 200 expectAsset("app|baz.txt", "modified baz"); |
| 201 }); |
| 202 |
| 203 test("re-declares its outputs for a new primary input received while " |
| 204 "applying after a primary input was modified", () { |
| 205 var transformer = new DeclaringAggregateManyToManyTransformer("txt"); |
| 206 initGraph(["app|foo.in", "app|bar.txt", "app|baz.txt"], {"app": [ |
| 207 [new LazyRewriteTransformer("in", "txt")], |
| 208 [transformer] |
| 209 ]}); |
| 210 |
| 211 transformer.pauseApply(); |
| 212 updateSources(["app|foo.in", "app|bar.txt"]); |
| 213 |
| 214 // Ensure we're waiting on `apply()`. |
| 215 schedule(pumpEventQueue); |
| 216 |
| 217 updateSources(["app|bar.txt"]); |
| 218 |
| 219 // Make sure the change to "bar.txt" is fully processed. |
| 220 schedule(pumpEventQueue); |
| 221 |
| 222 updateSources(["app|baz.txt"]); |
| 223 transformer.resumeApply(); |
| 224 buildShouldSucceed(); |
| 225 |
| 226 expectAsset("app|baz.txt", "modified baz"); |
| 227 }); |
| 228 }); |
| 229 |
| 230 group("a lazy aggregate transformer", () { |
| 231 test("doesn't run eagerly", () { |
| 232 var transformer = new LazyAggregateManyToOneTransformer("txt", "out.txt"); |
| 233 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 234 |
| 235 updateSources(["app|foo.txt"]); |
| 236 buildShouldSucceed(); |
| 237 |
| 238 expect(transformer.numRuns, completion(equals(0))); |
| 239 }); |
| 240 |
| 241 test("runs when an output is requested", () { |
| 242 initGraph(["app|foo.txt"], {"app": [[ |
| 243 new LazyAggregateManyToOneTransformer("txt", "out.txt") |
| 244 ]]}); |
| 245 |
| 246 updateSources(["app|foo.txt"]); |
| 247 buildShouldSucceed(); |
| 248 expectAsset("app|out.txt", "foo"); |
| 249 }); |
| 250 }); |
| 251 } |
OLD | NEW |