| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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.declaring_transformer_test; | 5 library barback.test.package_graph.declaring_transformer_test; |
| 6 | 6 |
| 7 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
| 8 import 'package:barback/src/utils.dart'; | 8 import 'package:barback/src/utils.dart'; |
| 9 import 'package:scheduled_test/scheduled_test.dart'; | 9 import 'package:scheduled_test/scheduled_test.dart'; |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 54 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 55 | 55 |
| 56 transformer.pauseApply(); | 56 transformer.pauseApply(); |
| 57 updateSources(["app|foo.blub"]); | 57 updateSources(["app|foo.blub"]); |
| 58 expectAsset("app|foo.blub", "foo"); | 58 expectAsset("app|foo.blub", "foo"); |
| 59 | 59 |
| 60 transformer.resumeApply(); | 60 transformer.resumeApply(); |
| 61 buildShouldSucceed(); | 61 buildShouldSucceed(); |
| 62 }); | 62 }); |
| 63 | 63 |
| 64 // TODO(nweiz): Enable this test when issue 18226 is fixed. | 64 test("fails to get a consumed asset before apply is finished", () { |
| 65 // test("fails to get a consumed asset before apply is finished", () { | 65 var transformer = new DeclaringRewriteTransformer("blub", "blab") |
| 66 // var transformer = new DeclaringRewriteTransformer("blub", "blab") | 66 ..consumePrimary = true; |
| 67 // ..consumePrimary = true; | 67 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 68 // initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 68 |
| 69 // | 69 transformer.pauseApply(); |
| 70 // transformer.pauseApply(); | 70 updateSources(["app|foo.blub"]); |
| 71 // updateSources(["app|foo.blub"]); | 71 expectNoAsset("app|foo.blub"); |
| 72 // expectNoAsset("app|foo.blub"); | 72 |
| 73 // | 73 transformer.resumeApply(); |
| 74 // transformer.resumeApply(); | 74 buildShouldSucceed(); |
| 75 // buildShouldSucceed(); | 75 }); |
| 76 // }); | 76 |
| 77 test("blocks on getting a declared asset that wasn't generated last run", () { |
| 78 var transformer = new DeclaringCheckContentAndRenameTransformer( |
| 79 oldExtension: "txt", oldContent: "yes", |
| 80 newExtension: "out", newContent: "done"); |
| 81 initGraph({"app|foo.txt": "no"}, {"app": [[transformer]]}); |
| 82 |
| 83 updateSources(["app|foo.txt"]); |
| 84 expectNoAsset("app|foo.out"); |
| 85 buildShouldSucceed(); |
| 86 |
| 87 // The transform should remember that foo.out was declared, so it should |
| 88 // expect that it might still be generated even though it wasn't last time. |
| 89 transformer.pauseApply(); |
| 90 modifyAsset("app|foo.txt", "yes"); |
| 91 updateSources(["app|foo.txt"]); |
| 92 expectAssetDoesNotComplete("app|foo.out"); |
| 93 |
| 94 transformer.resumeApply(); |
| 95 expectAsset("app|foo.out", "done"); |
| 96 buildShouldSucceed(); |
| 97 }); |
| 98 |
| 99 test("doesn't block on on getting an undeclared asset that wasn't generated " |
| 100 "last run", () { |
| 101 var transformer = new DeclaringCheckContentAndRenameTransformer( |
| 102 oldExtension: "txt", oldContent: "yes", |
| 103 newExtension: "out", newContent: "done"); |
| 104 initGraph({"app|foo.txt": "no"}, {"app": [[transformer]]}); |
| 105 |
| 106 updateSources(["app|foo.txt"]); |
| 107 expectNoAsset("app|foo.out"); |
| 108 buildShouldSucceed(); |
| 109 |
| 110 transformer.pauseApply(); |
| 111 modifyAsset("app|foo.txt", "yes"); |
| 112 updateSources(["app|foo.txt"]); |
| 113 expectNoAsset("app|undeclared.out"); |
| 114 |
| 115 transformer.resumeApply(); |
| 116 buildShouldSucceed(); |
| 117 }); |
| 118 |
| 119 test("fails to get a consumed asset before apply is finished when a sibling " |
| 120 "has finished applying", () { |
| 121 var transformer = new DeclaringRewriteTransformer("blub", "blab") |
| 122 ..consumePrimary = true; |
| 123 initGraph(["app|foo.blub", "app|foo.txt"], {"app": [[ |
| 124 transformer, |
| 125 new RewriteTransformer("txt", "out") |
| 126 ]]}); |
| 127 |
| 128 transformer.pauseApply(); |
| 129 updateSources(["app|foo.blub", "app|foo.txt"]); |
| 130 expectAsset("app|foo.out", "foo.out"); |
| 131 expectNoAsset("app|foo.blub"); |
| 132 |
| 133 transformer.resumeApply(); |
| 134 buildShouldSucceed(); |
| 135 }); |
| 136 |
| 137 test("blocks getting a consumed asset before apply is finished when a " |
| 138 "sibling hasn't finished applying", () { |
| 139 var declaring = new DeclaringRewriteTransformer("blub", "blab") |
| 140 ..consumePrimary = true; |
| 141 var eager = new RewriteTransformer("txt", "out"); |
| 142 initGraph(["app|foo.blub", "app|foo.txt"], {"app": [[declaring, eager]]}); |
| 143 |
| 144 declaring.pauseApply(); |
| 145 eager.pauseApply(); |
| 146 updateSources(["app|foo.blub", "app|foo.txt"]); |
| 147 expectAssetDoesNotComplete("app|foo.blub"); |
| 148 |
| 149 declaring.resumeApply(); |
| 150 eager.resumeApply(); |
| 151 expectNoAsset("app|foo.blub"); |
| 152 buildShouldSucceed(); |
| 153 }); |
| 77 | 154 |
| 78 test("waits until apply is finished to get an overwritten asset", () { | 155 test("waits until apply is finished to get an overwritten asset", () { |
| 79 var transformer = new DeclaringRewriteTransformer("blub", "blub"); | 156 var transformer = new DeclaringRewriteTransformer("blub", "blub"); |
| 80 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 157 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 81 | 158 |
| 82 transformer.pauseApply(); | 159 transformer.pauseApply(); |
| 83 updateSources(["app|foo.blub"]); | 160 updateSources(["app|foo.blub"]); |
| 84 expectAssetDoesNotComplete("app|foo.blub"); | 161 expectAssetDoesNotComplete("app|foo.blub"); |
| 85 | 162 |
| 86 transformer.resumeApply(); | 163 transformer.resumeApply(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Once we make a request, [declaring] should force the lazy transformer and | 213 // Once we make a request, [declaring] should force the lazy transformer and |
| 137 // then run itself. | 214 // then run itself. |
| 138 expectAsset("app|out.three", "app|out.two.three"); | 215 expectAsset("app|out.three", "app|out.two.three"); |
| 139 buildShouldSucceed(); | 216 buildShouldSucceed(); |
| 140 | 217 |
| 141 // Now [declaring] should have run twice. This ensures that it didn't use | 218 // Now [declaring] should have run twice. This ensures that it didn't use |
| 142 // its original output for some reason. | 219 // its original output for some reason. |
| 143 expect(declaring.numRuns, completion(equals(2))); | 220 expect(declaring.numRuns, completion(equals(2))); |
| 144 }); | 221 }); |
| 145 | 222 |
| 146 group("with an error in declareOutputs", () { | 223 // TODO(nweiz): Re-enable these when barback is capable of dealing with a |
| 147 test("still runs apply", () { | 224 // changing [TransformNode.deferred] value. |
| 148 initGraph(["app|foo.txt"], {"app": [[ | 225 // group("with an error in declareOutputs", () { |
| 149 new DeclaringBadTransformer("app|out.txt", | 226 // test("still runs apply", () { |
| 150 declareError: true, applyError: false) | 227 // initGraph(["app|foo.txt"], {"app": [[ |
| 151 ]]}); | 228 // new DeclaringBadTransformer("app|out.txt", |
| 152 | 229 // declareError: true, applyError: false) |
| 153 updateSources(["app|foo.txt"]); | 230 // ]]}); |
| 154 expectAsset("app|out.txt", "bad out"); | 231 // |
| 155 expectAsset("app|foo.txt", "foo"); | 232 // updateSources(["app|foo.txt"]); |
| 156 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); | 233 // expectAsset("app|out.txt", "bad out"); |
| 157 }); | 234 // expectAsset("app|foo.txt", "foo"); |
| 158 | 235 // buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 159 test("waits for apply to complete before passing through the input even if " | 236 // }); |
| 160 "consumePrimary was called", () { | 237 // |
| 161 var transformer = new DeclaringBadTransformer("app|out.txt", | 238 // test("waits for apply to complete before passing through the input even i
f " |
| 162 declareError: true, applyError: false)..consumePrimary = true; | 239 // "consumePrimary was called", () { |
| 163 initGraph(["app|foo.txt"], {"app": [[transformer]]}); | 240 // var transformer = new DeclaringBadTransformer("app|out.txt", |
| 164 | 241 // declareError: true, applyError: false)..consumePrimary = true; |
| 165 transformer.pauseApply(); | 242 // initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 166 updateSources(["app|foo.txt"]); | 243 // |
| 167 expectAssetDoesNotComplete("app|out.txt"); | 244 // transformer.pauseApply(); |
| 168 expectAssetDoesNotComplete("app|foo.txt"); | 245 // updateSources(["app|foo.txt"]); |
| 169 | 246 // expectAssetDoesNotComplete("app|out.txt"); |
| 170 transformer.resumeApply(); | 247 // expectAssetDoesNotComplete("app|foo.txt"); |
| 171 expectAsset("app|out.txt", "bad out"); | 248 // |
| 172 expectNoAsset("app|foo.txt"); | 249 // transformer.resumeApply(); |
| 173 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); | 250 // expectAsset("app|out.txt", "bad out"); |
| 174 }); | 251 // expectNoAsset("app|foo.txt"); |
| 175 }); | 252 // buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 253 // }); |
| 254 // }); |
| 176 | 255 |
| 177 test("with an error in apply still passes through the input", () { | 256 test("with an error in apply still passes through the input", () { |
| 178 initGraph(["app|foo.txt"], {"app": [[ | 257 initGraph(["app|foo.txt"], {"app": [[ |
| 179 new DeclaringBadTransformer("app|out.txt", | 258 new DeclaringBadTransformer("app|out.txt", |
| 180 declareError: false, applyError: true) | 259 declareError: false, applyError: true) |
| 181 ]]}); | 260 ]]}); |
| 182 | 261 |
| 183 updateSources(["app|foo.txt"]); | 262 updateSources(["app|foo.txt"]); |
| 184 expectNoAsset("app|out.txt"); | 263 expectNoAsset("app|out.txt"); |
| 185 expectAsset("app|foo.txt", "foo"); | 264 expectAsset("app|foo.txt", "foo"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 test("can declare outputs it doesn't emit", () { | 296 test("can declare outputs it doesn't emit", () { |
| 218 initGraph(["app|foo.txt"], {"app": [ | 297 initGraph(["app|foo.txt"], {"app": [ |
| 219 [new DeclareAssetsTransformer(["app|out.txt"], [])] | 298 [new DeclareAssetsTransformer(["app|out.txt"], [])] |
| 220 ]}); | 299 ]}); |
| 221 | 300 |
| 222 updateSources(["app|foo.txt"]); | 301 updateSources(["app|foo.txt"]); |
| 223 expectNoAsset("app|out.txt"); | 302 expectNoAsset("app|out.txt"); |
| 224 buildShouldSucceed(); | 303 buildShouldSucceed(); |
| 225 }); | 304 }); |
| 226 } | 305 } |
| OLD | NEW |