test: show pkgid spec + query doesnt work with --package

This commit is contained in:
Weihang Lo 2024-01-18 00:27:56 -05:00
parent 1ae631085f
commit a37d122949
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -3,6 +3,7 @@
use std::fmt::{self, Write};
use crate::messages::raw_rustc_output;
use cargo_test_support::compare;
use cargo_test_support::install::exe;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
@ -1519,3 +1520,40 @@ fn versionless_package() {
)
.run();
}
#[cargo_test]
fn pkgid_querystring_works() {
let git_project = git::new("gitdep", |p| {
p.file("Cargo.toml", &basic_manifest("gitdep", "1.0.0"))
.file("src/lib.rs", "")
});
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
[dependencies]
gitdep = {{ git = "{}", branch = "master" }}
"#,
git_project.url()
),
)
.file("src/lib.rs", "")
.build();
p.cargo("generate-lockfile").run();
let output = p.cargo("pkgid").arg("gitdep").exec_with_output().unwrap();
let gitdep_pkgid = String::from_utf8(output.stdout).unwrap();
let gitdep_pkgid = gitdep_pkgid.trim();
compare::assert_match_exact("git+file://[..]/gitdep?branch=master#1.0.0", &gitdep_pkgid);
p.cargo("build -p")
.arg(gitdep_pkgid)
.with_status(101)
.with_stderr("[ERROR] package pattern(s) `git+file:///[..]/gitdep?branch=master#1.0.0` not found in workspace `[CWD]`")
.run();
}