OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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.package_graph.transform.pass_through_test; |
| 6 |
| 7 import 'package:barback/src/utils.dart'; |
| 8 import 'package:scheduled_test/scheduled_test.dart'; |
| 9 |
| 10 import '../../utils.dart'; |
| 11 |
| 12 main() { |
| 13 initConfig(); |
| 14 test("a transform consumes its input without overwriting it", () { |
| 15 initGraph([ |
| 16 "app|foo.txt" |
| 17 ], { |
| 18 "app": [[new RewriteTransformer("txt", "out")..consumePrimary = true]] |
| 19 }); |
| 20 |
| 21 updateSources(["app|foo.txt"]); |
| 22 expectAsset("app|foo.out", "foo.out"); |
| 23 expectNoAsset("app|foo.txt"); |
| 24 buildShouldSucceed(); |
| 25 }); |
| 26 |
| 27 test("a transform consumes its input while a sibling overwrites it", () { |
| 28 initGraph([ |
| 29 "app|foo.txt" |
| 30 ], { |
| 31 "app": [[ |
| 32 new RewriteTransformer("txt", "out")..consumePrimary = true, |
| 33 new RewriteTransformer("txt", "txt") |
| 34 ]] |
| 35 }); |
| 36 |
| 37 updateSources(["app|foo.txt"]); |
| 38 expectAsset("app|foo.out", "foo.out"); |
| 39 expectAsset("app|foo.txt", "foo.txt"); |
| 40 buildShouldSucceed(); |
| 41 }); |
| 42 |
| 43 test("a transform stops consuming its input", () { |
| 44 initGraph({ |
| 45 "app|foo.txt": "yes" |
| 46 }, { |
| 47 "app": [[ |
| 48 new ConditionallyConsumePrimaryTransformer("txt", "out", "yes") |
| 49 ]] |
| 50 }); |
| 51 |
| 52 updateSources(["app|foo.txt"]); |
| 53 expectAsset("app|foo.out", "yes.out"); |
| 54 expectNoAsset("app|foo.txt"); |
| 55 buildShouldSucceed(); |
| 56 |
| 57 modifyAsset("app|foo.txt", "no"); |
| 58 updateSources(["app|foo.txt"]); |
| 59 expectAsset("app|foo.out", "no.out"); |
| 60 expectAsset("app|foo.txt", "no"); |
| 61 buildShouldSucceed(); |
| 62 }); |
| 63 |
| 64 test("two sibling transforms both consume their input", () { |
| 65 initGraph(["app|foo.txt"], { |
| 66 "app": [[ |
| 67 new RewriteTransformer("txt", "one")..consumePrimary = true, |
| 68 new RewriteTransformer("txt", "two")..consumePrimary = true |
| 69 ]] |
| 70 }); |
| 71 |
| 72 updateSources(["app|foo.txt"]); |
| 73 expectAsset("app|foo.one", "foo.one"); |
| 74 expectAsset("app|foo.two", "foo.two"); |
| 75 expectNoAsset("app|foo.txt"); |
| 76 buildShouldSucceed(); |
| 77 }); |
| 78 |
| 79 test("a transform stops consuming its input but a sibling is still " |
| 80 "consuming it", () { |
| 81 initGraph({ |
| 82 "app|foo.txt": "yes" |
| 83 }, { |
| 84 "app": [[ |
| 85 new RewriteTransformer("txt", "one")..consumePrimary = true, |
| 86 new ConditionallyConsumePrimaryTransformer("txt", "two", "yes") |
| 87 ]] |
| 88 }); |
| 89 |
| 90 updateSources(["app|foo.txt"]); |
| 91 expectAsset("app|foo.one", "yes.one"); |
| 92 expectAsset("app|foo.two", "yes.two"); |
| 93 expectNoAsset("app|foo.txt"); |
| 94 buildShouldSucceed(); |
| 95 |
| 96 modifyAsset("app|foo.txt", "no"); |
| 97 updateSources(["app|foo.txt"]); |
| 98 expectAsset("app|foo.one", "no.one"); |
| 99 expectAsset("app|foo.two", "no.two"); |
| 100 expectNoAsset("app|foo.txt"); |
| 101 buildShouldSucceed(); |
| 102 }); |
| 103 |
| 104 test("a transform consumes its input and emits nothing", () { |
| 105 initGraph([ |
| 106 "app|foo.txt" |
| 107 ], { |
| 108 "app": [[new EmitNothingTransformer("txt")..consumePrimary = true]] |
| 109 }); |
| 110 |
| 111 updateSources(["app|foo.txt"]); |
| 112 expectNoAsset("app|foo.txt"); |
| 113 buildShouldSucceed(); |
| 114 }); |
| 115 |
| 116 test("a transform consumes its input, then is removed", () { |
| 117 initGraph([ |
| 118 "app|foo.txt" |
| 119 ], { |
| 120 "app": [[new RewriteTransformer("txt", "out")..consumePrimary = true]] |
| 121 }); |
| 122 |
| 123 updateSources(["app|foo.txt"]); |
| 124 expectAsset("app|foo.out", "foo.out"); |
| 125 expectNoAsset("app|foo.txt"); |
| 126 buildShouldSucceed(); |
| 127 |
| 128 updateTransformers("app", [[]]); |
| 129 expectNoAsset("app|foo.out"); |
| 130 expectAsset("app|foo.txt", "foo"); |
| 131 buildShouldSucceed(); |
| 132 }); |
| 133 |
| 134 test("a transform consumes its input and emits nothing, then is removed", |
| 135 () { |
| 136 initGraph([ |
| 137 "app|foo.txt" |
| 138 ], { |
| 139 "app": [[new EmitNothingTransformer("txt")..consumePrimary = true]] |
| 140 }); |
| 141 |
| 142 updateSources(["app|foo.txt"]); |
| 143 expectNoAsset("app|foo.txt"); |
| 144 buildShouldSucceed(); |
| 145 |
| 146 updateTransformers("app", [[]]); |
| 147 expectAsset("app|foo.txt", "foo"); |
| 148 buildShouldSucceed(); |
| 149 }); |
| 150 |
| 151 test("a transform which consumes its input is added", () { |
| 152 initGraph([ |
| 153 "app|foo.txt" |
| 154 ], { |
| 155 "app": [[]] |
| 156 }); |
| 157 |
| 158 updateSources(["app|foo.txt"]); |
| 159 expectNoAsset("app|foo.out"); |
| 160 expectAsset("app|foo.txt", "foo"); |
| 161 buildShouldSucceed(); |
| 162 |
| 163 updateTransformers("app", [[ |
| 164 new RewriteTransformer("txt", "out")..consumePrimary = true |
| 165 ]]); |
| 166 expectAsset("app|foo.out", "foo.out"); |
| 167 expectNoAsset("app|foo.txt"); |
| 168 buildShouldSucceed(); |
| 169 }); |
| 170 } |
OLD | NEW |