Chromium Code Reviews| 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 library barback.test.asset_graph.source_test; | |
| 5 | |
| 6 import 'dart:async'; | |
| 7 | |
| 8 import 'package:barback/barback.dart'; | |
| 9 import 'package:barback/src/asset_graph.dart'; | |
| 10 import 'package:scheduled_test/scheduled_test.dart'; | |
| 11 | |
| 12 import '../utils.dart'; | |
| 13 | |
| 14 main() { | |
| 15 initConfig(); | |
| 16 | |
| 17 test("errors if two transformers output the same file", () { | |
| 18 var provider = new MockProvider({"app|foo.a": "foo"}); | |
| 19 var graph = new AssetGraph(provider, [ | |
| 20 [ | |
| 21 new RewriteTransformer("a", "b"), | |
| 22 new RewriteTransformer("a", "b") | |
| 23 ] | |
| 24 ]); | |
| 25 graph.updateSources([new AssetId.parse("app|foo.a")]); | |
| 26 | |
| 27 expectCollision(graph, "app|foo.b"); | |
|
nweiz
2013/06/18 23:14:46
I really think expect(graph, hasCollision("app|foo
Bob Nystrom
2013/06/20 00:23:59
My plan is to have utils.dart keep track of the gr
| |
| 28 }); | |
| 29 | |
| 30 test("reports asset not found errors in results", () { | |
| 31 var provider = new MockProvider([]); | |
| 32 var graph = new AssetGraph(provider, []); | |
| 33 | |
| 34 var gotError = false; | |
| 35 graph.results.listen(wrapAsync((result) { | |
| 36 expect(result.error is AssetNotFoundException, isTrue); | |
|
nweiz
2013/06/18 23:14:46
expect(result.error, new isInstanceOf<AssetNotFoun
Bob Nystrom
2013/06/20 00:23:59
Done.
| |
| 37 expect(result.error.id, equals(new AssetId.parse("app|foo.txt"))); | |
| 38 gotError = true; | |
| 39 })); | |
|
nweiz
2013/06/18 23:14:46
This wrapAsync/gotError stuff is complicated and g
Bob Nystrom
2013/06/20 00:23:59
Added a TODO. I'm planning to refactor it complete
| |
| 40 | |
| 41 expectNoAsset(graph, "app|foo.txt"); | |
| 42 | |
| 43 schedule(() { | |
| 44 expect(gotError, isTrue); | |
| 45 }); | |
| 46 }); | |
| 47 | |
| 48 test("reports missing input errors in results", () { | |
| 49 var provider = new MockProvider({"app|a.txt": "a.inc"}); | |
| 50 | |
| 51 var graph = new AssetGraph(provider, [ | |
| 52 [new ManyToOneTransformer("txt")] | |
| 53 ]); | |
| 54 | |
| 55 var gotError = false; | |
| 56 graph.results.listen(wrapAsync((result) { | |
| 57 expect(result.error is MissingInputException, isTrue); | |
| 58 expect(result.error.id, equals(new AssetId.parse("app|a.inc"))); | |
| 59 gotError = true; | |
| 60 })); | |
| 61 | |
| 62 graph.updateSources([new AssetId.parse("app|a.txt")]); | |
| 63 | |
| 64 expectNoAsset(graph, "app|a.out"); | |
| 65 | |
| 66 schedule(() { | |
| 67 expect(gotError, isTrue); | |
| 68 }); | |
| 69 }); | |
| 70 | |
| 71 test("fails if a non-primary input is removed", () { | |
| 72 var provider = new MockProvider({ | |
| 73 "app|a.txt": "a.inc,b.inc,c.inc", | |
| 74 "app|a.inc": "a", | |
| 75 "app|b.inc": "b", | |
| 76 "app|c.inc": "c" | |
| 77 }); | |
| 78 | |
| 79 var graph = new AssetGraph(provider, [ | |
| 80 [new ManyToOneTransformer("txt")] | |
| 81 ]); | |
| 82 | |
| 83 var gotError = false; | |
| 84 graph.results.listen(wrapAsync((result) { | |
| 85 expect(result.error is MissingInputException, isTrue); | |
| 86 expect(result.error.id, equals(new AssetId.parse("app|b.inc"))); | |
| 87 gotError = true; | |
| 88 })); | |
|
nweiz
2013/06/18 23:14:46
It's confusing that you're setting this up before
Bob Nystrom
2013/06/20 00:23:59
This is a broadcast stream and the build process r
| |
| 89 | |
| 90 graph.updateSources([ | |
| 91 new AssetId.parse("app|a.txt"), | |
| 92 new AssetId.parse("app|a.inc"), | |
| 93 new AssetId.parse("app|b.inc"), | |
| 94 new AssetId.parse("app|c.inc") | |
| 95 ]); | |
| 96 | |
| 97 expectAsset(graph, "app|a.out", "abc"); | |
| 98 | |
| 99 schedule(() { | |
| 100 graph.removeSources([new AssetId.parse("app|b.inc")]); | |
| 101 }); | |
| 102 | |
| 103 expectNoAsset(graph, "app|a.out"); | |
| 104 | |
| 105 schedule(() { | |
| 106 expect(gotError, isTrue); | |
| 107 }); | |
| 108 }); | |
| 109 | |
| 110 test("catches transformer exceptions and reports them", () { | |
| 111 var provider = new MockProvider(["app|foo.txt"]); | |
| 112 var graph = new AssetGraph(provider, [ | |
| 113 [new BadTransformer(["app|foo.out"])] | |
| 114 ]); | |
| 115 | |
| 116 var gotError = false; | |
| 117 graph.results.listen(wrapAsync((result) { | |
| 118 expect(result.error, equals(BadTransformer.ERROR)); | |
| 119 gotError = true; | |
| 120 })); | |
| 121 | |
| 122 schedule(() { | |
| 123 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 124 }); | |
| 125 | |
| 126 expectNoAsset(graph, "app|foo.out"); | |
| 127 | |
| 128 schedule(() { | |
| 129 expect(gotError, isTrue); | |
| 130 }); | |
| 131 }); | |
| 132 | |
| 133 // TODO(rnystrom): Is this the behavior we expect? If a transformer fails | |
| 134 // to transform a file, should we just skip past it to the source? | |
|
nweiz
2013/06/18 23:14:46
Definitely not. If a transformer fails, getting th
Bob Nystrom
2013/06/20 00:23:59
I'm going to leave this test for now just to pin d
| |
| 135 test("yields a source if a transform fails on it", () { | |
| 136 var provider = new MockProvider(["app|foo.txt"]); | |
| 137 var graph = new AssetGraph(provider, [ | |
| 138 [new BadTransformer(["app|foo.txt"])] | |
| 139 ]); | |
| 140 | |
| 141 schedule(() { | |
| 142 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 143 }); | |
| 144 | |
| 145 expectAsset(graph, "app|foo.txt"); | |
| 146 }); | |
| 147 | |
| 148 test("catches errors even if nothing is waiting for process results", () { | |
| 149 var provider = new MockProvider(["app|foo.txt"]); | |
| 150 var graph = new AssetGraph(provider, [[new BadTransformer([])]]); | |
| 151 var resultFuture = graph.results.first; | |
|
nweiz
2013/06/18 23:14:46
Why are you getting this future here? Why not do i
Bob Nystrom
2013/06/20 00:23:59
I need to make sure I grab it before the updateSou
| |
| 152 | |
| 153 schedule(() { | |
| 154 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 155 }); | |
| 156 | |
| 157 // Note: No asset requests here. | |
| 158 | |
| 159 schedule(() { | |
| 160 return resultFuture.then((result) { | |
| 161 expect(result.error, equals(BadTransformer.ERROR)); | |
| 162 }); | |
| 163 }); | |
|
nweiz
2013/06/18 23:14:46
I think wrapping the first argument to [expect] in
Bob Nystrom
2013/06/20 00:23:59
Maybe it's just me, but I really prefer the schedu
nweiz
2013/06/20 23:06:08
I disagree. I like them best when they're inside l
Bob Nystrom
2013/06/21 00:13:20
My plan for the next patch is to clean up the test
| |
| 164 }); | |
| 165 | |
| 166 test("discards outputs from failed transforms", () { | |
| 167 var provider = new MockProvider(["app|foo.txt"]); | |
| 168 var graph = new AssetGraph(provider, [ | |
| 169 [new BadTransformer(["a.out", "b.out"])] | |
| 170 ]); | |
| 171 | |
| 172 schedule(() { | |
| 173 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 174 }); | |
| 175 | |
| 176 expectNoAsset(graph, "app|a.out"); | |
| 177 }); | |
| 178 } | |
| OLD | NEW |