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

Unified Diff: sdk/lib/_internal/pub/test/transformer/can_log_messages_test.dart

Issue 423823010: Support source_span spans in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 5 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
« no previous file with comments | « sdk/lib/_internal/pub/test/serve/defaults_to_debug_mode_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/test/transformer/can_log_messages_test.dart
diff --git a/sdk/lib/_internal/pub/test/transformer/can_log_messages_test.dart b/sdk/lib/_internal/pub/test/transformer/can_log_messages_test.dart
index 528b9c8a068568cdd5dba7aa43c14d3019dfee4a..3144d3206364ab9aa53d0ce33dc39ae2e07beadf 100644
--- a/sdk/lib/_internal/pub/test/transformer/can_log_messages_test.dart
+++ b/sdk/lib/_internal/pub/test/transformer/can_log_messages_test.dart
@@ -11,7 +11,7 @@ import '../../lib/src/exit_codes.dart' as exit_codes;
import '../descriptor.dart' as d;
import '../test_pub.dart';
-const TRANSFORMER = """
+const SOURCE_MAPS_TRANSFORMER = """
import 'dart:async';
import 'package:barback/barback.dart';
@@ -38,52 +38,83 @@ class RewriteTransformer extends Transformer {
}
""";
+const SOURCE_SPAN_TRANSFORMER = """
+import 'dart:async';
+
+import 'package:barback/barback.dart';
+import 'package:source_span/source_span.dart';
+
+class RewriteTransformer extends Transformer {
+ RewriteTransformer.asPlugin();
+
+ String get allowedExtensions => '.txt';
+
+ Future apply(Transform transform) {
+ transform.logger.info('info!');
+ transform.logger.warning('Warning!',
+ asset: transform.primaryInput.id.changeExtension('.foo'));
+ var sourceFile = new SourceFile('not a real\\ndart file',
+ url: 'http://fake.com/not_real.dart');
+ transform.logger.error('ERROR!', span: sourceFile.span(11, 12));
+ return transform.primaryInput.readAsString().then((contents) {
+ var id = transform.primaryInput.id.changeExtension(".out");
+ transform.addOutput(new Asset.fromString(id, "\$contents.out"));
+ });
+ }
+}
+""";
+
main() {
initConfig();
- withBarbackVersions("any", () {
- integration("can log messages", () {
- d.dir(appPath, [
- d.pubspec({
- "name": "myapp",
- "transformers": ["myapp/src/transformer"]
- }),
- d.dir("lib", [d.dir("src", [
- d.file("transformer.dart", TRANSFORMER)
- ])]),
- d.dir("web", [
- d.file("foo.txt", "foo")
- ])
- ]).create();
-
- createLockFile('myapp', pkg: ['barback']);
-
- var pub = startPub(args: ["build"]);
- pub.stdout.expect(startsWith("Loading source assets..."));
- pub.stdout.expect(consumeWhile(matches("Loading .* transformers...")));
- pub.stdout.expect(startsWith("Building myapp..."));
-
- pub.stdout.expect(emitsLines("""
+ // This intentionally tests barback 0.14.2 with both transformers, since it
+ // supports both types of span.
+ withBarbackVersions("<0.15.0", () => runTest(SOURCE_MAPS_TRANSFORMER));
+ withBarbackVersions(">=0.14.2", () => runTest(SOURCE_SPAN_TRANSFORMER));
+}
+
+void runTest(String transformerText) {
+ integration("can log messages", () {
+ d.dir(appPath, [
+ d.pubspec({
+ "name": "myapp",
+ "transformers": ["myapp/src/transformer"]
+ }),
+ d.dir("lib", [d.dir("src", [
+ d.file("transformer.dart", transformerText)
+ ])]),
+ d.dir("web", [
+ d.file("foo.txt", "foo")
+ ])
+ ]).create();
+
+ createLockFile('myapp', pkg: ['barback']);
+
+ var pub = startPub(args: ["build"]);
+ pub.stdout.expect(startsWith("Loading source assets..."));
+ pub.stdout.expect(consumeWhile(matches("Loading .* transformers...")));
+ pub.stdout.expect(startsWith("Building myapp..."));
+
+ pub.stdout.expect(emitsLines("""
[Rewrite on myapp|web/foo.txt]:
info!"""));
- pub.stderr.expect(emitsLines("""
+ pub.stderr.expect(emitsLines("""
[Rewrite on myapp|web/foo.txt with input myapp|web/foo.foo]:
Warning!
[Rewrite on myapp|web/foo.txt]:"""));
- // The details of the analyzer's error message change pretty frequently,
- // so instead of validating the entire line, just look for a couple of
- // salient bits of information.
- pub.stderr.expect(allOf([
- contains("2"), // The line number.
- contains("1"), // The column number.
- contains("http://fake.com/not_real.dart"), // The library.
- contains("ERROR"), // That it's an error.
- ]));
+ // The details of the analyzer's error message change pretty frequently,
+ // so instead of validating the entire line, just look for a couple of
+ // salient bits of information.
+ pub.stderr.expect(allOf([
+ contains("2"), // The line number.
+ contains("1"), // The column number.
+ contains("http://fake.com/not_real.dart"), // The library.
+ contains("ERROR"), // That it's an error.
+ ]));
- pub.stderr.expect("Build failed.");
+ pub.stderr.expect("Build failed.");
- pub.shouldExit(exit_codes.DATA);
- });
+ pub.shouldExit(exit_codes.DATA);
});
}
« no previous file with comments | « sdk/lib/_internal/pub/test/serve/defaults_to_debug_mode_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698