-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Improved error message for versions prefixed with v
#15484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
681597f
test(install): Added test case for prefixed `v` in version
Pyr0de 7e09951
install: Added error message for when `v` is prefixed with version
Pyr0de ac86dea
test(add): Added test case for prefixed `v` in version
Pyr0de 9ae361a
add: Added error message for when `v` is prefixed with version
Pyr0de cd27a11
test(yank): Added test cases for bad version & prefixed `v` in version
Pyr0de d07439b
yank: Check for bad version & added error message for prefixed `v` in…
Pyr0de ef3e28d
test(update): Added test for prefixed `v` in version
Pyr0de 2ba61b9
update: Added error message for when `v` is prefixed with version
Pyr0de File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../add-basic.in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use cargo_test_support::compare::assert_ui; | ||
use cargo_test_support::current_dir; | ||
use cargo_test_support::file; | ||
use cargo_test_support::prelude::*; | ||
use cargo_test_support::str; | ||
use cargo_test_support::Project; | ||
|
||
#[cargo_test] | ||
fn case() { | ||
cargo_test_support::registry::init(); | ||
|
||
let project = Project::from_template(current_dir!().join("in")); | ||
let project_root = project.root(); | ||
let cwd = &project_root; | ||
|
||
snapbox::cmd::Command::cargo_ui() | ||
.arg("add") | ||
.arg_line("[email protected]") | ||
.current_dir(cwd) | ||
.assert() | ||
.code(101) | ||
.stdout_eq(str![""]) | ||
.stderr_eq(file!["stderr.term.svg"]); | ||
|
||
assert_ui().subset_matches(current_dir!().join("out"), &project_root); | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/testsuite/cargo_add/prefixed_v_in_version/out/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "cargo-list-test-fixture" | ||
version = "0.0.0" | ||
edition = "2015" |
37 changes: 37 additions & 0 deletions
37
tests/testsuite/cargo_add/prefixed_v_in_version/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2899,3 +2899,19 @@ fn dry_run_remove_orphan() { | |
// Ensure server is still installed after the dry run | ||
assert_has_installed_exe(paths::cargo_home(), "server"); | ||
} | ||
|
||
#[cargo_test] | ||
fn prefixed_v_in_version() { | ||
pkg("foo", "0.0.1"); | ||
cargo_process("install [email protected]") | ||
.with_status(1) | ||
.with_stderr_data(str![[r#" | ||
[ERROR] invalid value '[email protected]' for '[CRATE[@<VER>]]...': the version provided, `v0.0.1` is not a valid SemVer requirement | ||
|
||
[HELP] try changing the version to `0.0.1` | ||
|
||
For more information, try '--help'. | ||
|
||
"#]]) | ||
.run(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,3 +212,71 @@ fn inline_and_explicit_version() { | |
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn bad_version() { | ||
let registry = registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
license = "MIT" | ||
description = "foo" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
p.cargo("yank foo@bar") | ||
.replace_crates_io(registry.index_url()) | ||
.with_status(101) | ||
.with_stderr_data(str![[r#" | ||
[ERROR] invalid version `bar` | ||
|
||
Caused by: | ||
unexpected character 'b' while parsing major version number | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn prefixed_v_in_version() { | ||
let registry = registry::init(); | ||
setup("foo", "0.0.1"); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
authors = [] | ||
license = "MIT" | ||
description = "foo" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.build(); | ||
|
||
p.cargo("yank [email protected]") | ||
.replace_crates_io(registry.index_url()) | ||
.with_status(101) | ||
.with_stderr_data(str![[r#" | ||
[ERROR] the version provided, `v0.0.1` is not a valid SemVer version | ||
|
||
[HELP] try changing the version to `0.0.1` | ||
|
||
Caused by: | ||
unexpected character 'v' while parsing major version number | ||
|
||
"#]]) | ||
.run(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks nice.
Would you mind following the atomic commit pattern the contributor guide suggests? Which we add a new test first than captures the current behavior, followed by the next commit containing both the fix and test change. That makes the behavior change more prominent.