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

Side by Side Diff: sdk/lib/_internal/pub_generated/test/transformer/cache_test.dart

Issue 559833004: Cache snapshots of (mostly) immutable transformer phases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 library pub_tests;
2 import 'package:scheduled_test/scheduled_test.dart';
3 import '../descriptor.dart' as d;
4 import '../test_pub.dart';
5 import '../serve/utils.dart';
6 void setUp() {
7 servePackages((builder) {
8 builder.serveRepoPackage('barback');
9 builder.serve("foo", "1.2.3", deps: {
10 'barback': 'any'
11 },
12 contents: [
13 d.dir(
14 "lib",
15 [d.file("transformer.dart", replaceTransformer("Hello", "Goodbye "))])]);
16 builder.serve("bar", "1.2.3", deps: {
17 'barback': 'any'
18 },
19 contents: [
20 d.dir(
21 "lib",
22 [d.file("transformer.dart", replaceTransformer("Goodbye", "See y a"))])]);
23 });
24 d.dir(appPath, [d.pubspec({
25 "name": "myapp",
26 "dependencies": {
27 "foo": "1.2.3",
28 "bar": "1.2.3"
29 },
30 "transformers": ["foo"]
31 }),
32 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).cre ate();
33 pubGet();
34 }
35 main() {
36 initConfig();
37 integration("caches a transformer snapshot", () {
38 setUp();
39 var process = pubRun(args: ['myapp']);
40 process.stdout.expect("Goodbye!");
41 process.shouldExit();
42 d.dir(
43 appPath,
44 [
45 d.dir(
46 ".pub/transformers",
47 [
48 d.file("manifest.txt", "0.1.2+3\nfoo"),
49 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
50 process = pubRun(args: ['myapp']);
51 process.stdout.expect("Goodbye!");
52 process.shouldExit();
53 });
54 integration("recaches if the SDK version is out-of-date", () {
55 setUp();
56 d.dir(
57 appPath,
58 [
59 d.dir(
60 ".pub/transformers",
61 [
62 d.file("manifest.txt", "0.0.1\nfoo"),
63 d.file("transformers.snapshot", "junk")])]).create();
64 var process = pubRun(args: ['myapp']);
65 process.stdout.expect("Goodbye!");
66 process.shouldExit();
67 d.dir(
68 appPath,
69 [
70 d.dir(
71 ".pub/transformers",
72 [
73 d.file("manifest.txt", "0.1.2+3\nfoo"),
74 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
75 });
76 integration("recaches if the transformers change", () {
77 setUp();
78 var process = pubRun(args: ['myapp']);
79 process.stdout.expect("Goodbye!");
80 process.shouldExit();
81 d.dir(
82 appPath,
83 [
84 d.dir(
85 ".pub/transformers",
86 [
87 d.file("manifest.txt", "0.1.2+3\nfoo"),
88 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
89 d.dir(appPath, [d.pubspec({
90 "name": "myapp",
91 "dependencies": {
92 "foo": "1.2.3",
93 "bar": "1.2.3"
94 },
95 "transformers": ["foo", "bar"]
96 }),
97 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).c reate();
98 process = pubRun(args: ['myapp']);
99 process.stdout.expect("See ya!");
100 process.shouldExit();
101 d.dir(
102 appPath,
103 [
104 d.dir(
105 ".pub/transformers",
106 [
107 d.file("manifest.txt", "0.1.2+3\nbar,foo"),
108 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
109 });
110 integration("recaches if the transformer version changes", () {
111 setUp();
112 var process = pubRun(args: ['myapp']);
113 process.stdout.expect("Goodbye!");
114 process.shouldExit();
115 d.dir(
116 appPath,
117 [
118 d.dir(
119 ".pub/transformers",
120 [
121 d.file("manifest.txt", "0.1.2+3\nfoo"),
122 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
123 servePackages((builder) {
124 builder.serve("foo", "2.0.0", deps: {
125 'barback': 'any'
126 },
127 contents: [
128 d.dir(
129 "lib",
130 [d.file("transformer.dart", replaceTransformer("Hello", "New") )])]);
131 });
132 d.dir(appPath, [d.pubspec({
133 "name": "myapp",
134 "dependencies": {
135 "foo": "any"
136 },
137 "transformers": ["foo"]
138 })]).create();
139 pubUpgrade();
140 process = pubRun(args: ['myapp']);
141 process.stdout.expect("New!");
142 process.shouldExit();
143 d.dir(
144 appPath,
145 [
146 d.dir(
147 ".pub/transformers",
148 [
149 d.file("manifest.txt", "0.1.2+3\nfoo"),
150 d.matcherFile("transformers.snapshot", isNot(isEmpty))])]).v alidate();
151 });
152 integration("recaches if a transitive dependency version changes", () {
153 servePackages((builder) {
154 builder.serveRepoPackage('barback');
155 builder.serve("foo", "1.2.3", deps: {
156 'barback': 'any',
157 'bar': 'any'
158 }, contents: [d.dir("lib", [d.file("transformer.dart", """
159 import 'dart:async';
160
161 import 'package:barback/barback.dart';
162 import 'package:bar/bar.dart';
163
164 class ReplaceTransformer extends Transformer {
165 ReplaceTransformer.asPlugin();
166
167 String get allowedExtensions => '.dart';
168
169 Future apply(Transform transform) {
170 return transform.primaryInput.readAsString().then((contents) {
171 transform.addOutput(new Asset.fromString(
172 transform.primaryInput.id,
173 contents.replaceAll("Hello", replacement)));
174 });
175 }
176 }
177 """)])]);
178 builder.serve(
179 "bar",
180 "1.2.3",
181 contents: [
182 d.dir("lib", [d.file("bar.dart", "final replacement = 'Goodbye';") ])]);
183 });
184 d.dir(appPath, [d.pubspec({
185 "name": "myapp",
186 "dependencies": {
187 "foo": "1.2.3"
188 },
189 "transformers": ["foo"]
190 }),
191 d.dir("bin", [d.file("myapp.dart", "main() => print('Hello!');")])]).c reate();
192 pubGet();
193 var process = pubRun(args: ['myapp']);
194 process.stdout.expect("Goodbye!");
195 process.shouldExit();
196 servePackages((builder) {
197 builder.serve(
198 "bar",
199 "2.0.0",
200 contents: [
201 d.dir("lib", [d.file("bar.dart", "final replacement = 'See ya';")] )]);
202 });
203 d.dir(appPath, [d.pubspec({
204 "name": "myapp",
205 "dependencies": {
206 "foo": "any"
207 },
208 "transformers": ["foo"]
209 })]).create();
210 pubUpgrade();
211 process = pubRun(args: ['myapp']);
212 process.stdout.expect("See ya!");
213 process.shouldExit();
214 });
215 }
216 String replaceTransformer(String input, String output) {
217 return """
218 import 'dart:async';
219
220 import 'package:barback/barback.dart';
221
222 class ReplaceTransformer extends Transformer {
223 ReplaceTransformer.asPlugin();
224
225 String get allowedExtensions => '.dart';
226
227 Future apply(Transform transform) {
228 return transform.primaryInput.readAsString().then((contents) {
229 transform.addOutput(new Asset.fromString(
230 transform.primaryInput.id,
231 contents.replaceAll("$input", "$output")));
232 });
233 }
234 }
235 """;
236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698