test(msrv): Migrate most parse tests to unit tests

This commit is contained in:
Ed Page 2024-04-17 16:34:26 -05:00
parent 675d67d093
commit 3a2cc82789
4 changed files with 50 additions and 199 deletions

1
Cargo.lock generated
View File

@ -472,6 +472,7 @@ dependencies = [
"serde",
"serde-untagged",
"serde-value",
"snapbox",
"thiserror",
"toml",
"unicode-xid",

View File

@ -20,3 +20,6 @@ url.workspace = true
[lints]
workspace = true
[dev-dependencies]
snapbox.workspace = true

View File

@ -106,6 +106,7 @@ enum RustVersionErrorKind {
#[cfg(test)]
mod test {
use super::*;
use snapbox::str;
#[test]
fn is_compatible_with_rustc() {
@ -170,4 +171,48 @@ mod test {
}
assert!(passed);
}
#[test]
fn parse_errors() {
let cases = &[
// Disallow caret
(
"^1.43",
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
),
// Valid pre-release
(
"1.43.0-beta.1",
str![[r#"unexpected prerelease field, expected a version like "1.32""#]],
),
// Bad pre-release
(
"1.43-beta.1",
str![[r#"unexpected prerelease field, expected a version like "1.32""#]],
),
// Weird wildcard
(
"x",
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
),
(
"1.x",
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
),
(
"1.1.x",
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
),
// Non-sense
("foodaddle", str![[r#"expected a version like "1.32""#]]),
];
for (input, expected) in cases {
let actual: Result<RustVersion, _> = input.parse();
let actual = match actual {
Ok(result) => format!("didn't fail: {result:?}"),
Err(err) => err.to_string(),
};
snapbox::assert_eq(expected.clone(), actual);
}
}
}

View File

@ -26,7 +26,7 @@ fn rust_version_satisfied() {
}
#[cargo_test]
fn rust_version_bad_caret() {
fn rust_version_error() {
project()
.file(
"Cargo.toml",
@ -58,204 +58,6 @@ fn rust_version_bad_caret() {
.run();
}
#[cargo_test]
fn rust_version_good_pre_release() {
project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.43.0-beta.1"
[[bin]]
name = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build()
.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] unexpected prerelease field, expected a version like \"1.32\"
--> Cargo.toml:7:28
|
7 | rust-version = \"1.43.0-beta.1\"
| ^^^^^^^^^^^^^^^
|
",
)
.run();
}
#[cargo_test]
fn rust_version_bad_pre_release() {
project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.43-beta.1"
[[bin]]
name = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build()
.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] unexpected prerelease field, expected a version like \"1.32\"
--> Cargo.toml:7:28
|
7 | rust-version = \"1.43-beta.1\"
| ^^^^^^^^^^^^^
|
",
)
.run();
}
#[cargo_test]
fn rust_version_x_wildcard() {
project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "x"
[[bin]]
name = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build()
.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] unexpected version requirement, expected a version like \"1.32\"
--> Cargo.toml:7:28
|
7 | rust-version = \"x\"
| ^^^
|
",
)
.run();
}
#[cargo_test]
fn rust_version_minor_x_wildcard() {
project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.x"
[[bin]]
name = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build()
.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] unexpected version requirement, expected a version like \"1.32\"
--> Cargo.toml:7:28
|
7 | rust-version = \"1.x\"
| ^^^^^
|
",
)
.run();
}
#[cargo_test]
fn rust_version_patch_x_wildcard() {
project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.30.x"
[[bin]]
name = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build()
.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] unexpected version requirement, expected a version like \"1.32\"
--> Cargo.toml:7:28
|
7 | rust-version = \"1.30.x\"
| ^^^^^^^^
|
",
)
.run();
}
#[cargo_test]
fn rust_version_bad_nonsense() {
project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "foodaddle"
[[bin]]
name = "foo"
"#,
)
.file("src/main.rs", "fn main() {}")
.build()
.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] expected a version like \"1.32\"
--> Cargo.toml:7:28
|
7 | rust-version = \"foodaddle\"
| ^^^^^^^^^^^
|
",
)
.run();
}
#[cargo_test]
fn rust_version_older_than_edition() {
project()