Skip to content

Commit

Permalink
test: migrate generate_lockfile to snapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
eth3lbert committed Jul 6, 2024
1 parent a495ed8 commit abe43b7
Showing 1 changed file with 41 additions and 34 deletions.
75 changes: 41 additions & 34 deletions tests/testsuite/generate_lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Tests for the `cargo generate-lockfile` command.

#![allow(deprecated)]

use cargo_test_support::registry::{Package, RegistryBuilder};
use cargo_test_support::{basic_manifest, paths, project, ProjectBuilder};
use cargo_test_support::{basic_manifest, paths, project, str, ProjectBuilder};
use snapbox::IntoData;
use std::fs;

#[cargo_test]
Expand Down Expand Up @@ -61,15 +60,35 @@ fn adding_and_removing_packages() {
#[cargo_test]
fn no_index_update_sparse() {
let _registry = RegistryBuilder::new().http_index().build();
no_index_update();
no_index_update(
str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
"#]],
str![[r#"
[LOCKING] 2 packages to latest compatible versions
"#]],
);
}

#[cargo_test]
fn no_index_update_git() {
no_index_update();
no_index_update(
str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
"#]],
str![[r#"
[LOCKING] 2 packages to latest compatible versions
"#]],
);
}

fn no_index_update() {
fn no_index_update(expected: impl IntoData, expected_unstable_option: impl IntoData) {
Package::new("serde", "1.0.0").publish();

let p = project()
Expand All @@ -89,22 +108,13 @@ fn no_index_update() {
.build();

p.cargo("generate-lockfile")
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
",
)
.with_stderr_data(expected)
.run();

p.cargo("generate-lockfile -Zno-index-update")
.masquerade_as_nightly_cargo(&["no-index-update"])
.with_stdout("")
.with_stderr(
"\
[LOCKING] 2 packages to latest compatible versions
",
)
.with_stdout_data("")
.with_stderr_data(expected_unstable_option)
.run();
}

Expand Down Expand Up @@ -172,13 +182,13 @@ fn cargo_update_generate_lockfile() {

let lockfile = p.root().join("Cargo.lock");
assert!(!lockfile.is_file());
p.cargo("update").with_stderr("").run();
p.cargo("update").with_stderr_data("").run();
assert!(lockfile.is_file());

fs::remove_file(p.root().join("Cargo.lock")).unwrap();

assert!(!lockfile.is_file());
p.cargo("update").with_stderr("").run();
p.cargo("update").with_stderr_data("").run();
assert!(lockfile.is_file());
}

Expand Down Expand Up @@ -233,11 +243,10 @@ fn duplicate_entries_in_lockfile() {
// should fail due to a duplicate package `common` in the lock file
b.cargo("build")
.with_status(101)
.with_stderr_contains(
"[..]package collision in the lockfile: packages common [..] and \
common [..] are different, but only one can be written to \
lockfile unambiguously",
)
.with_stderr_data(str![[r#"
[ERROR] package collision in the lockfile: packages common v0.0.1 ([ROOT]/a/common) and common v0.0.1 ([ROOT]/b/common) are different, but only one can be written to lockfile unambiguously
"#]])
.run();
}

Expand All @@ -260,19 +269,17 @@ fn generate_lockfile_holds_lock_and_offline() {
.build();

p.cargo("generate-lockfile")
.with_stderr(
"\
[UPDATING] `[..]` index
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
",
)
"#]])
.run();

p.cargo("generate-lockfile --offline")
.with_stderr_contains(
"\
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
",
)
"#]])
.run();
}

0 comments on commit abe43b7

Please sign in to comment.