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