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

Unified Diff: test/transform/common.dart

Issue 22825012: Introduce transformers for: (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: Created 7 years, 4 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: test/transform/common.dart
diff --git a/test/transform/common.dart b/test/transform/common.dart
new file mode 100644
index 0000000000000000000000000000000000000000..91a8cefc0735050075b863f04e4b844d70c0129b
--- /dev/null
+++ b/test/transform/common.dart
@@ -0,0 +1,104 @@
+// Copyright (c) 2013, 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 polymer.test.transfom.common;
+
+import 'dart:async';
+
+import 'package:barback/barback.dart';
+import 'package:unittest/unittest.dart';
+import 'package:stack_trace/stack_trace.dart';
+
+/** A helper package provider that has files stored in memory. */
+class TestPackageProvider implements PackageProvider {
+
+ final List<List<Transformer>> transformers;
+
+ /**
+ * Maps from an asset string identifier of the form 'package|path' to the
+ * file contents.
+ */
+ final Map<String, String> files;
+ final Iterable<String> packages;
+
+ TestPackageProvider(this.transformers, files)
+ : files = files,
+ packages = files.keys.map((s) => idFromString(s).package);
+
+ Future<Asset> getAsset(AssetId id) =>
+ new Future.value(new Asset.fromString(id, files[idToString(id)]));
+
+ Iterable<Iterable<Transformer>> getTransformers(String package) =>
+ transformers;
+}
+
+String idToString(AssetId id) => '${id.package}|${id.path}';
+AssetId idFromString(String s) {
+ int index = s.indexOf('|');
+ return new AssetId(s.substring(0, index), s.substring(index + 1));
+}
+
+/** Wraps [Barback] to simply our tests. */
+class TestHelper {
+ final Map<String, String> files;
+ Barback barback;
+ var errorSubscription;
+ var resultSubscription;
+ TestHelper(List<List<Transformer>> transformers, Map<String, String> files)
+ : files = files,
+ barback = new Barback(new TestPackageProvider(transformers, files)) {
+ errorSubscription = barback.errors.listen((e) {
+ var trace = getAttachedStackTrace(e);
+ if (trace != null) {
+ print(Trace.format(trace));
+ }
+ fail('error running barback: $e');
+ });
+ resultSubscription = barback.results.listen((result) {
+ expect(result.succeeded, isTrue, reason: "${result.errors}");
+ });
+ }
+
+ void tearDown() {
+ errorSubscription.cancel();
+ resultSubscription.cancel();
+ }
+
+ /**
+ * Tells barback which files have changed, and thus anything that depends on
+ * it on should be computed. By default mark all the input files.
+ */
+ void run([Iterable<String> paths]) {
+ if (paths == null) paths = files.keys;
+ barback.updateSources(paths.map(idFromString));
+ }
+
+ Future<String> operator [](String assetString){
+ return barback.getAssetById(idFromString(assetString))
+ .then((asset) => asset.readAsString());
+ }
+
+ Future check(String assetIdString, String content) {
+ return this[assetIdString].then((value) {
+ expect(value, content, reason: 'Final output of $assetIdString differs.');
+ });
+ }
+
+ Future checkAll(Map<String, String> files) {
+ var futures = [];
+ files.forEach((k, v) {
+ futures.add(check(k, v));
+ });
+ return Future.wait(futures);
+ }
+}
+
+testPhases(String testName, List<List<Transformer>> phases,
+ Map<String, String> inputFiles, Map<String, String> expectedFiles) {
+ test(testName, () {
+ var helper = new TestHelper(phases, inputFiles)..run();
+ return helper.checkAll(expectedFiles).then((_) => helper.tearDown());
+ });
+}
+

Powered by Google App Engine
This is Rietveld 408576698