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

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

Issue 1165473002: Start pulling pub from its own repo. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 pub_tests;
6
7 import 'package:scheduled_test/scheduled_test.dart';
8 import 'package:scheduled_test/scheduled_stream.dart';
9
10 import '../../lib/src/exit_codes.dart' as exit_codes;
11 import '../descriptor.dart' as d;
12 import '../test_pub.dart';
13
14 const SOURCE_MAPS_TRANSFORMER = """
15 import 'dart:async';
16
17 import 'package:barback/barback.dart';
18 import 'package:source_maps/source_maps.dart';
19
20 class RewriteTransformer extends Transformer {
21 RewriteTransformer.asPlugin();
22
23 String get allowedExtensions => '.txt';
24
25 Future apply(Transform transform) {
26 transform.logger.info('info!');
27 transform.logger.warning('Warning!',
28 asset: transform.primaryInput.id.changeExtension('.foo'));
29 var sourceFile = new SourceFile.text(
30 'http://fake.com/not_real.dart',
31 'not a real\\ndart file');
32 transform.logger.error('ERROR!', span: new FileSpan(sourceFile, 11));
33 return transform.primaryInput.readAsString().then((contents) {
34 var id = transform.primaryInput.id.changeExtension(".out");
35 transform.addOutput(new Asset.fromString(id, "\$contents.out"));
36 });
37 }
38 }
39 """;
40
41 const SOURCE_SPAN_TRANSFORMER = """
42 import 'dart:async';
43
44 import 'package:barback/barback.dart';
45 import 'package:source_span/source_span.dart';
46
47 class RewriteTransformer extends Transformer {
48 RewriteTransformer.asPlugin();
49
50 String get allowedExtensions => '.txt';
51
52 Future apply(Transform transform) {
53 transform.logger.info('info!');
54 transform.logger.warning('Warning!',
55 asset: transform.primaryInput.id.changeExtension('.foo'));
56 var sourceFile = new SourceFile('not a real\\ndart file',
57 url: 'http://fake.com/not_real.dart');
58 transform.logger.error('ERROR!', span: sourceFile.span(11, 12));
59 return transform.primaryInput.readAsString().then((contents) {
60 var id = transform.primaryInput.id.changeExtension(".out");
61 transform.addOutput(new Asset.fromString(id, "\$contents.out"));
62 });
63 }
64 }
65 """;
66
67 main() {
68 initConfig();
69 // This intentionally tests barback 0.14.2 with both transformers, since it
70 // supports both types of span.
71 withBarbackVersions("<0.15.0", () => runTest(SOURCE_MAPS_TRANSFORMER));
72 withBarbackVersions(">=0.14.2", () => runTest(SOURCE_SPAN_TRANSFORMER));
73 }
74
75 void runTest(String transformerText) {
76 integration("can log messages", () {
77 d.dir(appPath, [
78 d.pubspec({
79 "name": "myapp",
80 "transformers": ["myapp/src/transformer"]
81 }),
82 d.dir("lib", [d.dir("src", [
83 d.file("transformer.dart", transformerText)
84 ])]),
85 d.dir("web", [
86 d.file("foo.txt", "foo")
87 ])
88 ]).create();
89
90 createLockFile('myapp', pkg: ['barback']);
91
92 var pub = startPub(args: ["build"]);
93 pub.stdout.expect(startsWith("Loading source assets..."));
94 pub.stdout.expect(consumeWhile(matches("Loading .* transformers...")));
95 pub.stdout.expect(startsWith("Building myapp..."));
96
97 pub.stdout.expect(emitsLines("""
98 [Rewrite on myapp|web/foo.txt]:
99 info!"""));
100
101 pub.stderr.expect(emitsLines("""
102 [Rewrite on myapp|web/foo.txt with input myapp|web/foo.foo]:
103 Warning!
104 [Rewrite on myapp|web/foo.txt]:"""));
105
106 // The details of the analyzer's error message change pretty frequently,
107 // so instead of validating the entire line, just look for a couple of
108 // salient bits of information.
109 pub.stderr.expect(allOf([
110 contains("2"), // The line number.
111 contains("1"), // The column number.
112 contains("http://fake.com/not_real.dart"), // The library.
113 contains("ERROR"), // That it's an error.
114 ]));
115
116 // In barback >=0.15.0, the span will point to the location where the error
117 // occurred.
118 pub.stderr.expect(allow(inOrder(["d", "^"])));
119
120 pub.stderr.expect("Build failed.");
121
122 pub.shouldExit(exit_codes.DATA);
123 });
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698