]>
Commit | Line | Data |
---|---|---|
1408eecc | 1 | use std::fs::File; |
51d23560 AC |
2 | use std::io::prelude::*; |
3 | ||
04ddd4d0 DW |
4 | use crate::support::registry::Package; |
5 | use crate::support::{basic_manifest, project}; | |
51d23560 AC |
6 | |
7 | #[test] | |
8 | fn minor_update_two_places() { | |
9 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 10 | let p = project() |
51d23560 AC |
11 | .file( |
12 | "Cargo.toml", | |
13 | r#" | |
14 | [package] | |
15 | name = "bar" | |
16 | version = "0.0.1" | |
17 | authors = [] | |
18 | ||
19 | [dependencies] | |
20 | log = "0.1" | |
21 | foo = { path = "foo" } | |
22 | "#, | |
fecb7246 AC |
23 | ) |
24 | .file("src/lib.rs", "") | |
51d23560 AC |
25 | .file( |
26 | "foo/Cargo.toml", | |
27 | r#" | |
28 | [package] | |
29 | name = "foo" | |
30 | version = "0.0.1" | |
31 | authors = [] | |
32 | ||
33 | [dependencies] | |
34 | log = "0.1" | |
35 | "#, | |
fecb7246 AC |
36 | ) |
37 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
38 | .build(); |
39 | ||
85984a87 | 40 | p.cargo("build").run(); |
51d23560 AC |
41 | Package::new("log", "0.1.1").publish(); |
42 | ||
43 | File::create(p.root().join("foo/Cargo.toml")) | |
44 | .unwrap() | |
45 | .write_all( | |
46 | br#" | |
47 | [package] | |
48 | name = "foo" | |
49 | version = "0.0.1" | |
50 | authors = [] | |
51 | ||
52 | [dependencies] | |
53 | log = "0.1.1" | |
54 | "#, | |
fecb7246 AC |
55 | ) |
56 | .unwrap(); | |
51d23560 | 57 | |
85984a87 | 58 | p.cargo("build").run(); |
51d23560 AC |
59 | } |
60 | ||
61 | #[test] | |
62 | fn transitive_minor_update() { | |
63 | Package::new("log", "0.1.0").publish(); | |
64 | Package::new("serde", "0.1.0").dep("log", "0.1").publish(); | |
65 | ||
7fe2fbc8 | 66 | let p = project() |
51d23560 AC |
67 | .file( |
68 | "Cargo.toml", | |
69 | r#" | |
70 | [package] | |
71 | name = "bar" | |
72 | version = "0.0.1" | |
73 | authors = [] | |
74 | ||
75 | [dependencies] | |
76 | serde = "0.1" | |
77 | log = "0.1" | |
78 | foo = { path = "foo" } | |
79 | "#, | |
fecb7246 AC |
80 | ) |
81 | .file("src/lib.rs", "") | |
51d23560 AC |
82 | .file( |
83 | "foo/Cargo.toml", | |
84 | r#" | |
85 | [package] | |
86 | name = "foo" | |
87 | version = "0.0.1" | |
88 | authors = [] | |
89 | ||
90 | [dependencies] | |
91 | serde = "0.1" | |
92 | "#, | |
fecb7246 AC |
93 | ) |
94 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
95 | .build(); |
96 | ||
85984a87 | 97 | p.cargo("build").run(); |
51d23560 AC |
98 | |
99 | Package::new("log", "0.1.1").publish(); | |
100 | Package::new("serde", "0.1.1").dep("log", "0.1.1").publish(); | |
101 | ||
102 | // Note that `serde` isn't actually updated here! The default behavior for | |
103 | // `update` right now is to as conservatively as possible attempt to satisfy | |
104 | // an update. In this case we previously locked the dependency graph to `log | |
105 | // 0.1.0`, but nothing on the command line says we're allowed to update | |
106 | // that. As a result the update of `serde` here shouldn't update to `serde | |
107 | // 0.1.1` as that would also force an update to `log 0.1.1`. | |
108 | // | |
109 | // Also note that this is probably counterintuitive and weird. We may wish | |
110 | // to change this one day. | |
85984a87 DW |
111 | p.cargo("update -p serde") |
112 | .with_stderr( | |
51d23560 | 113 | "\ |
41aa6fba | 114 | [UPDATING] `[..]` index |
51d23560 | 115 | ", |
fecb7246 AC |
116 | ) |
117 | .run(); | |
51d23560 AC |
118 | } |
119 | ||
120 | #[test] | |
121 | fn conservative() { | |
122 | Package::new("log", "0.1.0").publish(); | |
123 | Package::new("serde", "0.1.0").dep("log", "0.1").publish(); | |
124 | ||
7fe2fbc8 | 125 | let p = project() |
51d23560 AC |
126 | .file( |
127 | "Cargo.toml", | |
128 | r#" | |
129 | [package] | |
130 | name = "bar" | |
131 | version = "0.0.1" | |
132 | authors = [] | |
133 | ||
134 | [dependencies] | |
135 | serde = "0.1" | |
136 | log = "0.1" | |
137 | foo = { path = "foo" } | |
138 | "#, | |
fecb7246 AC |
139 | ) |
140 | .file("src/lib.rs", "") | |
51d23560 AC |
141 | .file( |
142 | "foo/Cargo.toml", | |
143 | r#" | |
144 | [package] | |
145 | name = "foo" | |
146 | version = "0.0.1" | |
147 | authors = [] | |
148 | ||
149 | [dependencies] | |
150 | serde = "0.1" | |
151 | "#, | |
fecb7246 AC |
152 | ) |
153 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
154 | .build(); |
155 | ||
85984a87 | 156 | p.cargo("build").run(); |
51d23560 AC |
157 | |
158 | Package::new("log", "0.1.1").publish(); | |
159 | Package::new("serde", "0.1.1").dep("log", "0.1").publish(); | |
160 | ||
85984a87 DW |
161 | p.cargo("update -p serde") |
162 | .with_stderr( | |
51d23560 | 163 | "\ |
41aa6fba | 164 | [UPDATING] `[..]` index |
51d23560 AC |
165 | [UPDATING] serde v0.1.0 -> v0.1.1 |
166 | ", | |
fecb7246 AC |
167 | ) |
168 | .run(); | |
51d23560 AC |
169 | } |
170 | ||
171 | #[test] | |
172 | fn update_via_new_dep() { | |
173 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 174 | let p = project() |
51d23560 AC |
175 | .file( |
176 | "Cargo.toml", | |
177 | r#" | |
178 | [package] | |
179 | name = "bar" | |
180 | version = "0.0.1" | |
181 | authors = [] | |
182 | ||
183 | [dependencies] | |
184 | log = "0.1" | |
185 | # foo = { path = "foo" } | |
186 | "#, | |
fecb7246 AC |
187 | ) |
188 | .file("src/lib.rs", "") | |
51d23560 AC |
189 | .file( |
190 | "foo/Cargo.toml", | |
191 | r#" | |
192 | [package] | |
193 | name = "foo" | |
194 | version = "0.0.1" | |
195 | authors = [] | |
196 | ||
197 | [dependencies] | |
198 | log = "0.1.1" | |
199 | "#, | |
fecb7246 AC |
200 | ) |
201 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
202 | .build(); |
203 | ||
85984a87 | 204 | p.cargo("build").run(); |
51d23560 AC |
205 | Package::new("log", "0.1.1").publish(); |
206 | ||
207 | p.uncomment_root_manifest(); | |
85984a87 | 208 | p.cargo("build").env("RUST_LOG", "cargo=trace").run(); |
51d23560 AC |
209 | } |
210 | ||
211 | #[test] | |
212 | fn update_via_new_member() { | |
213 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 214 | let p = project() |
51d23560 AC |
215 | .file( |
216 | "Cargo.toml", | |
217 | r#" | |
218 | [package] | |
219 | name = "bar" | |
220 | version = "0.0.1" | |
221 | authors = [] | |
222 | ||
223 | [workspace] | |
224 | # members = [ "foo" ] | |
225 | ||
226 | [dependencies] | |
227 | log = "0.1" | |
228 | "#, | |
fecb7246 AC |
229 | ) |
230 | .file("src/lib.rs", "") | |
51d23560 AC |
231 | .file( |
232 | "foo/Cargo.toml", | |
233 | r#" | |
234 | [package] | |
235 | name = "foo" | |
236 | version = "0.0.1" | |
237 | authors = [] | |
238 | ||
239 | [dependencies] | |
240 | log = "0.1.1" | |
241 | "#, | |
fecb7246 AC |
242 | ) |
243 | .file("foo/src/lib.rs", "") | |
51d23560 AC |
244 | .build(); |
245 | ||
85984a87 | 246 | p.cargo("build").run(); |
51d23560 AC |
247 | Package::new("log", "0.1.1").publish(); |
248 | ||
249 | p.uncomment_root_manifest(); | |
85984a87 | 250 | p.cargo("build").run(); |
51d23560 AC |
251 | } |
252 | ||
253 | #[test] | |
254 | fn add_dep_deep_new_requirement() { | |
255 | Package::new("log", "0.1.0").publish(); | |
7fe2fbc8 | 256 | let p = project() |
51d23560 AC |
257 | .file( |
258 | "Cargo.toml", | |
259 | r#" | |
260 | [package] | |
261 | name = "bar" | |
262 | version = "0.0.1" | |
263 | authors = [] | |
264 | ||
265 | [dependencies] | |
266 | log = "0.1" | |
267 | # bar = "0.1" | |
268 | "#, | |
fecb7246 AC |
269 | ) |
270 | .file("src/lib.rs", "") | |
51d23560 AC |
271 | .build(); |
272 | ||
85984a87 | 273 | p.cargo("build").run(); |
51d23560 AC |
274 | |
275 | Package::new("log", "0.1.1").publish(); | |
276 | Package::new("bar", "0.1.0").dep("log", "0.1.1").publish(); | |
277 | ||
278 | p.uncomment_root_manifest(); | |
85984a87 | 279 | p.cargo("build").run(); |
51d23560 AC |
280 | } |
281 | ||
282 | #[test] | |
283 | fn everything_real_deep() { | |
284 | Package::new("log", "0.1.0").publish(); | |
285 | Package::new("foo", "0.1.0").dep("log", "0.1").publish(); | |
7fe2fbc8 | 286 | let p = project() |
51d23560 AC |
287 | .file( |
288 | "Cargo.toml", | |
289 | r#" | |
290 | [package] | |
291 | name = "bar" | |
292 | version = "0.0.1" | |
293 | authors = [] | |
294 | ||
295 | [dependencies] | |
296 | foo = "0.1" | |
297 | # bar = "0.1" | |
298 | "#, | |
fecb7246 AC |
299 | ) |
300 | .file("src/lib.rs", "") | |
51d23560 AC |
301 | .build(); |
302 | ||
85984a87 | 303 | p.cargo("build").run(); |
51d23560 AC |
304 | |
305 | Package::new("log", "0.1.1").publish(); | |
306 | Package::new("bar", "0.1.0").dep("log", "0.1.1").publish(); | |
307 | ||
308 | p.uncomment_root_manifest(); | |
85984a87 | 309 | p.cargo("build").run(); |
51d23560 | 310 | } |
0deaae9e AC |
311 | |
312 | #[test] | |
313 | fn change_package_version() { | |
7fe2fbc8 | 314 | let p = project() |
0deaae9e AC |
315 | .file( |
316 | "Cargo.toml", | |
317 | r#" | |
318 | [package] | |
319 | name = "a-foo" | |
320 | version = "0.2.0-alpha" | |
321 | authors = [] | |
322 | ||
323 | [dependencies] | |
324 | bar = { path = "bar", version = "0.2.0-alpha" } | |
325 | "#, | |
fecb7246 AC |
326 | ) |
327 | .file("src/lib.rs", "") | |
ab19c483 | 328 | .file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0-alpha")) |
0deaae9e AC |
329 | .file("bar/src/lib.rs", "") |
330 | .file( | |
331 | "Cargo.lock", | |
332 | r#" | |
333 | [[package]] | |
334 | name = "foo" | |
335 | version = "0.2.0" | |
336 | dependencies = ["bar 0.2.0"] | |
337 | ||
338 | [[package]] | |
339 | name = "bar" | |
340 | version = "0.2.0" | |
341 | "#, | |
fecb7246 AC |
342 | ) |
343 | .build(); | |
0deaae9e | 344 | |
85984a87 | 345 | p.cargo("build").run(); |
0deaae9e | 346 | } |
1a26e86c | 347 | |
348 | #[test] | |
349 | fn update_precise() { | |
350 | Package::new("log", "0.1.0").publish(); | |
351 | Package::new("serde", "0.1.0").publish(); | |
352 | Package::new("serde", "0.2.1").publish(); | |
353 | ||
7fe2fbc8 | 354 | let p = project() |
1a26e86c | 355 | .file( |
356 | "Cargo.toml", | |
357 | r#" | |
358 | [package] | |
359 | name = "bar" | |
360 | version = "0.0.1" | |
361 | authors = [] | |
362 | ||
363 | [dependencies] | |
364 | serde = "0.2" | |
365 | foo = { path = "foo" } | |
366 | "#, | |
fecb7246 AC |
367 | ) |
368 | .file("src/lib.rs", "") | |
1a26e86c | 369 | .file( |
370 | "foo/Cargo.toml", | |
371 | r#" | |
372 | [package] | |
373 | name = "foo" | |
374 | version = "0.0.1" | |
375 | authors = [] | |
376 | ||
377 | [dependencies] | |
378 | serde = "0.1" | |
379 | "#, | |
fecb7246 AC |
380 | ) |
381 | .file("foo/src/lib.rs", "") | |
1a26e86c | 382 | .build(); |
383 | ||
85984a87 | 384 | p.cargo("build").run(); |
1a26e86c | 385 | |
386 | Package::new("serde", "0.2.0").publish(); | |
387 | ||
85984a87 DW |
388 | p.cargo("update -p serde:0.2.1 --precise 0.2.0") |
389 | .with_stderr( | |
1a26e86c | 390 | "\ |
41aa6fba | 391 | [UPDATING] `[..]` index |
1a26e86c | 392 | [UPDATING] serde v0.2.1 -> v0.2.0 |
393 | ", | |
fecb7246 AC |
394 | ) |
395 | .run(); | |
1a26e86c | 396 | } |
851e20b2 DW |
397 | |
398 | #[test] | |
399 | fn preserve_top_comment() { | |
400 | let p = project().file("src/lib.rs", "").build(); | |
401 | ||
402 | p.cargo("update").run(); | |
403 | ||
1408eecc DW |
404 | let mut lockfile = p.read_file("Cargo.lock"); |
405 | lockfile.insert_str(0, "# @generated\n"); | |
ce40ab87 | 406 | lockfile.insert_str(0, "# some other comment\n"); |
851e20b2 DW |
407 | println!("saving Cargo.lock contents:\n{}", lockfile); |
408 | ||
409 | p.change_file("Cargo.lock", &lockfile); | |
410 | ||
411 | p.cargo("update").run(); | |
412 | ||
1408eecc | 413 | let lockfile2 = p.read_file("Cargo.lock"); |
851e20b2 DW |
414 | println!("loaded Cargo.lock contents:\n{}", lockfile2); |
415 | ||
0cdb7803 | 416 | assert!(lockfile == lockfile2); |
851e20b2 | 417 | } |