| 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 |
| 56 test("fails if a non-primary input is removed", () { | 64 test("fails if a non-primary input is removed", () { |
| 57 initGraph({ | 65 initGraph({ |
| 58 "app|a.txt": "a.inc,b.inc,c.inc", | 66 "app|a.txt": "a.inc,b.inc,c.inc", |
| 59 "app|a.inc": "a", | 67 "app|a.inc": "a", |
| 60 "app|b.inc": "b", | 68 "app|b.inc": "b", |
| 61 "app|c.inc": "c" | 69 "app|c.inc": "c" |
| 62 }, [ | 70 }, {"app": [ |
| 63 [new ManyToOneTransformer("txt")] | 71 [new ManyToOneTransformer("txt")] |
| 64 ]); | 72 ]}); |
| 65 | 73 |
| 66 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); | 74 updateSources(["app|a.txt", "app|a.inc", "app|b.inc", "app|c.inc"]); |
| 67 expectAsset("app|a.out", "abc"); | 75 expectAsset("app|a.out", "abc"); |
| 68 buildShouldSucceed(); | 76 buildShouldSucceed(); |
| 69 | 77 |
| 70 schedule(() { | 78 schedule(() { |
| 71 removeSources(["app|b.inc"]); | 79 removeSources(["app|b.inc"]); |
| 72 }); | 80 }); |
| 73 | 81 |
| 74 buildShouldFail([isMissingInputException("app|b.inc")]); | 82 buildShouldFail([isMissingInputException("app|b.inc")]); |
| 75 expectNoAsset("app|a.out"); | 83 expectNoAsset("app|a.out"); |
| 76 }); | 84 }); |
| 77 | 85 |
| 78 test("catches transformer exceptions and reports them", () { | 86 test("catches transformer exceptions and reports them", () { |
| 79 initGraph(["app|foo.txt"], [ | 87 initGraph(["app|foo.txt"], {"app": [ |
| 80 [new BadTransformer(["app|foo.out"])] | 88 [new BadTransformer(["app|foo.out"])] |
| 81 ]); | 89 ]}); |
| 82 | 90 |
| 83 schedule(() { | 91 schedule(() { |
| 84 updateSources(["app|foo.txt"]); | 92 updateSources(["app|foo.txt"]); |
| 85 }); | 93 }); |
| 86 | 94 |
| 87 expectNoAsset("app|foo.out"); | 95 expectNoAsset("app|foo.out"); |
| 88 | 96 |
| 89 buildShouldFail([equals(BadTransformer.ERROR)]); | 97 buildShouldFail([equals(BadTransformer.ERROR)]); |
| 90 }); | 98 }); |
| 91 | 99 |
| 92 // TODO(rnystrom): Is this the behavior we expect? If a transformer fails | 100 // 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? | 101 // to transform a file, should we just skip past it to the source? |
| 94 test("yields a source if a transform fails on it", () { | 102 test("yields a source if a transform fails on it", () { |
| 95 initGraph(["app|foo.txt"], [ | 103 initGraph(["app|foo.txt"], {"app": [ |
| 96 [new BadTransformer(["app|foo.txt"])] | 104 [new BadTransformer(["app|foo.txt"])] |
| 97 ]); | 105 ]}); |
| 98 | 106 |
| 99 schedule(() { | 107 schedule(() { |
| 100 updateSources(["app|foo.txt"]); | 108 updateSources(["app|foo.txt"]); |
| 101 }); | 109 }); |
| 102 | 110 |
| 103 expectAsset("app|foo.txt"); | 111 expectAsset("app|foo.txt"); |
| 104 }); | 112 }); |
| 105 | 113 |
| 106 test("catches errors even if nothing is waiting for process results", () { | 114 test("catches errors even if nothing is waiting for process results", () { |
| 107 initGraph(["app|foo.txt"], [[new BadTransformer([])]]); | 115 initGraph(["app|foo.txt"], {"app": [[new BadTransformer([])]]}); |
| 108 | 116 |
| 109 schedule(() { | 117 schedule(() { |
| 110 updateSources(["app|foo.txt"]); | 118 updateSources(["app|foo.txt"]); |
| 111 }); | 119 }); |
| 112 | 120 |
| 113 // Note: No asset requests here. | 121 // Note: No asset requests here. |
| 114 | 122 |
| 115 buildShouldFail([equals(BadTransformer.ERROR)]); | 123 buildShouldFail([equals(BadTransformer.ERROR)]); |
| 116 }); | 124 }); |
| 117 | 125 |
| 118 test("discards outputs from failed transforms", () { | 126 test("discards outputs from failed transforms", () { |
| 119 initGraph(["app|foo.txt"], [ | 127 initGraph(["app|foo.txt"], {"app": [ |
| 120 [new BadTransformer(["a.out", "b.out"])] | 128 [new BadTransformer(["a.out", "b.out"])] |
| 121 ]); | 129 ]}); |
| 122 | 130 |
| 123 schedule(() { | 131 schedule(() { |
| 124 updateSources(["app|foo.txt"]); | 132 updateSources(["app|foo.txt"]); |
| 125 }); | 133 }); |
| 126 | 134 |
| 127 expectNoAsset("app|a.out"); | 135 expectNoAsset("app|a.out"); |
| 128 }); | 136 }); |
| 137 |
| 138 test("fails if only one package fails", () { |
| 139 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], |
| 140 {"pkg1": [[new BadTransformer([])]]}); |
| 141 |
| 142 schedule(() { |
| 143 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
| 144 }); |
| 145 |
| 146 expectAsset("pkg2|foo.txt", "foo"); |
| 147 buildShouldFail([equals(BadTransformer.ERROR)]); |
| 148 }); |
| 149 |
| 150 test("emits multiple failures if multiple packages fail", () { |
| 151 initGraph(["pkg1|foo.txt", "pkg2|foo.txt"], { |
| 152 "pkg1": [[new BadTransformer([])]], |
| 153 "pkg2": [[new BadTransformer([])]] |
| 154 }); |
| 155 |
| 156 schedule(() { |
| 157 updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]); |
| 158 }); |
| 159 |
| 160 buildShouldFail([ |
| 161 equals(BadTransformer.ERROR), |
| 162 equals(BadTransformer.ERROR) |
| 163 ]); |
| 164 }); |
| 129 } | 165 } |
| OLD | NEW |