| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library barback.test.package_graph.source_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 | |
| 15 test("errors if two transformers output the same file", () { | |
| 16 initGraph(["app|foo.a"], {"app": [ | |
| 17 [ | |
| 18 new RewriteTransformer("a", "b"), | |
| 19 new RewriteTransformer("a", "b") | |
| 20 ] | |
| 21 ]}); | |
| 22 updateSources(["app|foo.a"]); | |
| 23 | |
| 24 buildShouldFail([isAssetCollisionException("app|foo.b")]); | |
| 25 }); | |
| 26 | |
| 27 test("errors if a new transformer outputs the same file as an old " | |
| 28 "transformer", () { | |
| 29 initGraph(["app|foo.a", "app|foo.b"], {"app": [ | |
| 30 [ | |
| 31 new RewriteTransformer("a", "c"), | |
| 32 new RewriteTransformer("b", "c") | |
| 33 ] | |
| 34 ]}); | |
| 35 updateSources(["app|foo.a"]); | |
| 36 expectAsset("app|foo.c", "foo.c"); | |
| 37 buildShouldSucceed(); | |
| 38 | |
| 39 updateSources(["app|foo.b"]); | |
| 40 buildShouldFail([isAssetCollisionException("app|foo.c")]); | |
| 41 }); | |
| 42 | |
| 43 test("a collision returns the first-produced output", () { | |
| 44 var rewrite1 = new RewriteTransformer("one", "out"); | |
| 45 var rewrite2 = new RewriteTransformer("two", "out"); | |
| 46 initGraph({ | |
| 47 "app|foo.one": "one", | |
| 48 "app|foo.two": "two" | |
| 49 }, {"app": [[rewrite1, rewrite2]]}); | |
| 50 | |
| 51 rewrite1.pauseApply(); | |
| 52 updateSources(["app|foo.one", "app|foo.two"]); | |
| 53 // Wait long enough to ensure that rewrite2 has completed. | |
| 54 schedule(pumpEventQueue); | |
| 55 | |
| 56 rewrite1.resumeApply(); | |
| 57 expectAsset("app|foo.out", "two.out"); | |
| 58 buildShouldFail([isAssetCollisionException("app|foo.out")]); | |
| 59 | |
| 60 // Even after the collision is discovered, the first-produced output should | |
| 61 // be returned. | |
| 62 expectAsset("app|foo.out", "two.out"); | |
| 63 | |
| 64 // Even if the other output is updated more recently, the first output | |
| 65 // should continue to take precedence. | |
| 66 updateSources(["app|foo.one"]); | |
| 67 expectAsset("app|foo.out", "two.out"); | |
| 68 }); | |
| 69 | |
| 70 test("a collision that is later resolved produces an output", () { | |
| 71 initGraph({ | |
| 72 "app|foo.one": "one", | |
| 73 "app|foo.two": "two" | |
| 74 }, {"app": [ | |
| 75 [ | |
| 76 new RewriteTransformer("one", "out"), | |
| 77 new RewriteTransformer("two", "out") | |
| 78 ] | |
| 79 ]}); | |
| 80 | |
| 81 updateSources(["app|foo.one"]); | |
| 82 expectAsset("app|foo.out", "one.out"); | |
| 83 buildShouldSucceed(); | |
| 84 | |
| 85 updateSources(["app|foo.two"]); | |
| 86 expectAsset("app|foo.out", "one.out"); | |
| 87 buildShouldFail([isAssetCollisionException("app|foo.out")]); | |
| 88 | |
| 89 removeSources(["app|foo.one"]); | |
| 90 expectAsset("app|foo.out", "two.out"); | |
| 91 buildShouldSucceed(); | |
| 92 }); | |
| 93 | |
| 94 test("a collision that is later resolved runs transforms", () { | |
| 95 initGraph({ | |
| 96 "app|foo.one": "one", | |
| 97 "app|foo.two": "two" | |
| 98 }, {"app": [ | |
| 99 [ | |
| 100 new RewriteTransformer("one", "mid"), | |
| 101 new RewriteTransformer("two", "mid") | |
| 102 ], | |
| 103 [new RewriteTransformer("mid", "out")] | |
| 104 ]}); | |
| 105 | |
| 106 updateSources(["app|foo.one"]); | |
| 107 expectAsset("app|foo.out", "one.mid.out"); | |
| 108 buildShouldSucceed(); | |
| 109 | |
| 110 updateSources(["app|foo.two"]); | |
| 111 expectAsset("app|foo.out", "one.mid.out"); | |
| 112 buildShouldFail([isAssetCollisionException("app|foo.mid")]); | |
| 113 | |
| 114 removeSources(["app|foo.one"]); | |
| 115 expectAsset("app|foo.out", "two.mid.out"); | |
| 116 buildShouldSucceed(); | |
| 117 }); | |
| 118 | |
| 119 test("a collision that is partially resolved returns the second completed " | |
| 120 "output", () { | |
| 121 var rewrite1 = new RewriteTransformer("one", "out"); | |
| 122 var rewrite2 = new RewriteTransformer("two", "out"); | |
| 123 var rewrite3 = new RewriteTransformer("three", "out"); | |
| 124 initGraph({ | |
| 125 "app|foo.one": "one", | |
| 126 "app|foo.two": "two", | |
| 127 "app|foo.three": "three" | |
| 128 }, {"app": [[rewrite1, rewrite2, rewrite3]]}); | |
| 129 | |
| 130 // Make rewrite3 the most-recently-completed transformer from the first run. | |
| 131 rewrite2.pauseApply(); | |
| 132 rewrite3.pauseApply(); | |
| 133 updateSources(["app|foo.one", "app|foo.two", "app|foo.three"]); | |
| 134 schedule(pumpEventQueue); | |
| 135 rewrite2.resumeApply(); | |
| 136 schedule(pumpEventQueue); | |
| 137 rewrite3.resumeApply(); | |
| 138 buildShouldFail([ | |
| 139 isAssetCollisionException("app|foo.out"), | |
| 140 isAssetCollisionException("app|foo.out") | |
| 141 ]); | |
| 142 | |
| 143 // Then update rewrite3 in a separate build. rewrite2 should still be the | |
| 144 // next version of foo.out in line. | |
| 145 // TODO(nweiz): Should this emit a collision error as well? Or should they | |
| 146 // only be emitted when a file is added or removed? | |
| 147 updateSources(["app|foo.three"]); | |
| 148 buildShouldSucceed(); | |
| 149 | |
| 150 removeSources(["app|foo.one"]); | |
| 151 expectAsset("app|foo.out", "two.out"); | |
| 152 buildShouldFail([isAssetCollisionException("app|foo.out")]); | |
| 153 }); | |
| 154 | |
| 155 test("a collision with a pass-through asset returns the pass-through asset", | |
| 156 () { | |
| 157 initGraph([ | |
| 158 "app|foo.txt", | |
| 159 "app|foo.in" | |
| 160 ], {"app": [ | |
| 161 [new RewriteTransformer("in", "txt")] | |
| 162 ]}); | |
| 163 | |
| 164 updateSources(["app|foo.txt", "app|foo.in"]); | |
| 165 expectAsset("app|foo.txt", "foo"); | |
| 166 buildShouldFail([isAssetCollisionException("app|foo.txt")]); | |
| 167 }); | |
| 168 | |
| 169 test("a new pass-through asset that collides returns the previous asset", () { | |
| 170 initGraph([ | |
| 171 "app|foo.txt", | |
| 172 "app|foo.in" | |
| 173 ], {"app": [ | |
| 174 [new RewriteTransformer("in", "txt")] | |
| 175 ]}); | |
| 176 | |
| 177 updateSources(["app|foo.in"]); | |
| 178 expectAsset("app|foo.txt", "foo.txt"); | |
| 179 buildShouldSucceed(); | |
| 180 | |
| 181 updateSources(["app|foo.txt"]); | |
| 182 expectAsset("app|foo.txt", "foo.txt"); | |
| 183 buildShouldFail([isAssetCollisionException("app|foo.txt")]); | |
| 184 }); | |
| 185 | |
| 186 test("a new transform output that collides with a pass-through asset returns " | |
| 187 "the pass-through asset", () { | |
| 188 initGraph([ | |
| 189 "app|foo.txt", | |
| 190 "app|foo.in" | |
| 191 ], {"app": [ | |
| 192 [new RewriteTransformer("in", "txt")] | |
| 193 ]}); | |
| 194 | |
| 195 updateSources(["app|foo.txt"]); | |
| 196 expectAsset("app|foo.txt", "foo"); | |
| 197 buildShouldSucceed(); | |
| 198 | |
| 199 updateSources(["app|foo.in"]); | |
| 200 expectAsset("app|foo.txt", "foo"); | |
| 201 buildShouldFail([isAssetCollisionException("app|foo.txt")]); | |
| 202 }); | |
| 203 } | |
| OLD | NEW |