diff --git a/tests/testsuite/clean.rs b/tests/testsuite/clean.rs index 65f6cf476166..bf2df9cc60ef 100644 --- a/tests/testsuite/clean.rs +++ b/tests/testsuite/clean.rs @@ -569,10 +569,10 @@ fn assert_all_clean(build_dir: &Path) { } #[cargo_test] -fn clean_spec_multiple() { +fn clean_spec_version() { // clean -p foo where foo matches multiple versions - Package::new("bar", "1.0.0").publish(); - Package::new("bar", "2.0.0").publish(); + Package::new("bar", "0.1.0").publish(); + Package::new("bar", "0.2.0").publish(); let p = project() .file( @@ -583,8 +583,8 @@ fn clean_spec_multiple() { version = "0.1.0" [dependencies] - bar1 = {version="1.0", package="bar"} - bar2 = {version="2.0", package="bar"} + bar1 = {version="0.1", package="bar"} + bar2 = {version="0.2", package="bar"} "#, ) .file("src/lib.rs", "") @@ -604,9 +604,9 @@ error: package ID specification `baz` did not match any packages ) .run(); - p.cargo("clean -p bar:1.0.0") + p.cargo("clean -p bar:0.1.0") .with_stderr( - "warning: version qualifier in `-p bar:1.0.0` is ignored, \ + "warning: version qualifier in `-p bar:0.1.0` is ignored, \ cleaning all versions of `bar` found", ) .run(); @@ -622,6 +622,98 @@ error: package ID specification `baz` did not match any packages } } +#[cargo_test] +fn clean_spec_partial_version() { + // clean -p foo where foo matches multiple versions + Package::new("bar", "0.1.0").publish(); + Package::new("bar", "0.2.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + bar1 = {version="0.1", package="bar"} + bar2 = {version="0.2", package="bar"} + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build").run(); + + // Check suggestion for bad pkgid. + p.cargo("clean -p baz") + .with_status(101) + .with_stderr( + "\ +error: package ID specification `baz` did not match any packages + +Did you mean `bar`? +", + ) + .run(); + + p.cargo("clean -p bar:0.1") + .with_status(101) + .with_stderr( + "\ +error: cannot parse '0.1' as a SemVer version +", + ) + .run(); +} + +#[cargo_test] +fn clean_spec_partial_version_ambiguous() { + // clean -p foo where foo matches multiple versions + Package::new("bar", "0.1.0").publish(); + Package::new("bar", "0.2.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + bar1 = {version="0.1", package="bar"} + bar2 = {version="0.2", package="bar"} + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build").run(); + + // Check suggestion for bad pkgid. + p.cargo("clean -p baz") + .with_status(101) + .with_stderr( + "\ +error: package ID specification `baz` did not match any packages + +Did you mean `bar`? +", + ) + .run(); + + p.cargo("clean -p bar:0") + .with_status(101) + .with_stderr( + "\ +error: cannot parse '0' as a SemVer version +", + ) + .run(); +} + #[cargo_test] fn clean_spec_reserved() { // Clean when a target (like a test) has a reserved name. In this case,