Skip to content

Commit 00604fa

Browse files
committed
test(pkgid): Show existing pkgid behavior
1 parent 8dd37c1 commit 00604fa

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

crates/cargo-util-schemas/src/core/package_id_spec.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ mod tests {
437437
},
438438
"foo",
439439
);
440+
err!("foo::bar", ErrorKind::PartialVersion(_));
440441
ok(
441442
"foo:1.2.3",
442443
PackageIdSpec {
@@ -447,6 +448,7 @@ mod tests {
447448
},
448449
"foo@1.2.3",
449450
);
451+
err!("foo::bar:1.2.3", ErrorKind::PartialVersion(_));
450452
ok(
451453
"foo@1.2.3",
452454
PackageIdSpec {
@@ -457,6 +459,7 @@ mod tests {
457459
},
458460
"foo@1.2.3",
459461
);
462+
err!("foo::bar@1.2.3", ErrorKind::PartialVersion(_));
460463
ok(
461464
"foo@1.2",
462465
PackageIdSpec {
@@ -591,6 +594,16 @@ mod tests {
591594
},
592595
"file:///path/to/my/project/foo",
593596
);
597+
ok(
598+
"file:///path/to/my/project/foo::bar",
599+
PackageIdSpec {
600+
name: String::from("foo::bar"),
601+
version: None,
602+
url: Some(Url::parse("file:///path/to/my/project/foo::bar").unwrap()),
603+
kind: None,
604+
},
605+
"file:///path/to/my/project/foo::bar",
606+
);
594607
ok(
595608
"file:///path/to/my/project/foo#1.1.8",
596609
PackageIdSpec {
@@ -611,6 +624,48 @@ mod tests {
611624
},
612625
"path+file:///path/to/my/project/foo#1.1.8",
613626
);
627+
ok(
628+
"path+file:///path/to/my/project/foo#bar",
629+
PackageIdSpec {
630+
name: String::from("bar"),
631+
version: None,
632+
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
633+
kind: Some(SourceKind::Path),
634+
},
635+
"path+file:///path/to/my/project/foo#bar",
636+
);
637+
err!(
638+
"path+file:///path/to/my/project/foo#foo::bar",
639+
ErrorKind::PartialVersion(_)
640+
);
641+
ok(
642+
"path+file:///path/to/my/project/foo#bar:1.1.8",
643+
PackageIdSpec {
644+
name: String::from("bar"),
645+
version: Some("1.1.8".parse().unwrap()),
646+
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
647+
kind: Some(SourceKind::Path),
648+
},
649+
"path+file:///path/to/my/project/foo#bar@1.1.8",
650+
);
651+
err!(
652+
"path+file:///path/to/my/project/foo#foo::bar:1.1.8",
653+
ErrorKind::PartialVersion(_)
654+
);
655+
ok(
656+
"path+file:///path/to/my/project/foo#bar@1.1.8",
657+
PackageIdSpec {
658+
name: String::from("bar"),
659+
version: Some("1.1.8".parse().unwrap()),
660+
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
661+
kind: Some(SourceKind::Path),
662+
},
663+
"path+file:///path/to/my/project/foo#bar@1.1.8",
664+
);
665+
err!(
666+
"path+file:///path/to/my/project/foo#foo::bar@1.1.8",
667+
ErrorKind::PartialVersion(_)
668+
);
614669
}
615670

616671
#[test]

tests/testsuite/open_namespaces.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,106 @@ fn main() {}
327327
.run();
328328
}
329329

330+
#[cargo_test]
331+
fn generate_pkgid_with_namespace() {
332+
let p = project()
333+
.file(
334+
"Cargo.toml",
335+
r#"
336+
cargo-features = ["open-namespaces"]
337+
338+
[package]
339+
name = "foo::bar"
340+
version = "0.0.1"
341+
edition = "2015"
342+
"#,
343+
)
344+
.file("src/lib.rs", "")
345+
.build();
346+
347+
p.cargo("generate-lockfile")
348+
.masquerade_as_nightly_cargo(&["open-namespaces"])
349+
.run();
350+
p.cargo("pkgid")
351+
.masquerade_as_nightly_cargo(&["open-namespaces"])
352+
.with_stdout_data(str![[r#"
353+
path+[ROOTURL]/foo#foo::bar@0.0.1
354+
355+
"#]])
356+
.with_stderr_data("")
357+
.run()
358+
}
359+
360+
#[cargo_test]
361+
fn update_spec_accepts_namespaced_name() {
362+
let p = project()
363+
.file(
364+
"Cargo.toml",
365+
r#"
366+
cargo-features = ["open-namespaces"]
367+
368+
[package]
369+
name = "foo::bar"
370+
version = "0.0.1"
371+
edition = "2015"
372+
"#,
373+
)
374+
.file("src/lib.rs", "")
375+
.build();
376+
377+
p.cargo("generate-lockfile")
378+
.masquerade_as_nightly_cargo(&["open-namespaces"])
379+
.run();
380+
p.cargo("update foo::bar")
381+
.masquerade_as_nightly_cargo(&["open-namespaces"])
382+
.with_status(101)
383+
.with_stdout_data(str![""])
384+
.with_stderr_data(str![[r#"
385+
[ERROR] invalid package ID specification: `foo::bar`
386+
387+
Did you mean `foo::bar`?
388+
389+
Caused by:
390+
expected a version like "1.32"
391+
392+
"#]])
393+
.run()
394+
}
395+
396+
#[cargo_test]
397+
fn update_spec_accepts_namespaced_pkgid() {
398+
let p = project()
399+
.file(
400+
"Cargo.toml",
401+
r#"
402+
cargo-features = ["open-namespaces"]
403+
404+
[package]
405+
name = "foo::bar"
406+
version = "0.0.1"
407+
edition = "2015"
408+
"#,
409+
)
410+
.file("src/lib.rs", "")
411+
.build();
412+
413+
p.cargo("generate-lockfile")
414+
.masquerade_as_nightly_cargo(&["open-namespaces"])
415+
.run();
416+
p.cargo(&format!("update path+{}#foo::bar@0.0.1", p.url()))
417+
.masquerade_as_nightly_cargo(&["open-namespaces"])
418+
.with_status(101)
419+
.with_stdout_data(str![""])
420+
.with_stderr_data(str![[r#"
421+
[ERROR] invalid package ID specification: `path+[ROOTURL]/foo#foo::bar@0.0.1`
422+
423+
Caused by:
424+
expected a version like "1.32"
425+
426+
"#]])
427+
.run()
428+
}
429+
330430
#[cargo_test]
331431
#[cfg(unix)] // until we get proper packaging support
332432
fn publish_namespaced() {

0 commit comments

Comments
 (0)