| 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 var provider = new MockProvider(["app|foo.a"]); | 19 initGraph(["app|foo.a"], [ |
| 20 var graph = new AssetGraph(provider, [ | |
| 21 [ | 20 [ |
| 22 new RewriteTransformer("a", "b"), | 21 new RewriteTransformer("a", "b"), |
| 23 new RewriteTransformer("a", "b") | 22 new RewriteTransformer("a", "b") |
| 24 ] | 23 ] |
| 25 ]); | 24 ]); |
| 26 graph.updateSources([new AssetId.parse("app|foo.a")]); | 25 updateSources(["app|foo.a"]); |
| 27 | 26 |
| 28 expectCollision(graph, "app|foo.b"); | 27 expectCollision("app|foo.b"); |
| 29 }); | 28 }); |
| 30 | 29 |
| 31 test("reports asset not found errors in results", () { | 30 test("does not report asset not found errors in results", () { |
| 32 var provider = new MockProvider([]); | 31 initGraph(); |
| 33 var graph = new AssetGraph(provider, []); | |
| 34 | 32 |
| 35 // TODO(rnystrom): This is verbose and ugly. Better would be to have | 33 expectNoAsset("app|foo.txt"); |
| 36 // utils.dart register this on the graph and then have functions to expect | 34 buildShouldSucceed(); |
| 37 // certain build results. | |
| 38 var numResults = 0; | |
| 39 var gotError = false; | |
| 40 graph.results.listen(wrapAsync((result) { | |
| 41 numResults++; | |
| 42 expect(numResults, lessThan(3)); | |
| 43 | |
| 44 if (numResults == 1) { | |
| 45 // Should complete the build first. | |
| 46 expect(result.error, isNull); | |
| 47 } else if (numResults == 2) { | |
| 48 // Then have the error. | |
| 49 expect(result.error, new isInstanceOf<AssetNotFoundException>()); | |
| 50 expect(result.error.id, equals(new AssetId.parse("app|foo.txt"))); | |
| 51 gotError = true; | |
| 52 } | |
| 53 })); | |
| 54 | |
| 55 expectNoAsset(graph, "app|foo.txt"); | |
| 56 | |
| 57 schedule(() { | |
| 58 expect(gotError, isTrue); | |
| 59 }); | |
| 60 }); | 35 }); |
| 61 | 36 |
| 62 test("reports an error for an unprovided source", () { | 37 test("reports an error for an unprovided source", () { |
| 63 var provider = new MockProvider([]); | 38 initGraph(); |
| 64 var graph = new AssetGraph(provider, []); | 39 updateSources(["app|unknown.txt"]); |
| 65 var resultFuture = graph.results.first; | |
| 66 | 40 |
| 67 graph.updateSources([new AssetId.parse("app|unknown.txt")]); | 41 buildShouldFail((error) { |
| 68 | 42 expect(error, new isInstanceOf<AssetNotFoundException>()); |
| 69 schedule(() { | 43 expect(error.id, equals(new AssetId.parse("app|unknown.txt"))); |
| 70 return resultFuture.then((result) { | |
| 71 expect(result.error, new isInstanceOf<AssetNotFoundException>()); | |
| 72 expect(result.error.id, equals(new AssetId.parse("app|unknown.txt"))); | |
| 73 }); | |
| 74 }); | 44 }); |
| 75 }); | 45 }); |
| 76 | 46 |
| 77 test("reports missing input errors in results", () { | 47 test("reports missing input errors in results", () { |
| 78 var provider = new MockProvider({"app|a.txt": "a.inc"}); | 48 initGraph({"app|a.txt": "a.inc"}, [ |
| 79 | |
| 80 var graph = new AssetGraph(provider, [ | |
| 81 [new ManyToOneTransformer("txt")] | 49 [new ManyToOneTransformer("txt")] |
| 82 ]); | 50 ]); |
| 83 | 51 |
| 84 var gotError = false; | 52 buildShouldFail((error) { |
| 85 graph.results.listen(wrapAsync((result) { | 53 expect(error, new isInstanceOf<MissingInputException>()); |
| 86 expect(result.error is MissingInputException, isTrue); | 54 expect(error.id, equals(new AssetId.parse("app|a.inc"))); |
| 87 expect(result.error.id, equals(new AssetId.parse("app|a.inc"))); | 55 }); |
| 88 gotError = true; | |
| 89 })); | |
| 90 | 56 |
| 91 graph.updateSources([new AssetId.parse("app|a.txt")]); | 57 updateSources(["app|a.txt"]); |
| 92 | 58 |
| 93 expectNoAsset(graph, "app|a.out"); | 59 expectNoAsset("app|a.out"); |
| 94 | |
| 95 schedule(() { | |
| 96 expect(gotError, isTrue); | |
| 97 }); | |
| 98 }); | 60 }); |
| 99 | 61 |
| 100 test("fails if a non-primary input is removed", () { | 62 test("fails if a non-primary input is removed", () { |
| 101 var provider = new MockProvider({ | 63 initGraph({ |
| 102 "app|a.txt": "a.inc,b.inc,c.inc", | 64 "app|a.txt": "a.inc,b.inc,c.inc", |
| 103 "app|a.inc": "a", | 65 "app|a.inc": "a", |
| 104 "app|b.inc": "b", | 66 "app|b.inc": "b", |
| 105 "app|c.inc": "c" | 67 "app|c.inc": "c" |
| 106 }); | 68 }, [ |
| 107 | |
| 108 var graph = new AssetGraph(provider, [ | |
| 109 [new ManyToOneTransformer("txt")] | 69 [new ManyToOneTransformer("txt")] |
| 110 ]); | 70 ]); |
| 111 | 71 |
| 112 // TODO(rnystrom): This is verbose and ugly. Better would be to have | 72 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); |
| 113 // utils.dart register this on the graph and then have functions to expect | 73 expectAsset("app|a.out", "abc"); |
| 114 // certain build results. | 74 buildShouldSucceed(); |
| 115 var numResults = 0; | |
| 116 var gotError = false; | |
| 117 graph.results.listen(wrapAsync((result) { | |
| 118 numResults++; | |
| 119 expect(numResults, lessThan(3)); | |
| 120 | |
| 121 if (numResults == 1) { | |
| 122 // Should complete the build first. | |
| 123 expect(result.error, isNull); | |
| 124 } else if (numResults == 2) { | |
| 125 // Then have the error. | |
| 126 expect(result.error is MissingInputException, isTrue); | |
| 127 expect(result.error.id, equals(new AssetId.parse("app|b.inc"))); | |
| 128 gotError = true; | |
| 129 } | |
| 130 })); | |
| 131 | |
| 132 graph.updateSources([ | |
| 133 new AssetId.parse("app|a.txt"), | |
| 134 new AssetId.parse("app|a.inc"), | |
| 135 new AssetId.parse("app|b.inc"), | |
| 136 new AssetId.parse("app|c.inc") | |
| 137 ]); | |
| 138 | |
| 139 expectAsset(graph, "app|a.out", "abc"); | |
| 140 | 75 |
| 141 schedule(() { | 76 schedule(() { |
| 142 graph.removeSources([new AssetId.parse("app|b.inc")]); | 77 removeSources(["app|b.inc"]); |
| 143 }); | 78 }); |
| 144 | 79 |
| 145 expectNoAsset(graph, "app|a.out"); | 80 buildShouldFail((error) { |
| 146 | 81 expect(error, new isInstanceOf<MissingInputException>()); |
| 147 schedule(() { | 82 expect(error.id, equals(new AssetId.parse("app|b.inc"))); |
| 148 expect(gotError, isTrue); | |
| 149 }); | 83 }); |
| 84 expectNoAsset("app|a.out"); |
| 150 }); | 85 }); |
| 151 | 86 |
| 152 test("catches transformer exceptions and reports them", () { | 87 test("catches transformer exceptions and reports them", () { |
| 153 var provider = new MockProvider(["app|foo.txt"]); | 88 initGraph(["app|foo.txt"], [ |
| 154 var graph = new AssetGraph(provider, [ | |
| 155 [new BadTransformer(["app|foo.out"])] | 89 [new BadTransformer(["app|foo.out"])] |
| 156 ]); | 90 ]); |
| 157 | 91 |
| 158 var gotError = false; | |
| 159 graph.results.listen(wrapAsync((result) { | |
| 160 expect(result.error, equals(BadTransformer.ERROR)); | |
| 161 gotError = true; | |
| 162 })); | |
| 163 | |
| 164 schedule(() { | 92 schedule(() { |
| 165 graph.updateSources([new AssetId.parse("app|foo.txt")]); | 93 updateSources(["app|foo.txt"]); |
| 166 }); | 94 }); |
| 167 | 95 |
| 168 expectNoAsset(graph, "app|foo.out"); | 96 expectNoAsset("app|foo.out"); |
| 169 | 97 |
| 170 schedule(() { | 98 buildShouldFail((error) { |
| 171 expect(gotError, isTrue); | 99 expect(error, equals(BadTransformer.ERROR)); |
| 172 }); | 100 }); |
| 173 }); | 101 }); |
| 174 | 102 |
| 175 // TODO(rnystrom): Is this the behavior we expect? If a transformer fails | 103 // TODO(rnystrom): Is this the behavior we expect? If a transformer fails |
| 176 // to transform a file, should we just skip past it to the source? | 104 // to transform a file, should we just skip past it to the source? |
| 177 test("yields a source if a transform fails on it", () { | 105 test("yields a source if a transform fails on it", () { |
| 178 var provider = new MockProvider(["app|foo.txt"]); | 106 initGraph(["app|foo.txt"], [ |
| 179 var graph = new AssetGraph(provider, [ | |
| 180 [new BadTransformer(["app|foo.txt"])] | 107 [new BadTransformer(["app|foo.txt"])] |
| 181 ]); | 108 ]); |
| 182 | 109 |
| 183 schedule(() { | 110 schedule(() { |
| 184 graph.updateSources([new AssetId.parse("app|foo.txt")]); | 111 updateSources(["app|foo.txt"]); |
| 185 }); | 112 }); |
| 186 | 113 |
| 187 expectAsset(graph, "app|foo.txt"); | 114 expectAsset("app|foo.txt"); |
| 188 }); | 115 }); |
| 189 | 116 |
| 190 test("catches errors even if nothing is waiting for process results", () { | 117 test("catches errors even if nothing is waiting for process results", () { |
| 191 var provider = new MockProvider(["app|foo.txt"]); | 118 initGraph(["app|foo.txt"], [[new BadTransformer([])]]); |
| 192 var graph = new AssetGraph(provider, [[new BadTransformer([])]]); | |
| 193 var resultFuture = graph.results.first; | |
| 194 | 119 |
| 195 schedule(() { | 120 schedule(() { |
| 196 graph.updateSources([new AssetId.parse("app|foo.txt")]); | 121 updateSources(["app|foo.txt"]); |
| 197 }); | 122 }); |
| 198 | 123 |
| 199 // Note: No asset requests here. | 124 // Note: No asset requests here. |
| 200 | 125 |
| 201 schedule(() { | 126 buildShouldFail((error) { |
| 202 return resultFuture.then((result) { | 127 expect(error, equals(BadTransformer.ERROR)); |
| 203 expect(result.error, equals(BadTransformer.ERROR)); | |
| 204 }); | |
| 205 }); | 128 }); |
| 206 }); | 129 }); |
| 207 | 130 |
| 208 test("discards outputs from failed transforms", () { | 131 test("discards outputs from failed transforms", () { |
| 209 var provider = new MockProvider(["app|foo.txt"]); | 132 initGraph(["app|foo.txt"], [ |
| 210 var graph = new AssetGraph(provider, [ | |
| 211 [new BadTransformer(["a.out", "b.out"])] | 133 [new BadTransformer(["a.out", "b.out"])] |
| 212 ]); | 134 ]); |
| 213 | 135 |
| 214 schedule(() { | 136 schedule(() { |
| 215 graph.updateSources([new AssetId.parse("app|foo.txt")]); | 137 updateSources(["app|foo.txt"]); |
| 216 }); | 138 }); |
| 217 | 139 |
| 218 expectNoAsset(graph, "app|a.out"); | 140 expectNoAsset("app|a.out"); |
| 219 }); | 141 }); |
| 220 } | 142 } |
| OLD | NEW |