Skip to content

Commit

Permalink
test(clean): Verify spec version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 7, 2023
1 parent 305bfd6 commit ad149fd
Showing 1 changed file with 99 additions and 7 deletions.
106 changes: 99 additions & 7 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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", "")
Expand All @@ -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();
Expand All @@ -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
<tab>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
<tab>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,
Expand Down

0 comments on commit ad149fd

Please sign in to comment.