Skip to content

Commit 3a2cc82

Browse files
committed
test(msrv): Migrate most parse tests to unit tests
1 parent 675d67d commit 3a2cc82

File tree

4 files changed

+50
-199
lines changed

4 files changed

+50
-199
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cargo-util-schemas/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ url.workspace = true
2020

2121
[lints]
2222
workspace = true
23+
24+
[dev-dependencies]
25+
snapbox.workspace = true

crates/cargo-util-schemas/src/manifest/rust_version.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ enum RustVersionErrorKind {
106106
#[cfg(test)]
107107
mod test {
108108
use super::*;
109+
use snapbox::str;
109110

110111
#[test]
111112
fn is_compatible_with_rustc() {
@@ -170,4 +171,48 @@ mod test {
170171
}
171172
assert!(passed);
172173
}
174+
175+
#[test]
176+
fn parse_errors() {
177+
let cases = &[
178+
// Disallow caret
179+
(
180+
"^1.43",
181+
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
182+
),
183+
// Valid pre-release
184+
(
185+
"1.43.0-beta.1",
186+
str![[r#"unexpected prerelease field, expected a version like "1.32""#]],
187+
),
188+
// Bad pre-release
189+
(
190+
"1.43-beta.1",
191+
str![[r#"unexpected prerelease field, expected a version like "1.32""#]],
192+
),
193+
// Weird wildcard
194+
(
195+
"x",
196+
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
197+
),
198+
(
199+
"1.x",
200+
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
201+
),
202+
(
203+
"1.1.x",
204+
str![[r#"unexpected version requirement, expected a version like "1.32""#]],
205+
),
206+
// Non-sense
207+
("foodaddle", str![[r#"expected a version like "1.32""#]]),
208+
];
209+
for (input, expected) in cases {
210+
let actual: Result<RustVersion, _> = input.parse();
211+
let actual = match actual {
212+
Ok(result) => format!("didn't fail: {result:?}"),
213+
Err(err) => err.to_string(),
214+
};
215+
snapbox::assert_eq(expected.clone(), actual);
216+
}
217+
}
173218
}

tests/testsuite/rust_version.rs

Lines changed: 1 addition & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn rust_version_satisfied() {
2626
}
2727

2828
#[cargo_test]
29-
fn rust_version_bad_caret() {
29+
fn rust_version_error() {
3030
project()
3131
.file(
3232
"Cargo.toml",
@@ -58,204 +58,6 @@ fn rust_version_bad_caret() {
5858
.run();
5959
}
6060

61-
#[cargo_test]
62-
fn rust_version_good_pre_release() {
63-
project()
64-
.file(
65-
"Cargo.toml",
66-
r#"
67-
[package]
68-
name = "foo"
69-
version = "0.0.1"
70-
edition = "2015"
71-
authors = []
72-
rust-version = "1.43.0-beta.1"
73-
[[bin]]
74-
name = "foo"
75-
"#,
76-
)
77-
.file("src/main.rs", "fn main() {}")
78-
.build()
79-
.cargo("check")
80-
.with_status(101)
81-
.with_stderr(
82-
"\
83-
[ERROR] unexpected prerelease field, expected a version like \"1.32\"
84-
--> Cargo.toml:7:28
85-
|
86-
7 | rust-version = \"1.43.0-beta.1\"
87-
| ^^^^^^^^^^^^^^^
88-
|
89-
",
90-
)
91-
.run();
92-
}
93-
94-
#[cargo_test]
95-
fn rust_version_bad_pre_release() {
96-
project()
97-
.file(
98-
"Cargo.toml",
99-
r#"
100-
[package]
101-
name = "foo"
102-
version = "0.0.1"
103-
edition = "2015"
104-
authors = []
105-
rust-version = "1.43-beta.1"
106-
[[bin]]
107-
name = "foo"
108-
"#,
109-
)
110-
.file("src/main.rs", "fn main() {}")
111-
.build()
112-
.cargo("check")
113-
.with_status(101)
114-
.with_stderr(
115-
"\
116-
[ERROR] unexpected prerelease field, expected a version like \"1.32\"
117-
--> Cargo.toml:7:28
118-
|
119-
7 | rust-version = \"1.43-beta.1\"
120-
| ^^^^^^^^^^^^^
121-
|
122-
",
123-
)
124-
.run();
125-
}
126-
127-
#[cargo_test]
128-
fn rust_version_x_wildcard() {
129-
project()
130-
.file(
131-
"Cargo.toml",
132-
r#"
133-
[package]
134-
name = "foo"
135-
version = "0.0.1"
136-
edition = "2015"
137-
authors = []
138-
rust-version = "x"
139-
[[bin]]
140-
name = "foo"
141-
"#,
142-
)
143-
.file("src/main.rs", "fn main() {}")
144-
.build()
145-
.cargo("check")
146-
.with_status(101)
147-
.with_stderr(
148-
"\
149-
[ERROR] unexpected version requirement, expected a version like \"1.32\"
150-
--> Cargo.toml:7:28
151-
|
152-
7 | rust-version = \"x\"
153-
| ^^^
154-
|
155-
",
156-
)
157-
.run();
158-
}
159-
160-
#[cargo_test]
161-
fn rust_version_minor_x_wildcard() {
162-
project()
163-
.file(
164-
"Cargo.toml",
165-
r#"
166-
[package]
167-
name = "foo"
168-
version = "0.0.1"
169-
edition = "2015"
170-
authors = []
171-
rust-version = "1.x"
172-
[[bin]]
173-
name = "foo"
174-
"#,
175-
)
176-
.file("src/main.rs", "fn main() {}")
177-
.build()
178-
.cargo("check")
179-
.with_status(101)
180-
.with_stderr(
181-
"\
182-
[ERROR] unexpected version requirement, expected a version like \"1.32\"
183-
--> Cargo.toml:7:28
184-
|
185-
7 | rust-version = \"1.x\"
186-
| ^^^^^
187-
|
188-
",
189-
)
190-
.run();
191-
}
192-
193-
#[cargo_test]
194-
fn rust_version_patch_x_wildcard() {
195-
project()
196-
.file(
197-
"Cargo.toml",
198-
r#"
199-
[package]
200-
name = "foo"
201-
version = "0.0.1"
202-
edition = "2015"
203-
authors = []
204-
rust-version = "1.30.x"
205-
[[bin]]
206-
name = "foo"
207-
"#,
208-
)
209-
.file("src/main.rs", "fn main() {}")
210-
.build()
211-
.cargo("check")
212-
.with_status(101)
213-
.with_stderr(
214-
"\
215-
[ERROR] unexpected version requirement, expected a version like \"1.32\"
216-
--> Cargo.toml:7:28
217-
|
218-
7 | rust-version = \"1.30.x\"
219-
| ^^^^^^^^
220-
|
221-
",
222-
)
223-
.run();
224-
}
225-
226-
#[cargo_test]
227-
fn rust_version_bad_nonsense() {
228-
project()
229-
.file(
230-
"Cargo.toml",
231-
r#"
232-
[package]
233-
name = "foo"
234-
version = "0.0.1"
235-
edition = "2015"
236-
authors = []
237-
rust-version = "foodaddle"
238-
[[bin]]
239-
name = "foo"
240-
"#,
241-
)
242-
.file("src/main.rs", "fn main() {}")
243-
.build()
244-
.cargo("check")
245-
.with_status(101)
246-
.with_stderr(
247-
"\
248-
[ERROR] expected a version like \"1.32\"
249-
--> Cargo.toml:7:28
250-
|
251-
7 | rust-version = \"foodaddle\"
252-
| ^^^^^^^^^^^
253-
|
254-
",
255-
)
256-
.run();
257-
}
258-
25961
#[cargo_test]
26062
fn rust_version_older_than_edition() {
26163
project()

0 commit comments

Comments
 (0)