Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/bin/set-version/set_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ fn exec(args: VersionArgs) -> CargoResult<()> {
let root_manifest_path = ws_metadata.workspace_root.as_std_path().join("Cargo.toml");
let workspace_members = find_ws_members(&ws_metadata);

let mut missing = Vec::new();
for name in &pkgid {
let name = name.as_str();
if !workspace_members
.iter()
.any(|package| package.name.as_str() == name)
&& !missing.contains(&name)
{
missing.push(name);
}
}
match missing.len() {
0 => {}
1 => anyhow::bail!("package {} doesn't exist", missing.join(", ")),
_ => anyhow::bail!("packages {} don't exist", missing.join(", ")),
}

if all {
shell_warn("The flag `--all` has been deprecated in favor of `--workspace`")?;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/cargo-set-version/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
mod downgrade_error;
mod dry_run;
mod ignore_dependent;
mod package_not_found;
mod package_not_found_mixed;
mod package_not_found_repeated;
mod packages_not_found;
mod relative_absolute_conflict;
mod set_absolute_version;
mod set_absolute_workspace_version;
Expand Down
9 changes: 9 additions & 0 deletions tests/cargo-set-version/package_not_found/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
24 changes: 24 additions & 0 deletions tests/cargo-set-version/package_not_found/mod.rs
Comment thread
ychampion marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use cargo_test_support::Project;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;

use crate::CargoCommand;

#[cargo_test]
fn case() {
let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();

snapbox::cmd::Command::cargo_ui()
.arg("set-version")
.args(["2.0.0", "--package", "missing"])
.current_dir(&project_root)
.assert()
.code(1)
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
9 changes: 9 additions & 0 deletions tests/cargo-set-version/package_not_found/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
25 changes: 25 additions & 0 deletions tests/cargo-set-version/package_not_found/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tests/cargo-set-version/package_not_found/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/cargo-set-version/package_not_found_mixed/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
24 changes: 24 additions & 0 deletions tests/cargo-set-version/package_not_found_mixed/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use cargo_test_support::Project;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;

use crate::CargoCommand;

#[cargo_test]
fn case() {
let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();

snapbox::cmd::Command::cargo_ui()
.arg("set-version")
.args(["2.0.0", "--package", "sample", "--package", "missing"])
.current_dir(&project_root)
.assert()
.code(1)
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
25 changes: 25 additions & 0 deletions tests/cargo-set-version/package_not_found_mixed/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tests/cargo-set-version/package_not_found_mixed/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
24 changes: 24 additions & 0 deletions tests/cargo-set-version/package_not_found_repeated/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use cargo_test_support::Project;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;

use crate::CargoCommand;

#[cargo_test]
fn case() {
let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();

snapbox::cmd::Command::cargo_ui()
.arg("set-version")
.args(["2.0.0", "-p", "missing", "-p", "missing"])
.current_dir(&project_root)
.assert()
.code(1)
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
25 changes: 25 additions & 0 deletions tests/cargo-set-version/package_not_found_repeated/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tests/cargo-set-version/package_not_found_repeated/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/cargo-set-version/packages_not_found/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
30 changes: 30 additions & 0 deletions tests/cargo-set-version/packages_not_found/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use cargo_test_support::Project;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;

use crate::CargoCommand;

#[cargo_test]
fn case() {
let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();

snapbox::cmd::Command::cargo_ui()
.arg("set-version")
.args([
"2.0.0",
"--package",
"first-missing",
"--package",
"second-missing",
])
.current_dir(&project_root)
.assert()
.code(1)
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
9 changes: 9 additions & 0 deletions tests/cargo-set-version/packages_not_found/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "sample"
version = "0.1.0"
edition = "2015"

[lib]
path = "dummy.rs"
25 changes: 25 additions & 0 deletions tests/cargo-set-version/packages_not_found/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading