Skip to content

Commit e7ca585

Browse files
committed
test(pkgid): Demonstrate ambiguos specs
1 parent a5fa676 commit e7ca585

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

tests/testsuite/pkgid.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tests for the `cargo pkgid` command.
22
3+
use cargo_test_support::basic_lib_manifest;
4+
use cargo_test_support::git;
35
use cargo_test_support::project;
46
use cargo_test_support::registry::Package;
57

@@ -195,3 +197,88 @@ Did you mean one of these?
195197
)
196198
.run();
197199
}
200+
201+
// Not for `cargo pkgid` but the `PackageIdSpec` format
202+
#[cargo_test]
203+
fn multiple_git_same_version() {
204+
// Test what happens if different packages refer to the same git repo with
205+
// different refs, and the package version is the same.
206+
let (xyz_project, xyz_repo) = git::new_repo("xyz", |project| {
207+
project
208+
.file("Cargo.toml", &basic_lib_manifest("xyz"))
209+
.file("src/lib.rs", "fn example() {}")
210+
});
211+
let rev1 = xyz_repo.revparse_single("HEAD").unwrap().id();
212+
xyz_project.change_file("src/lib.rs", "pub fn example() {}");
213+
git::add(&xyz_repo);
214+
let rev2 = git::commit(&xyz_repo);
215+
// Both rev1 and rev2 point to version 0.1.0.
216+
217+
let p = project()
218+
.file(
219+
"Cargo.toml",
220+
&format!(
221+
r#"
222+
[package]
223+
name = "foo"
224+
version = "0.1.0"
225+
226+
[dependencies]
227+
bar = {{ path = "bar" }}
228+
xyz = {{ git = "{}", rev = "{}" }}
229+
230+
"#,
231+
xyz_project.url(),
232+
rev1
233+
),
234+
)
235+
.file("src/lib.rs", "")
236+
.file(
237+
"bar/Cargo.toml",
238+
&format!(
239+
r#"
240+
[package]
241+
name = "bar"
242+
version = "0.1.0"
243+
244+
[dependencies]
245+
xyz = {{ git = "{}", rev = "{}" }}
246+
"#,
247+
xyz_project.url(),
248+
rev2
249+
),
250+
)
251+
.file("bar/src/lib.rs", "")
252+
.build();
253+
254+
p.cargo("check").run();
255+
p.cargo("tree")
256+
.with_stdout(&format!(
257+
"\
258+
foo v0.1.0 ([..]/foo)
259+
├── bar v0.1.0 ([..]/foo/bar)
260+
│ └── xyz v0.5.0 (file://[..]/xyz?rev={}#{})
261+
└── xyz v0.5.0 (file://[..]/xyz?rev={}#{})
262+
",
263+
rev2,
264+
&rev2.to_string()[..8],
265+
rev1,
266+
&rev1.to_string()[..8]
267+
))
268+
.run();
269+
// FIXME: This fails since xyz is ambiguous, but the
270+
// possible pkgids are also ambiguous.
271+
p.cargo("pkgid xyz")
272+
.with_status(101)
273+
.with_stderr(
274+
"\
275+
error: There are multiple `xyz` packages in your project, and the specification `xyz` is ambiguous.
276+
Please re-run this command with one of the following specifications:
277+
file://[..]/xyz#0.5.0
278+
file://[..]/xyz#0.5.0
279+
",
280+
)
281+
.run();
282+
// TODO, what should the `-p` value be here?
283+
//p.cargo("update -p")
284+
}

0 commit comments

Comments
 (0)