OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014, 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 | |
9 import '../descriptor.dart' as d; | |
10 import '../test_pub.dart'; | |
11 import '../serve/utils.dart'; | |
12 | |
13 // TODO(nweiz): Currently scheduled_test.setUp doesn't play well with test_pub, | |
14 // since it only assigns the sandbox directory once the main test body has | |
15 // run. Fix this and move this to a real setUp call. | |
16 void setUp() { | |
17 servePackages((builder) { | |
18 builder.serveRepoPackage('barback'); | |
19 | |
20 builder.serve("foo", "1.2.3", | |
21 deps: {'barback': 'any'}, | |
22 contents: [ | |
23 d.dir("lib", [ | |
24 d.file("transformer.dart", replaceTransformer("Hello", "Goodbye")) | |
25 ]) | |
26 ]); | |
27 | |
28 builder.serve("bar", "1.2.3", | |
29 deps: {'barback': 'any'}, | |
30 contents: [ | |
31 d.dir("lib", [ | |
32 d.file("transformer.dart", replaceTransformer("Goodbye", "See ya")) | |
33 ]) | |
34 ]); | |
35 }); | |
36 | |
37 d.dir(appPath, [ | |
38 d.pubspec({ | |
39 "name": "myapp", | |
40 "dependencies": { | |
41 "foo": "1.2.3", | |
42 "bar": "1.2.3" | |
43 }, | |
44 "transformers": ["foo"] | |
45 }), | |
46 d.dir("bin", [ | |
47 d.file("myapp.dart", "main() => print('Hello!');") | |
48 ]) | |
49 ]).create(); | |
50 | |
51 pubGet(); | |
52 } | |
53 | |
54 main() { | |
55 initConfig(); | |
56 | |
57 integration("caches a transformer snapshot", () { | |
58 setUp(); | |
59 | |
60 var process = pubRun(args: ['myapp']); | |
61 process.stdout.expect("Goodbye!"); | |
62 process.shouldExit(); | |
63 | |
64 d.dir(appPath, [ | |
65 d.dir(".pub/transformers", [ | |
66 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
67 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
68 ]) | |
69 ]).validate(); | |
70 | |
71 // Run the executable again to make sure loading the transformer from the | |
72 // cache works. | |
73 process = pubRun(args: ['myapp']); | |
74 process.stdout.expect("Goodbye!"); | |
75 process.shouldExit(); | |
76 }); | |
77 | |
78 integration("recaches if the SDK version is out-of-date", () { | |
79 setUp(); | |
80 | |
81 d.dir(appPath, [ | |
82 d.dir(".pub/transformers", [ | |
83 // The version 0.0.1 is different than the test version 0.1.2+3. | |
84 d.file("manifest.txt", "0.0.1\nfoo"), | |
85 d.file("transformers.snapshot", "junk") | |
86 ]) | |
87 ]).create(); | |
88 | |
89 var process = pubRun(args: ['myapp']); | |
90 process.stdout.expect("Goodbye!"); | |
91 process.shouldExit(); | |
92 | |
93 d.dir(appPath, [ | |
94 d.dir(".pub/transformers", [ | |
95 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
96 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
97 ]) | |
98 ]).validate(); | |
99 }); | |
100 | |
101 integration("recaches if the transformers change", () { | |
102 setUp(); | |
103 | |
104 var process = pubRun(args: ['myapp']); | |
105 process.stdout.expect("Goodbye!"); | |
106 process.shouldExit(); | |
107 | |
108 d.dir(appPath, [ | |
109 d.dir(".pub/transformers", [ | |
110 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
111 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
112 ]) | |
113 ]).validate(); | |
114 | |
115 d.dir(appPath, [ | |
116 d.pubspec({ | |
117 "name": "myapp", | |
118 "dependencies": { | |
119 "foo": "1.2.3", | |
120 "bar": "1.2.3" | |
121 }, | |
122 "transformers": ["foo", "bar"] | |
123 }), | |
124 d.dir("bin", [ | |
125 d.file("myapp.dart", "main() => print('Hello!');") | |
126 ]) | |
127 ]).create(); | |
128 | |
129 process = pubRun(args: ['myapp']); | |
130 process.stdout.expect("See ya!"); | |
131 process.shouldExit(); | |
132 | |
133 d.dir(appPath, [ | |
134 d.dir(".pub/transformers", [ | |
135 d.file("manifest.txt", "0.1.2+3\nbar,foo"), | |
136 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
137 ]) | |
138 ]).validate(); | |
139 }); | |
140 | |
141 integration("recaches if the transformer version changes", () { | |
Bob Nystrom
2014/09/12 21:17:17
Also test that it recaches if a transitive depende
nweiz
2014/09/16 00:10:53
Done.
nweiz
2014/09/16 00:10:53
Done.
| |
142 setUp(); | |
143 | |
144 var process = pubRun(args: ['myapp']); | |
145 process.stdout.expect("Goodbye!"); | |
146 process.shouldExit(); | |
147 | |
148 d.dir(appPath, [ | |
149 d.dir(".pub/transformers", [ | |
150 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
151 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
152 ]) | |
153 ]).validate(); | |
154 | |
155 servePackages((builder) { | |
156 builder.serve("foo", "2.0.0", | |
157 deps: {'barback': 'any'}, | |
158 contents: [ | |
159 d.dir("lib", [ | |
160 d.file("transformer.dart", replaceTransformer("Hello", "New")) | |
161 ]) | |
162 ]); | |
163 }); | |
164 | |
165 d.dir(appPath, [ | |
166 d.pubspec({ | |
167 "name": "myapp", | |
168 "dependencies": {"foo": "any"}, | |
169 "transformers": ["foo"] | |
170 }) | |
171 ]).create(); | |
172 | |
173 pubUpgrade(); | |
174 | |
175 process = pubRun(args: ['myapp']); | |
176 process.stdout.expect("New!"); | |
177 process.shouldExit(); | |
178 | |
179 d.dir(appPath, [ | |
180 d.dir(".pub/transformers", [ | |
181 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
182 d.matcherFile("transformers.snapshot", isNot(isEmpty)) | |
183 ]) | |
184 ]).validate(); | |
185 }); | |
186 } | |
187 | |
188 String replaceTransformer(String input, String output) { | |
189 return """ | |
190 import 'dart:async'; | |
191 | |
192 import 'package:barback/barback.dart'; | |
193 | |
194 class ReplaceTransformer extends Transformer { | |
195 ReplaceTransformer.asPlugin(); | |
196 | |
197 String get allowedExtensions => '.dart'; | |
198 | |
199 Future apply(Transform transform) { | |
200 return transform.primaryInput.readAsString().then((contents) { | |
201 transform.addOutput(new Asset.fromString( | |
202 transform.primaryInput.id, | |
203 contents.replaceAll("$input", "$output"))); | |
204 }); | |
205 } | |
206 } | |
207 """; | |
208 } | |
OLD | NEW |