|
3 | 3 | use std::fs; |
4 | 4 |
|
5 | 5 | use crate::prelude::*; |
| 6 | +use cargo_test_support::compare::assert_e2e; |
6 | 7 | use cargo_test_support::registry::{Package, RegistryBuilder}; |
7 | 8 | use cargo_test_support::{ProjectBuilder, basic_manifest, paths, project, str}; |
8 | 9 |
|
@@ -284,3 +285,126 @@ fn generate_lockfile_holds_lock_and_offline() { |
284 | 285 | "#]]) |
285 | 286 | .run(); |
286 | 287 | } |
| 288 | + |
| 289 | +#[cargo_test] |
| 290 | +fn publish_time() { |
| 291 | + Package::new("has_time", "2025.1.1") |
| 292 | + .pubtime("2025-01-01T06:00:00Z") |
| 293 | + .publish(); |
| 294 | + Package::new("has_time", "2025.6.1") |
| 295 | + .pubtime("2025-06-01T06:00:00Z") |
| 296 | + .publish(); |
| 297 | + Package::new("no_time", "2025.1.1") |
| 298 | + .pubtime("2025-01-01T06:00:00Z") |
| 299 | + .publish(); |
| 300 | + Package::new("no_time", "2025.6.1") |
| 301 | + .pubtime("2025-06-01T06:00:00Z") |
| 302 | + .publish(); |
| 303 | + |
| 304 | + let p = project() |
| 305 | + .file( |
| 306 | + "Cargo.toml", |
| 307 | + r#" |
| 308 | + [package] |
| 309 | + name = "foo" |
| 310 | +
|
| 311 | + [dependencies] |
| 312 | + has_time = "2025.0" |
| 313 | + no_time = "2025.0" |
| 314 | + "#, |
| 315 | + ) |
| 316 | + .file("src/lib.rs", "") |
| 317 | + .build(); |
| 318 | + |
| 319 | + p.cargo("generate-lockfile") |
| 320 | + .with_stderr_data(str![[r#" |
| 321 | +[UPDATING] `dummy-registry` index |
| 322 | +[LOCKING] 2 packages to latest compatible versions |
| 323 | +
|
| 324 | +"#]]) |
| 325 | + .run(); |
| 326 | + |
| 327 | + let lock = p.read_lockfile(); |
| 328 | + assert_e2e().eq( |
| 329 | + lock, |
| 330 | + str![[r##" |
| 331 | +# This file is automatically @generated by Cargo. |
| 332 | +# It is not intended for manual editing. |
| 333 | +version = 4 |
| 334 | +
|
| 335 | +[[package]] |
| 336 | +name = "foo" |
| 337 | +version = "0.0.0" |
| 338 | +dependencies = [ |
| 339 | + "has_time", |
| 340 | + "no_time", |
| 341 | +] |
| 342 | +
|
| 343 | +[[package]] |
| 344 | +name = "has_time" |
| 345 | +version = "2025.6.1" |
| 346 | +source = "registry+https://github.com/rust-lang/crates.io-index" |
| 347 | +checksum = "ac0b8bfb45ec1b58be8fecc5d9a59ed4e13bb9ed9b656220198ec1d31da30e4b" |
| 348 | +
|
| 349 | +[[package]] |
| 350 | +name = "no_time" |
| 351 | +version = "2025.6.1" |
| 352 | +source = "registry+https://github.com/rust-lang/crates.io-index" |
| 353 | +checksum = "01e688c07975f1e85f526c033322273181a4d8fe97800543d813d0a0adc134e3" |
| 354 | +
|
| 355 | +"##]], |
| 356 | + ); |
| 357 | +} |
| 358 | + |
| 359 | +#[cargo_test] |
| 360 | +fn publish_time_no_candidates() { |
| 361 | + Package::new("has_time", "2025.6.1") |
| 362 | + .pubtime("2025-06-01T06:00:00Z") |
| 363 | + .publish(); |
| 364 | + |
| 365 | + let p = project() |
| 366 | + .file( |
| 367 | + "Cargo.toml", |
| 368 | + r#" |
| 369 | + [package] |
| 370 | + name = "foo" |
| 371 | +
|
| 372 | + [dependencies] |
| 373 | + has_time = "2025.0" |
| 374 | + "#, |
| 375 | + ) |
| 376 | + .file("src/lib.rs", "") |
| 377 | + .build(); |
| 378 | + |
| 379 | + p.cargo("generate-lockfile") |
| 380 | + .with_stderr_data(str![[r#" |
| 381 | +[UPDATING] `dummy-registry` index |
| 382 | +[LOCKING] 1 package to latest compatible version |
| 383 | +
|
| 384 | +"#]]) |
| 385 | + .run(); |
| 386 | + |
| 387 | + let lock = p.read_lockfile(); |
| 388 | + assert_e2e().eq( |
| 389 | + lock, |
| 390 | + str![[r##" |
| 391 | +# This file is automatically @generated by Cargo. |
| 392 | +# It is not intended for manual editing. |
| 393 | +version = 4 |
| 394 | +
|
| 395 | +[[package]] |
| 396 | +name = "foo" |
| 397 | +version = "0.0.0" |
| 398 | +dependencies = [ |
| 399 | + "has_time", |
| 400 | +] |
| 401 | +
|
| 402 | +[[package]] |
| 403 | +name = "has_time" |
| 404 | +version = "2025.6.1" |
| 405 | +source = "registry+https://github.com/rust-lang/crates.io-index" |
| 406 | +checksum = "ac0b8bfb45ec1b58be8fecc5d9a59ed4e13bb9ed9b656220198ec1d31da30e4b" |
| 407 | +
|
| 408 | +"##]], |
| 409 | + ); |
| 410 | +} |
0 commit comments