| 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.asset_graph.source_test; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:barback/barback.dart'; | |
| 10 import 'package:barback/src/asset_graph.dart'; | |
| 11 import 'package:scheduled_test/scheduled_test.dart'; | |
| 12 | |
| 13 import '../utils.dart'; | |
| 14 | |
| 15 main() { | |
| 16 initConfig(); | |
| 17 | |
| 18 test("errors if two transformers output the same file", () { | |
| 19 initGraph(["app|foo.a"], {"app": [ | |
| 20 [ | |
| 21 new RewriteTransformer("a", "b"), | |
| 22 new RewriteTransformer("a", "b") | |
| 23 ] | |
| 24 ]}); | |
| 25 updateSources(["app|foo.a"]); | |
| 26 | |
| 27 buildShouldFail([isAssetCollisionException("app|foo.b")]); | |
| 28 }); | |
| 29 | |
| 30 test("does not report asset not found errors in results", () { | |
| 31 initGraph(["app|bar.txt"]); | |
| 32 | |
| 33 // Trigger a build. | |
| 34 updateSources(["app|bar.txt"]); | |
| 35 | |
| 36 expectNoAsset("app|foo.txt"); | |
| 37 buildShouldSucceed(); | |
| 38 }); | |
| 39 | |
| 40 test("reports an error for an unprovided package", () { | |
| 41 initGraph(); | |
| 42 expect(() => updateSources(["unknown|foo.txt"]), throwsArgumentError); | |
| 43 }); | |
| 44 | |
| 45 test("reports an error for an unprovided source", () { | |
| 46 initGraph(["app|known.txt"]); | |
| 47 updateSources(["app|unknown.txt"]); | |
| 48 | |
| 49 buildShouldFail([isAssetNotFoundException("app|unknown.txt")]); | |
| 50 }); | |
| 51 | |
| 52 test("reports missing input errors in results", () { | |
| 53 initGraph({"app|a.txt": "a.inc"}, {"app": [ | |
| 54 [new ManyToOneTransformer("txt")] | |
| 55 ]}); | |
| 56 | |
| 57 buildShouldFail([isMissingInputException("app|a.inc")]); | |
| 58 | |
| 59 updateSources(["app|a.txt"]); | |
| 60 | |
| 61 expectNoAsset("app|a.out"); | |
| 62 }); | |
| 63 | |
| 64 test("reports an error if a transformer emits an asset for another package", | |
| 65 () { | |
| 66 initGraph(["app|foo.txt"], { | |
| 67 "app": [[new CreateAssetTransformer("wrong|foo.txt")]] | |
| 68 }); | |
| 69 | |
| 70 buildShouldFail([isInvalidOutputException("app", "wrong|foo.txt")]); | |
| 71 | |
| 72 updateSources(["app|foo.txt"]); | |
| 73 }); | |
| 74 | |
| 75 test("fails if a non-primary input is removed", () { | |
| 76 initGraph({ | |
| 77 "app|a.txt": "a.inc,b.inc,c.inc", | |
| 78 "app|a.inc": "a", | |
| 79 "app|b.inc": "b", | |
| 80 "app|c.inc": "c" | |
| 81 }, {"app": [ | |
| 82 [new ManyToOneTransformer("txt")] | |
| 83 ]}); | |
| 84 | |
| 85 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); | |
| 86 expectAsset("app|a.out", "abc"); | |
| 87 buildShouldSucceed(); | |
| 88 | |
| 89 schedule(() { | |
| 90 removeSources(["app|b.inc"]); | |
| 91 }); | |
| 92 | |
| 93 buildShouldFail([isMissingInputException("app|b.inc")]); | |
| 94 expectNoAsset("app|a.out"); | |
| 95 }); | |
| 96 | |
| 97 test("catches transformer exceptions and reports them", () { | |
| 98 initGraph(["app|foo.txt"], {"app": [ | |
| 99 [new BadTransformer(["app|foo.out"])] | |
| 100 ]}); | |
| 101 | |
| 102 schedule(() { | |
| 103 updateSources(["app|foo.txt"]); | |
| 104 }); | |
| 105 | |
| 106 expectNoAsset("app|foo.out"); | |
| 107 | |
| 108 buildShouldFail([equals(BadTransformer.ERROR)]); | |
| 109 }); | |
| 110 | |
| 111 // TODO(rnystrom): Is this the behavior we expect? If a transformer fails | |
| 112 // to transform a file, should we just skip past it to the source? | |
| 113 test("yields a source if a transform fails on it", () { | |
| 114 initGraph(["app|foo.txt"], {"app": [ | |
| 115 [new BadTransformer(["app|foo.txt"])] | |
| 116 ]}); | |
| 117 | |
| 118 schedule(() { | |
| 119 updateSources(["app|foo.txt"]); | |
| 120 }); | |
| 121 | |
| 122 expectAsset("app|foo.txt"); | |
| 123 }); | |
| 124 | |
| 125 test("catches errors even if nothing is waiting for process results", () { | |
| 126 initGraph(["app|foo.txt"], {"app": [[new BadTransformer([])]]}); | |
| 127 | |
| 128 schedule(() { | |
| 129 updateSources(["app|foo.txt"]); | |
| 130 }); | |
| 131 | |
| 132 // Note: No asset requests here. | |
| 133 | |
| 134 buildShouldFail([equals(BadTransformer.ERROR)]); | |
| 135 }); | |
| 136 | |
| 137 test("discards outputs from failed transforms", () { | |
| 138 initGraph(["app|foo.txt"], {"app": [ | |
| 139 [new BadTransformer(["a.out", "b.out"])] | |
| 140 ]}); | |
| 141 | |
| 142 schedule(() { | |
| 143 updateSources(["app|foo.txt"]); | |
| 144 }); | |
| 145 | |
| 146 expectNoAsset("app|a.out"); | |
| 147 }); | |
| 148 | |
| 149 test("fails if only one package fails", () { | |
| 150 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], | |
| 151 {"pkg1": [[new BadTransformer([])]]}); | |
| 152 | |
| 153 schedule(() { | |
| 154 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); | |
| 155 }); | |
| 156 | |
| 157 expectAsset("pkg2|foo.txt", "foo"); | |
| 158 buildShouldFail([equals(BadTransformer.ERROR)]); | |
| 159 }); | |
| 160 | |
| 161 test("emits multiple failures if multiple packages fail", () { | |
| 162 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], { | |
| 163 "pkg1": [[new BadTransformer([])]], | |
| 164 "pkg2": [[new BadTransformer([])]] | |
| 165 }); | |
| 166 | |
| 167 schedule(() { | |
| 168 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); | |
| 169 }); | |
| 170 | |
| 171 buildShouldFail([ | |
| 172 equals(BadTransformer.ERROR), | |
| 173 equals(BadTransformer.ERROR) | |
| 174 ]); | |
| 175 }); | |
| 176 } | |
| OLD | NEW |