Chromium Code Reviews| Index: pkg/barback/test/package_graph/declaring_transformer_test.dart |
| diff --git a/pkg/barback/test/package_graph/declaring_transformer_test.dart b/pkg/barback/test/package_graph/declaring_transformer_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ad28f3c1a44c2ddc41b86e549c4e1d9ee854fc42 |
| --- /dev/null |
| +++ b/pkg/barback/test/package_graph/declaring_transformer_test.dart |
| @@ -0,0 +1,155 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library barback.test.package_graph.declaring_transformer_test; |
| + |
| +import 'package:barback/barback.dart'; |
| +import 'package:barback/src/utils.dart'; |
| +import 'package:scheduled_test/scheduled_test.dart'; |
| + |
| +import '../utils.dart'; |
| + |
| +main() { |
| + initConfig(); |
| + |
| + test("gets a declared output with a different path", () { |
| + initGraph(["app|foo.blub"], {"app": [ |
| + [new DeclaringRewriteTransformer("blub", "blab")] |
| + ]}); |
| + updateSources(["app|foo.blub"]); |
| + expectAsset("app|foo.blab", "foo.blab"); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + test("gets a declared output with the same path", () { |
| + initGraph(["app|foo.blub"], {"app": [ |
| + [new DeclaringRewriteTransformer("blub", "blub")] |
| + ]}); |
| + updateSources(["app|foo.blub"]); |
| + expectAsset("app|foo.blub", "foo.blub"); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + test("gets a passed-through asset", () { |
| + initGraph(["app|foo.blub"], {"app": [ |
| + [new DeclaringRewriteTransformer("blub", "blab")] |
| + ]}); |
| + updateSources(["app|foo.blub"]); |
| + expectAsset("app|foo.blub", "foo"); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + test("doesn't get a consumed asset", () { |
| + initGraph(["app|foo.blub"], {"app": [ |
| + [new DeclaringRewriteTransformer("blub", "blab")..consumePrimary = true] |
| + ]}); |
| + updateSources(["app|foo.blub"]); |
| + expectNoAsset("app|foo.blub"); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + test("gets a passed-through asset before apply is finished", () { |
|
Bob Nystrom
2014/04/08 18:23:44
What if it doesn't declare that it will overwrite
nweiz
2014/04/08 23:42:33
I think we should assume that it won't, but start
|
| + var transformer = new DeclaringRewriteTransformer("blub", "blab"); |
| + initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| + |
| + transformer.pauseApply(); |
| + updateSources(["app|foo.blub"]); |
| + expectAsset("app|foo.blub", "foo"); |
| + |
| + transformer.resumeApply(); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + test("fails to get a consumed asset before apply is finished", () { |
| + var transformer = new DeclaringRewriteTransformer("blub", "blab") |
| + ..consumePrimary = true; |
| + initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| + |
| + transformer.pauseApply(); |
| + updateSources(["app|foo.blub"]); |
| + expectNoAsset("app|foo.blub"); |
| + |
| + transformer.resumeApply(); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + test("waits to get an overwritten asset until apply is finished", () { |
|
Bob Nystrom
2014/04/08 18:23:44
The grammar is weird here. How about "waits until
nweiz
2014/04/08 23:42:33
Done.
|
| + var transformer = new DeclaringRewriteTransformer("blub", "blub"); |
| + initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| + |
| + transformer.pauseApply(); |
| + updateSources(["app|foo.blub"]); |
| + expectAssetDoesNotComplete("app|foo.blub"); |
| + |
| + transformer.resumeApply(); |
| + expectAsset("app|foo.blub", "foo.blub"); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + group("with an error in declareOutputs", () { |
| + test("still runs apply", () { |
| + initGraph(["app|foo.txt"], {"app": [[ |
| + new DeclaringBadTransformer("app|out.txt", |
| + declareError: true, applyError: false) |
| + ]]}); |
| + |
| + updateSources(["app|foo.txt"]); |
| + expectAsset("app|out.txt", "bad out"); |
| + expectAsset("app|foo.txt", "foo"); |
| + buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| + }); |
| + |
| + test("waits for apply to complete before passing through the input even if " |
| + "consumePrimary was called", () { |
| + var transformer = new DeclaringBadTransformer("app|out.txt", |
| + declareError: true, applyError: false)..consumePrimary = true; |
| + initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| + |
| + transformer.pauseApply(); |
| + updateSources(["app|foo.txt"]); |
| + expectAssetDoesNotComplete("app|out.txt"); |
| + expectAssetDoesNotComplete("app|foo.txt"); |
| + |
| + transformer.resumeApply(); |
| + expectAsset("app|out.txt", "bad out"); |
| + expectNoAsset("app|foo.txt"); |
| + buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| + }); |
| + }); |
| + |
| + test("with an error in apply still passes through the input", () { |
| + initGraph(["app|foo.txt"], {"app": [[ |
| + new DeclaringBadTransformer("app|out.txt", |
| + declareError: false, applyError: true) |
| + ]]}); |
| + |
| + updateSources(["app|foo.txt"]); |
| + expectNoAsset("app|out.txt"); |
| + expectAsset("app|foo.txt", "foo"); |
| + buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| + }); |
| + |
| + test("can emit outputs it didn't declare", () { |
|
Bob Nystrom
2014/04/08 18:23:44
What about overwriting the primary if it didn't de
nweiz
2014/04/08 23:42:33
See above.
|
| + initGraph(["app|foo.txt"], {"app": [ |
| + [new DeclareAssetsTransformer([], ["app|out.txt"])] |
| + ]}); |
| + |
| + updateSources(["app|foo.txt"]); |
| + // There's probably going to be some time when "out.txt" is unavailable, |
| + // since it was undeclared. |
| + schedule(pumpEventQueue); |
|
Bob Nystrom
2014/04/08 18:23:44
This is super sketchy.
nweiz
2014/04/08 23:42:33
In what way?
Bob Nystrom
2014/04/09 18:07:08
The comment says "probably" and then just waits an
nweiz
2014/04/09 20:11:52
It's not arbitrary; it waits until there are no ad
|
| + expectAsset("app|out.txt", "app|out.txt"); |
| + buildShouldSucceed(); |
| + }); |
| + |
| + test("can declare outputs it doesn't emit", () { |
|
Bob Nystrom
2014/04/08 18:23:44
This should at least be a warning.
nweiz
2014/04/08 23:42:33
Done.
|
| + initGraph(["app|foo.txt"], {"app": [ |
| + [new DeclareAssetsTransformer(["app|out.txt"], [])] |
| + ]}); |
| + |
| + updateSources(["app|foo.txt"]); |
| + expectNoAsset("app|out.txt"); |
| + buildShouldSucceed(); |
| + }); |
| +} |