mirror of
https://github.com/rust-lang/cargo
synced 2024-08-27 19:29:21 +00:00
test: assert error kind for pkgidspec parsing
This commit is contained in:
parent
48eca1b164
commit
99b4a49530
|
@ -318,6 +318,7 @@ enum ErrorKind {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use super::ErrorKind;
|
||||||
use super::PackageIdSpec;
|
use super::PackageIdSpec;
|
||||||
use crate::core::{GitReference, SourceKind};
|
use crate::core::{GitReference, SourceKind};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -602,31 +603,53 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bad_parsing() {
|
fn bad_parsing() {
|
||||||
assert!(PackageIdSpec::parse("baz:").is_err());
|
macro_rules! err {
|
||||||
assert!(PackageIdSpec::parse("baz:*").is_err());
|
($spec:expr, $expected:pat) => {
|
||||||
assert!(PackageIdSpec::parse("baz@").is_err());
|
let err = PackageIdSpec::parse($spec).unwrap_err();
|
||||||
assert!(PackageIdSpec::parse("baz@*").is_err());
|
let kind = err.0;
|
||||||
assert!(PackageIdSpec::parse("baz@^1.0").is_err());
|
assert!(
|
||||||
assert!(PackageIdSpec::parse("https://baz:1.0").is_err());
|
matches!(kind, $expected),
|
||||||
assert!(PackageIdSpec::parse("https://#baz:1.0").is_err());
|
"`{}` parse error mismatch, got {kind:?}",
|
||||||
assert!(
|
$spec
|
||||||
PackageIdSpec::parse("foobar+https://github.com/rust-lang/crates.io-index").is_err()
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
err!("baz:", ErrorKind::PartialVersion(_));
|
||||||
|
err!("baz:*", ErrorKind::PartialVersion(_));
|
||||||
|
err!("baz@", ErrorKind::PartialVersion(_));
|
||||||
|
err!("baz@*", ErrorKind::PartialVersion(_));
|
||||||
|
err!("baz@^1.0", ErrorKind::PartialVersion(_));
|
||||||
|
err!("https://baz:1.0", ErrorKind::PartialVersion(_));
|
||||||
|
err!("https://#baz:1.0", ErrorKind::PartialVersion(_));
|
||||||
|
err!(
|
||||||
|
"foobar+https://github.com/rust-lang/crates.io-index",
|
||||||
|
ErrorKind::UnsupportedProtocol(_)
|
||||||
|
);
|
||||||
|
err!(
|
||||||
|
"path+https://github.com/rust-lang/crates.io-index",
|
||||||
|
ErrorKind::UnsupportedPathPlusScheme(_)
|
||||||
);
|
);
|
||||||
assert!(PackageIdSpec::parse("path+https://github.com/rust-lang/crates.io-index").is_err());
|
|
||||||
|
|
||||||
// Only `git+` can use `?`
|
// Only `git+` can use `?`
|
||||||
assert!(PackageIdSpec::parse("file:///path/to/my/project/foo?branch=dev").is_err());
|
err!(
|
||||||
assert!(PackageIdSpec::parse("path+file:///path/to/my/project/foo?branch=dev").is_err());
|
"file:///path/to/my/project/foo?branch=dev",
|
||||||
assert!(PackageIdSpec::parse(
|
ErrorKind::UnexpectedQueryString(_)
|
||||||
"registry+https://github.com/rust-lang/cargo#0.52.0?branch=dev"
|
);
|
||||||
)
|
err!(
|
||||||
.is_err());
|
"path+file:///path/to/my/project/foo?branch=dev",
|
||||||
assert!(PackageIdSpec::parse(
|
ErrorKind::UnexpectedQueryString(_)
|
||||||
"sparse+https://github.com/rust-lang/cargo#0.52.0?branch=dev"
|
);
|
||||||
)
|
err!(
|
||||||
.is_err());
|
"registry+https://github.com/rust-lang/cargo#0.52.0?branch=dev",
|
||||||
assert!(PackageIdSpec::parse("@1.2.3").is_err());
|
ErrorKind::PartialVersion(_)
|
||||||
assert!(PackageIdSpec::parse("registry+https://github.com").is_err());
|
);
|
||||||
assert!(PackageIdSpec::parse("https://crates.io/1foo#1.2.3").is_err())
|
err!(
|
||||||
|
"sparse+https://github.com/rust-lang/cargo#0.52.0?branch=dev",
|
||||||
|
ErrorKind::PartialVersion(_)
|
||||||
|
);
|
||||||
|
err!("@1.2.3", ErrorKind::NameValidation(_));
|
||||||
|
err!("registry+https://github.com", ErrorKind::NameValidation(_));
|
||||||
|
err!("https://crates.io/1foo#1.2.3", ErrorKind::NameValidation(_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue