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/release", [ | |
66 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
67 d.matcherFile("phase1.snapshot", isNot(isEmpty)) | |
68 ]) | |
69 ]).validate(); | |
70 | |
Bob Nystrom
2014/09/10 17:58:10
Document running again to make sure running the sn
nweiz
2014/09/10 23:30:13
Done.
| |
71 process = pubRun(args: ['myapp']); | |
72 process.stdout.expect("Goodbye!"); | |
73 process.shouldExit(); | |
74 }); | |
75 | |
76 integration("recaches if the SDK version is out-of-date", () { | |
77 setUp(); | |
78 | |
79 d.dir(appPath, [ | |
80 d.dir(".pub/transformers/release", [ | |
81 // The version 0.0.1 is different than the test version 0.1.2+3. | |
82 d.file("manifest.txt", "0.0.1\nfoo"), | |
83 d.file("phase1.snapshot", "junk") | |
84 ]) | |
85 ]).create(); | |
86 | |
87 var process = pubRun(args: ['myapp']); | |
88 process.stdout.expect("Goodbye!"); | |
89 process.shouldExit(); | |
90 | |
91 d.dir(appPath, [ | |
92 d.dir(".pub/transformers/release", [ | |
93 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
94 d.matcherFile("phase1.snapshot", isNot(isEmpty)) | |
95 ]) | |
96 ]).validate(); | |
97 | |
98 process = pubRun(args: ['myapp']); | |
99 process.stdout.expect("Goodbye!"); | |
100 process.shouldExit(); | |
Bob Nystrom
2014/09/10 17:58:10
I don't think it's worth re-running here.
nweiz
2014/09/10 23:30:13
Done.
| |
101 }); | |
102 | |
103 integration("recaches if the phase changes", () { | |
104 setUp(); | |
105 | |
106 var process = pubRun(args: ['myapp']); | |
107 process.stdout.expect("Goodbye!"); | |
108 process.shouldExit(); | |
109 | |
110 d.dir(appPath, [ | |
111 d.dir(".pub/transformers/release", [ | |
112 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
113 d.matcherFile("phase1.snapshot", isNot(isEmpty)) | |
114 ]) | |
115 ]).validate(); | |
116 | |
117 d.dir(appPath, [ | |
118 d.pubspec({ | |
119 "name": "myapp", | |
120 "dependencies": { | |
121 "foo": "1.2.3", | |
122 "bar": "1.2.3" | |
123 }, | |
124 "transformers": ["foo", "bar"] | |
125 }), | |
126 d.dir("bin", [ | |
127 d.file("myapp.dart", "main() => print('Hello!');") | |
128 ]) | |
129 ]).create(); | |
130 | |
131 process = pubRun(args: ['myapp']); | |
132 process.stdout.expect("See ya!"); | |
133 process.shouldExit(); | |
134 | |
135 d.dir(appPath, [ | |
136 d.dir(".pub/transformers/release", [ | |
137 d.file("manifest.txt", "0.1.2+3\nbar,foo"), | |
138 d.matcherFile("phase1.snapshot", isNot(isEmpty)) | |
139 ]) | |
140 ]).validate(); | |
141 }); | |
142 | |
143 integration("URL-escapes a custom mode", () { | |
144 setUp(); | |
145 | |
146 pubServe(args: ["--mode", "weird/custom mode", "bin"]); | |
147 requestShouldSucceed("myapp.dart", "main() => print('Goodbye!');", | |
148 root: 'bin'); | |
149 endPubServe(); | |
150 | |
151 d.dir(appPath, [ | |
152 d.dir(".pub/transformers/weird%2Fcustom%20mode", [ | |
153 d.file("manifest.txt", "0.1.2+3\nfoo"), | |
154 d.matcherFile("phase1.snapshot", isNot(isEmpty)) | |
155 ]) | |
156 ]).validate(); | |
157 }); | |
158 | |
159 solo_integration("removes an unused phase snapshot", () { | |
Bob Nystrom
2014/09/10 17:58:10
Oopsie!
nweiz
2014/09/10 23:30:13
Done.
| |
160 setUp(); | |
161 | |
162 var process = pubRun(args: ['myapp']); | |
163 process.stdout.expect("Goodbye!"); | |
164 process.shouldExit(); | |
165 | |
166 d.dir(appPath, [ | |
167 d.dir(".pub/transformers/release", [ | |
168 // Add a phase2 snapshot that's unused. This should get deleted when we | |
169 // run again. | |
170 d.file("manifest.txt", "0.1.2+3\nfoo\nbar"), | |
171 d.file("phase2.snapshot", "junk") | |
172 ]) | |
173 ]).create(); | |
174 | |
175 process = pubRun(args: ['myapp']); | |
176 process.stdout.expect("Goodbye!"); | |
177 process.shouldExit(); | |
178 | |
179 d.dir(appPath, [ | |
180 d.dir(".pub/transformers/release", [ | |
181 d.nothing("phase2.snapshot") | |
182 ]) | |
183 ]).validate(); | |
184 }); | |
185 } | |
186 | |
187 String replaceTransformer(String input, String output) { | |
188 return """ | |
189 import 'dart:async'; | |
190 | |
191 import 'package:barback/barback.dart'; | |
192 | |
193 class ReplaceTransformer extends Transformer { | |
194 ReplaceTransformer.asPlugin(); | |
195 | |
196 String get allowedExtensions => '.dart'; | |
197 | |
198 Future apply(Transform transform) { | |
199 return transform.primaryInput.readAsString().then((contents) { | |
200 transform.addOutput(new Asset.fromString( | |
201 transform.primaryInput.id, | |
202 contents.replaceAll("$input", "$output"))); | |
203 }); | |
204 } | |
205 } | |
206 """; | |
207 } | |
OLD | NEW |