Skip to content

Commit b05373d

Browse files
committed
test: add extra test for package command
1 parent 1abaa88 commit b05373d

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

tests/testsuite/lockfile_path.rs

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ use std::fs;
44

55
use snapbox::str;
66

7-
use cargo_test_support::paths::CargoPathExt;
87
use cargo_test_support::registry::RegistryBuilder;
98
use cargo_test_support::{
10-
basic_bin_manifest, basic_lib_manifest, cargo_test, paths, project, symlink_supported, Execs,
11-
Project, ProjectBuilder,
9+
basic_bin_manifest, cargo_test, project, symlink_supported, Execs,
10+
ProjectBuilder,
1211
};
1312

1413
const VALID_LOCKFILE: &str = r#"# Test lockfile
@@ -41,7 +40,7 @@ fn make_basic_command(execs: &mut Execs, lockfile_path_argument: String) -> &mut
4140
}
4241

4342
fn lockfile_must_exist(command: &str) -> bool {
44-
return command == "pkgid" || command == "publish";
43+
return command == "pkgid" || command == "publish" || command == "package";
4544
}
4645

4746
fn assert_lockfile_created(
@@ -332,7 +331,7 @@ tests!(fetch, "fetch");
332331
tests!(fix, "fix", make_fix_command, make_basic_project);
333332
tests!(generate_lockfile, "generate-lockfile");
334333
tests!(metadata, "metadata");
335-
// tests!(package, "package"); // TODO: check why lockfile is not generated
334+
tests!(package, "package");
336335
tests!(pkgid, "pkgid");
337336
tests!(publish, "publish");
338337
tests!(remove, "remove", make_remove_command, make_remove_project);
@@ -343,3 +342,65 @@ tests!(test, "test");
343342
tests!(tree, "tree");
344343
tests!(update, "update");
345344
tests!(vendor, "vendor");
345+
346+
#[cfg(test)]
347+
mod package_extra {
348+
use std::fs;
349+
use cargo_test_support::{cargo_test, project};
350+
use crate::lockfile_path::{make_basic_command};
351+
352+
#[cargo_test(nightly, reason = "--lockfile-path is unstable")]
353+
fn assert_respect_pinned_version_from_lockfile_path() {
354+
const PINNED_VERSION: &str = r#"# This file is automatically @generated by Cargo.
355+
# It is not intended for manual editing.
356+
version = 3
357+
358+
[[package]]
359+
name = "hello"
360+
version = "1.0.2"
361+
source = "registry+https://github.com/rust-lang/crates.io-index"
362+
checksum = "2b94f16c310ebbd9efcca5a5a17131d70bd454876f2af007f3da211afadff4fc"
363+
364+
[[package]]
365+
name = "test_foo"
366+
version = "0.5.0"
367+
dependencies = [
368+
"hello",
369+
]
370+
"#;
371+
const TOML: &str = r#"#
372+
[package]
373+
374+
name = "test_foo"
375+
version = "0.5.0"
376+
authors = ["[email protected]"]
377+
edition = "2015"
378+
379+
[[bin]]
380+
381+
name = "test_foo"
382+
383+
[dependencies]
384+
hello = "1.0.0"
385+
"#;
386+
387+
let lockfile_path_argument = "mylockfile/Cargo.lock";
388+
let p = project()
389+
.file("Cargo.toml", TOML)
390+
.file("src/main.rs", "fn main() {}")
391+
.file("mylockfile/Cargo.lock", PINNED_VERSION)
392+
.build();
393+
394+
make_basic_command(&mut p.cargo("package"), lockfile_path_argument.to_string()).run();
395+
396+
assert!(!p.root().join("Cargo.lock").is_file());
397+
assert!(p.root().join(lockfile_path_argument).is_file());
398+
399+
assert!(p.root().join("target/package/test_foo-0.5.0/Cargo.lock").is_file());
400+
401+
let path = p.root().join("target/package/test_foo-0.5.0/Cargo.lock");
402+
let contents = fs::read_to_string(path).unwrap();
403+
404+
assert_eq!(contents, PINNED_VERSION);
405+
}
406+
}

0 commit comments

Comments
 (0)