Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Unified Diff: pkg/barback/test/package_graph/lazy_transformer_test.dart

Issue 149243009: Add support for lazy transformers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/barback/test/package_graph/lazy_transformer_test.dart
diff --git a/pkg/barback/test/package_graph/lazy_transformer_test.dart b/pkg/barback/test/package_graph/lazy_transformer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f592d0b8eb3860eea61aefe2f8493971aa24f805
--- /dev/null
+++ b/pkg/barback/test/package_graph/lazy_transformer_test.dart
@@ -0,0 +1,177 @@
+// 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.lazy_asset_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("requesting a lazy asset should cause it to be generated", () {
+ initGraph(["app|foo.blub"], {"app": [
+ [new LazyRewriteTransformer("blub", "blab")]
+ ]});
+ updateSources(["app|foo.blub"]);
+ expectAsset("app|foo.blab", "foo.blab");
+ buildShouldSucceed();
+ });
+
+ test("calling getAllAssets should cause a lazy asset to be generated", () {
+ var transformer = new LazyRewriteTransformer("blub", "blab");
+ initGraph(["app|foo.blub"], {"app": [[transformer]]});
+ updateSources(["app|foo.blub"]);
+ expectAllAssets(["app|foo.blab"]);
+ buildShouldSucceed();
+ expect(transformer.numRuns, completion(equals(1)));
+ });
+
+ test("requesting a lazy asset multiple times should only cause it to be "
+ "generated once", () {
+ var transformer = new LazyRewriteTransformer("blub", "blab");
+ initGraph(["app|foo.blub"], {"app": [[transformer]]});
+ updateSources(["app|foo.blub"]);
+ expectAsset("app|foo.blab", "foo.blab");
+ expectAsset("app|foo.blab", "foo.blab");
+ expectAsset("app|foo.blab", "foo.blab");
+ buildShouldSucceed();
+ expect(transformer.numRuns, completion(equals(1)));
+ });
+
+ test("a lazy asset can be consumed by a non-lazy transformer", () {
+ initGraph(["app|foo.blub"], {"app": [
+ [new LazyRewriteTransformer("blub", "blab")],
+ [new RewriteTransformer("blab", "blib")]
+ ]});
+ updateSources(["app|foo.blub"]);
+ expectAsset("app|foo.blib", "foo.blab.blib");
+ buildShouldSucceed();
+ });
+
+ test("a lazy asset isn't eagerly compiled", () {
+ var transformer = new LazyRewriteTransformer("blub", "blab");
+ initGraph(["app|foo.blub"], {"app": [[transformer]]});
+ updateSources(["app|foo.blub"]);
+ buildShouldSucceed();
+ expect(transformer.numRuns, completion(equals(0)));
+ });
+
+ test("a lazy asset emitted by a group isn't eagerly compiled", () {
+ var transformer = new LazyRewriteTransformer("blub", "blab");
+ initGraph(["app|foo.blub"], {"app": [
+ [new TransformerGroup([[transformer]])]
+ ]});
+ updateSources(["app|foo.blub"]);
+ buildShouldSucceed();
+ expect(transformer.numRuns, completion(equals(0)));
+ });
+
+ test("a lazy asset piped into a non-lazy transformer is eagerly compiled",
+ () {
+ var transformer = new LazyRewriteTransformer("blub", "blab");
+ initGraph(["app|foo.blub"], {"app": [
+ [transformer],
+ [new RewriteTransformer("blab", "blib")]
+ ]});
+ updateSources(["app|foo.blub"]);
+ buildShouldSucceed();
+ expect(transformer.numRuns, completion(equals(1)));
+ });
+
+ // TODO(nweiz): enable these once DryRunTransformers forward laziness
+ // properly.
Bob Nystrom 2014/01/30 19:33:44 File a bug for this.
nweiz 2014/01/31 03:43:27 Done.
+ //
+ // test("a lazy asset piped into a dry-run transformer isn't eagerly "
+ // "compiled", () {
+ // var transformer1 = new LazyRewriteTransformer("blub", "blab");
+ // var transformer2 = new DryRunRewriteTransformer("blab", "blib");
+ // initGraph(["app|foo.blub"], {"app": [
+ // [transformer1], [transformer2]
+ // ]});
+ // updateSources(["app|foo.blub"]);
+ // buildShouldSucceed();
+ // expect(transformer1.numRuns, completion(equals(0)));
+ // expect(transformer2.numRuns, completion(equals(0)));
+ // });
+ //
+ // test("a lazy asset piped into a dry-run transformer is compiled on-demand",
+ // () {
+ // initGraph(["app|foo.blub"], {"app": [
+ // [new LazyRewriteTransformer("blub", "blab")],
+ // [new DryRunRewriteTransformer("blab", "blib")]
+ // ]});
+ // updateSources(["app|foo.blub"]);
+ // expectAsset("app|foo.blib", "foo.blab.blib");
+ // buildShouldSucceed();
+ // });
+
+ test("a lazy asset works as a cross-package input", () {
+ initGraph({
+ "pkg1|foo.blub": "foo",
+ "pkg2|a.txt": "pkg1|foo.blab"
+ }, {"pkg1": [
+ [new LazyRewriteTransformer("blub", "blab")],
+ ], "pkg2": [
+ [new ManyToOneTransformer("txt")]
+ ]});
+
+ updateSources(["pkg1|foo.blub", "pkg2|a.txt"]);
+ expectAsset("pkg2|a.out", "foo.blab");
+ buildShouldSucceed();
+ });
+
+ test("a lazy transformer can consume secondary inputs lazily", () {
+ initGraph({
+ "app|a.inc": "a",
+ "app|a.txt": "a.inc"
+ }, {"app": [
+ [new LazyManyToOneTransformer("txt")]
+ ]});
+
+ updateSources(["app|a.inc", "app|a.txt"]);
+ expectAsset("app|a.out", "a");
+ buildShouldSucceed();
+ });
+
+ test("once a lazy transformer is materialized, it runs eagerly afterwards",
Bob Nystrom 2014/01/30 19:33:44 I know this is what we discussed, but I wonder if
nweiz 2014/01/31 03:43:27 I think this is correct. I think when the user is
Bob Nystrom 2014/01/31 18:28:53 SGTM!
+ () {
+ var transformer = new LazyRewriteTransformer("blub", "blab");
+ initGraph(["app|foo.blub"], {"app": [[transformer]]});
+
+ updateSources(["app|foo.blub"]);
+ buildShouldSucceed();
+
Bob Nystrom 2014/01/30 19:33:44 Comment: // Request the asset once to force it to
nweiz 2014/01/31 03:43:27 Done.
+ expectAsset("app|foo.blab", "foo.blab");
+ buildShouldSucceed();
+
+ updateSources(["app|foo.blub"]);
+ buildShouldSucceed();
+
+ expect(transformer.numRuns, completion(equals(2)));
+ });
+
+ test("an error emitted in a lazy transformer's dryRun method is caught and "
+ "reported", () {
+ initGraph(["app|foo.txt"], {"app": [
+ [new LazyBadTransformer("app|foo.out")]
+ ]});
+
+ updateSources(["app|foo.txt"]);
+ buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]);
+ });
+
+ test("an error emitted in a lazy transformer's dryRun method prevents it "
+ "from being materialized", () {
+ var transformer = new LazyBadTransformer("app|foo.out");
+ initGraph(["app|foo.txt"], {"app": [[transformer]]});
+
+ updateSources(["app|foo.txt"]);
+ expectNoAsset("app|foo.out");
+ buildShouldFail([isTransformerException(equals(LazyBadTransformer.ERROR))]);
+ expect(transformer.numRuns, completion(equals(0)));
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698