| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 import 'package:scheduled_test/scheduled_test.dart'; | 10 import 'package:scheduled_test/scheduled_test.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 initGraph(["app|foo.a", "app|foo.b"], {"app": [ | 31 initGraph(["app|foo.a", "app|foo.b"], {"app": [ |
| 32 [ | 32 [ |
| 33 new RewriteTransformer("a", "c"), | 33 new RewriteTransformer("a", "c"), |
| 34 new RewriteTransformer("b", "c") | 34 new RewriteTransformer("b", "c") |
| 35 ] | 35 ] |
| 36 ]}); | 36 ]}); |
| 37 updateSources(["app|foo.a"]); | 37 updateSources(["app|foo.a"]); |
| 38 expectAsset("app|foo.c", "foo.c"); | 38 expectAsset("app|foo.c", "foo.c"); |
| 39 buildShouldSucceed(); | 39 buildShouldSucceed(); |
| 40 | 40 |
| 41 schedule(() => updateSources(["app|foo.b"])); | 41 updateSources(["app|foo.b"]); |
| 42 buildShouldFail([isAssetCollisionException("app|foo.c")]); | 42 buildShouldFail([isAssetCollisionException("app|foo.c")]); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 test("does not report asset not found errors in results", () { | 45 test("does not report asset not found errors in results", () { |
| 46 initGraph(["app|bar.txt"]); | 46 initGraph(["app|bar.txt"]); |
| 47 | 47 |
| 48 // Trigger a build. | 48 // Trigger a build. |
| 49 updateSources(["app|bar.txt"]); | 49 updateSources(["app|bar.txt"]); |
| 50 | 50 |
| 51 expectNoAsset("app|foo.txt"); | 51 expectNoAsset("app|foo.txt"); |
| 52 buildShouldSucceed(); | 52 buildShouldSucceed(); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test("reports an error for an unprovided package", () { | 55 test("reports an error for an unprovided package", () { |
| 56 initGraph(); | 56 initGraph(); |
| 57 expect(() => updateSources(["unknown|foo.txt"]), throwsArgumentError); | 57 expect(() => updateSourcesSync(["unknown|foo.txt"]), throwsArgumentError); |
| 58 }); | 58 }); |
| 59 | 59 |
| 60 test("reports an error for an unprovided source", () { | 60 test("reports an error for an unprovided source", () { |
| 61 initGraph(["app|known.txt"]); | 61 initGraph(["app|known.txt"]); |
| 62 updateSources(["app|unknown.txt"]); | 62 updateSources(["app|unknown.txt"]); |
| 63 | 63 |
| 64 buildShouldFail([isAssetNotFoundException("app|unknown.txt")]); | 64 buildShouldFail([isAssetNotFoundException("app|unknown.txt")]); |
| 65 }); | 65 }); |
| 66 | 66 |
| 67 test("reports missing input errors in results", () { | 67 test("reports missing input errors in results", () { |
| 68 initGraph({"app|a.txt": "a.inc"}, {"app": [ | 68 initGraph({"app|a.txt": "a.inc"}, {"app": [ |
| 69 [new ManyToOneTransformer("txt")] | 69 [new ManyToOneTransformer("txt")] |
| 70 ]}); | 70 ]}); |
| 71 | 71 |
| 72 updateSources(["app|a.txt"]); |
| 73 expectNoAsset("app|a.out"); |
| 72 buildShouldFail([isMissingInputException("app|a.inc")]); | 74 buildShouldFail([isMissingInputException("app|a.inc")]); |
| 73 | |
| 74 updateSources(["app|a.txt"]); | |
| 75 | |
| 76 expectNoAsset("app|a.out"); | |
| 77 }); | 75 }); |
| 78 | 76 |
| 79 test("reports an error if a transformer emits an asset for another package", | 77 test("reports an error if a transformer emits an asset for another package", |
| 80 () { | 78 () { |
| 81 initGraph(["app|foo.txt"], { | 79 initGraph(["app|foo.txt"], { |
| 82 "app": [[new CreateAssetTransformer("wrong|foo.txt")]] | 80 "app": [[new CreateAssetTransformer("wrong|foo.txt")]] |
| 83 }); | 81 }); |
| 84 | 82 |
| 83 updateSources(["app|foo.txt"]); |
| 85 buildShouldFail([isInvalidOutputException("app", "wrong|foo.txt")]); | 84 buildShouldFail([isInvalidOutputException("app", "wrong|foo.txt")]); |
| 86 | |
| 87 updateSources(["app|foo.txt"]); | |
| 88 }); | 85 }); |
| 89 | 86 |
| 90 test("fails if a non-primary input is removed", () { | 87 test("fails if a non-primary input is removed", () { |
| 91 initGraph({ | 88 initGraph({ |
| 92 "app|a.txt": "a.inc,b.inc,c.inc", | 89 "app|a.txt": "a.inc,b.inc,c.inc", |
| 93 "app|a.inc": "a", | 90 "app|a.inc": "a", |
| 94 "app|b.inc": "b", | 91 "app|b.inc": "b", |
| 95 "app|c.inc": "c" | 92 "app|c.inc": "c" |
| 96 }, {"app": [ | 93 }, {"app": [ |
| 97 [new ManyToOneTransformer("txt")] | 94 [new ManyToOneTransformer("txt")] |
| 98 ]}); | 95 ]}); |
| 99 | 96 |
| 100 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); | 97 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); |
| 101 expectAsset("app|a.out", "abc"); | 98 expectAsset("app|a.out", "abc"); |
| 102 buildShouldSucceed(); | 99 buildShouldSucceed(); |
| 103 | 100 |
| 104 schedule(() { | 101 removeSources(["app|b.inc"]); |
| 105 removeSources(["app|b.inc"]); | |
| 106 }); | |
| 107 | |
| 108 buildShouldFail([isMissingInputException("app|b.inc")]); | 102 buildShouldFail([isMissingInputException("app|b.inc")]); |
| 109 expectNoAsset("app|a.out"); | 103 expectNoAsset("app|a.out"); |
| 110 }); | 104 }); |
| 111 | 105 |
| 112 test("catches transformer exceptions and reports them", () { | 106 test("catches transformer exceptions and reports them", () { |
| 113 initGraph(["app|foo.txt"], {"app": [ | 107 initGraph(["app|foo.txt"], {"app": [ |
| 114 [new BadTransformer(["app|foo.out"])] | 108 [new BadTransformer(["app|foo.out"])] |
| 115 ]}); | 109 ]}); |
| 116 | 110 |
| 117 schedule(() { | 111 updateSources(["app|foo.txt"]); |
| 118 updateSources(["app|foo.txt"]); | |
| 119 }); | |
| 120 | |
| 121 expectNoAsset("app|foo.out"); | 112 expectNoAsset("app|foo.out"); |
| 122 | |
| 123 buildShouldFail([equals(BadTransformer.ERROR)]); | 113 buildShouldFail([equals(BadTransformer.ERROR)]); |
| 124 }); | 114 }); |
| 125 | 115 |
| 126 test("doesn't yield a source if a transform fails on it", () { | 116 test("doesn't yield a source if a transform fails on it", () { |
| 127 initGraph(["app|foo.txt"], {"app": [ | 117 initGraph(["app|foo.txt"], {"app": [ |
| 128 [new BadTransformer(["app|foo.txt"])] | 118 [new BadTransformer(["app|foo.txt"])] |
| 129 ]}); | 119 ]}); |
| 130 | 120 |
| 131 schedule(() { | 121 updateSources(["app|foo.txt"]); |
| 132 updateSources(["app|foo.txt"]); | |
| 133 }); | |
| 134 | |
| 135 expectNoAsset("app|foo.txt"); | 122 expectNoAsset("app|foo.txt"); |
| 136 }); | 123 }); |
| 137 | 124 |
| 138 test("catches errors even if nothing is waiting for process results", () { | 125 test("catches errors even if nothing is waiting for process results", () { |
| 139 initGraph(["app|foo.txt"], {"app": [[new BadTransformer([])]]}); | 126 initGraph(["app|foo.txt"], {"app": [[new BadTransformer([])]]}); |
| 140 | 127 |
| 141 schedule(() { | 128 updateSources(["app|foo.txt"]); |
| 142 updateSources(["app|foo.txt"]); | |
| 143 }); | |
| 144 | |
| 145 // Note: No asset requests here. | 129 // Note: No asset requests here. |
| 146 | |
| 147 buildShouldFail([equals(BadTransformer.ERROR)]); | 130 buildShouldFail([equals(BadTransformer.ERROR)]); |
| 148 }); | 131 }); |
| 149 | 132 |
| 150 test("discards outputs from failed transforms", () { | 133 test("discards outputs from failed transforms", () { |
| 151 initGraph(["app|foo.txt"], {"app": [ | 134 initGraph(["app|foo.txt"], {"app": [ |
| 152 [new BadTransformer(["a.out", "b.out"])] | 135 [new BadTransformer(["a.out", "b.out"])] |
| 153 ]}); | 136 ]}); |
| 154 | 137 |
| 155 schedule(() { | 138 updateSources(["app|foo.txt"]); |
| 156 updateSources(["app|foo.txt"]); | |
| 157 }); | |
| 158 | |
| 159 expectNoAsset("app|a.out"); | 139 expectNoAsset("app|a.out"); |
| 160 }); | 140 }); |
| 161 | 141 |
| 162 test("fails if only one package fails", () { | 142 test("fails if only one package fails", () { |
| 163 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], | 143 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], |
| 164 {"pkg1": [[new BadTransformer([])]]}); | 144 {"pkg1": [[new BadTransformer([])]]}); |
| 165 | 145 |
| 166 schedule(() { | 146 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
| 167 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); | |
| 168 }); | |
| 169 | |
| 170 expectAsset("pkg2|foo.txt", "foo"); | 147 expectAsset("pkg2|foo.txt", "foo"); |
| 171 buildShouldFail([equals(BadTransformer.ERROR)]); | 148 buildShouldFail([equals(BadTransformer.ERROR)]); |
| 172 }); | 149 }); |
| 173 | 150 |
| 174 test("emits multiple failures if multiple packages fail", () { | 151 test("emits multiple failures if multiple packages fail", () { |
| 175 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], { | 152 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], { |
| 176 "pkg1": [[new BadTransformer([])]], | 153 "pkg1": [[new BadTransformer([])]], |
| 177 "pkg2": [[new BadTransformer([])]] | 154 "pkg2": [[new BadTransformer([])]] |
| 178 }); | 155 }); |
| 179 | 156 |
| 180 schedule(() { | 157 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
| 181 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); | |
| 182 }); | |
| 183 | |
| 184 buildShouldFail([ | 158 buildShouldFail([ |
| 185 equals(BadTransformer.ERROR), | 159 equals(BadTransformer.ERROR), |
| 186 equals(BadTransformer.ERROR) | 160 equals(BadTransformer.ERROR) |
| 187 ]); | 161 ]); |
| 188 }); | 162 }); |
| 189 | 163 |
| 190 test("an error loading an asset removes the asset from the graph", () { | 164 test("an error loading an asset removes the asset from the graph", () { |
| 191 initGraph(["app|foo.txt"]); | 165 initGraph(["app|foo.txt"]); |
| 192 | 166 |
| 193 setAssetError("app|foo.txt"); | 167 setAssetError("app|foo.txt"); |
| 194 schedule(() => updateSources(["app|foo.txt"])); | 168 updateSources(["app|foo.txt"]); |
| 195 expectNoAsset("app|foo.txt"); | 169 expectNoAsset("app|foo.txt"); |
| 196 buildShouldFail([isMockLoadException("app|foo.txt")]); | 170 buildShouldFail([isMockLoadException("app|foo.txt")]); |
| 197 }); | 171 }); |
| 198 } | 172 } |
| OLD | NEW |