Skip to content

Commit c385741

Browse files
authored
tarball: Use snapshot testing for more tests (#11450)
1 parent ab9b8a5 commit c385741

12 files changed

+820
-94
lines changed

crates/crates_io_tarball/src/lib.rs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ impl AbstractFilesystem for PathsFileSystem {
183183
mod tests {
184184
use super::process_tarball;
185185
use crate::TarballBuilder;
186-
use cargo_manifest::{MaybeInherited, StringOrBool};
187186
use insta::{assert_debug_snapshot, assert_snapshot};
188187

189188
const MANIFEST: &[u8] = b"[package]\nname = \"foo\"\nversion = \"0.0.1\"\n";
@@ -196,10 +195,7 @@ mod tests {
196195
.build();
197196

198197
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
199-
assert_none!(tarball_info.vcs_info);
200-
assert_none!(tarball_info.manifest.lib);
201-
assert_eq!(tarball_info.manifest.bin, vec![]);
202-
assert_eq!(tarball_info.manifest.example, vec![]);
198+
assert_debug_snapshot!(tarball_info);
203199

204200
let err = assert_err!(process_tarball("bar-0.0.1", &*tarball, MAX_SIZE).await);
205201
assert_snapshot!(err, @"invalid path found: foo-0.0.1/Cargo.toml");
@@ -224,8 +220,8 @@ mod tests {
224220
.build();
225221

226222
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
227-
let vcs_info = assert_some!(tarball_info.vcs_info);
228-
assert_eq!(vcs_info.path_in_vcs, "");
223+
assert_some!(&tarball_info.vcs_info);
224+
assert_debug_snapshot!(tarball_info);
229225
}
230226

231227
#[tokio::test]
@@ -237,8 +233,8 @@ mod tests {
237233
.build();
238234

239235
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
240-
let vcs_info = assert_some!(tarball_info.vcs_info);
241-
assert_eq!(vcs_info.path_in_vcs, "path/in/vcs");
236+
assert_some!(&tarball_info.vcs_info);
237+
assert_debug_snapshot!(tarball_info);
242238
}
243239

244240
#[tokio::test]
@@ -256,10 +252,7 @@ mod tests {
256252
.build();
257253

258254
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
259-
let package = assert_some!(tarball_info.manifest.package);
260-
assert_matches!(package.readme, Some(MaybeInherited::Local(StringOrBool::String(s))) if s == "README.md");
261-
assert_matches!(package.repository, Some(MaybeInherited::Local(s)) if s == "https://github.com/foo/bar");
262-
assert_matches!(package.rust_version, Some(MaybeInherited::Local(s)) if s == "1.59");
255+
assert_debug_snapshot!(tarball_info);
263256
}
264257

265258
#[tokio::test]
@@ -275,8 +268,7 @@ mod tests {
275268
.build();
276269

277270
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
278-
let package = assert_some!(tarball_info.manifest.package);
279-
assert_matches!(package.rust_version, Some(MaybeInherited::Local(s)) if s == "1.23");
271+
assert_debug_snapshot!(tarball_info);
280272
}
281273

282274
#[tokio::test]
@@ -286,8 +278,7 @@ mod tests {
286278
.build();
287279

288280
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
289-
let package = assert_some!(tarball_info.manifest.package);
290-
assert_none!(package.readme);
281+
assert_debug_snapshot!(tarball_info);
291282
}
292283

293284
#[tokio::test]
@@ -303,8 +294,7 @@ mod tests {
303294
.build();
304295

305296
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
306-
let package = assert_some!(tarball_info.manifest.package);
307-
assert_matches!(package.readme, Some(MaybeInherited::Local(StringOrBool::Bool(b))) if !b);
297+
assert_debug_snapshot!(tarball_info);
308298
}
309299

310300
#[tokio::test]
@@ -320,8 +310,7 @@ mod tests {
320310
.build();
321311

322312
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
323-
let package = assert_some!(tarball_info.manifest.package);
324-
assert_matches!(package.repository, Some(MaybeInherited::Local(s)) if s == "https://github.com/foo/bar");
313+
assert_debug_snapshot!(tarball_info);
325314
}
326315

327316
#[tokio::test]
@@ -372,10 +361,7 @@ mod tests {
372361
.build();
373362

374363
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
375-
let lib = assert_some!(tarball_info.manifest.lib);
376-
assert_debug_snapshot!(lib);
377-
assert_eq!(tarball_info.manifest.bin, vec![]);
378-
assert_eq!(tarball_info.manifest.example, vec![]);
364+
assert_debug_snapshot!(tarball_info);
379365
}
380366

381367
#[tokio::test]
@@ -389,10 +375,7 @@ mod tests {
389375
.build();
390376

391377
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
392-
let lib = assert_some!(tarball_info.manifest.lib);
393-
assert_debug_snapshot!(lib);
394-
assert_debug_snapshot!(tarball_info.manifest.bin);
395-
assert_debug_snapshot!(tarball_info.manifest.example);
378+
assert_debug_snapshot!(tarball_info);
396379
}
397380

398381
#[tokio::test]
@@ -403,8 +386,6 @@ mod tests {
403386
.build();
404387

405388
let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
406-
assert_none!(tarball_info.manifest.lib);
407-
assert_debug_snapshot!(tarball_info.manifest.bin);
408-
assert_eq!(tarball_info.manifest.example, vec![]);
389+
assert_debug_snapshot!(tarball_info);
409390
}
410391
}
Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,79 @@
11
---
22
source: crates/crates_io_tarball/src/lib.rs
3-
expression: tarball_info.manifest.bin
3+
expression: tarball_info
44
---
5-
[
6-
Product {
7-
path: Some(
8-
"src/main.rs",
5+
TarballInfo {
6+
manifest: Manifest {
7+
package: Some(
8+
Package {
9+
name: "foo",
10+
edition: None,
11+
version: Some(
12+
Local(
13+
"0.0.1",
14+
),
15+
),
16+
build: None,
17+
workspace: None,
18+
authors: None,
19+
links: None,
20+
description: None,
21+
homepage: None,
22+
documentation: None,
23+
readme: None,
24+
keywords: None,
25+
categories: None,
26+
license: None,
27+
license_file: None,
28+
repository: None,
29+
metadata: None,
30+
rust_version: None,
31+
exclude: None,
32+
include: None,
33+
default_run: None,
34+
autolib: None,
35+
autobins: None,
36+
autoexamples: None,
37+
autotests: None,
38+
autobenches: None,
39+
publish: None,
40+
resolver: None,
41+
},
942
),
10-
name: Some(
11-
"foo",
12-
),
13-
test: true,
14-
doctest: true,
15-
bench: true,
16-
doc: true,
17-
plugin: false,
18-
proc_macro: false,
19-
harness: true,
20-
edition: None,
21-
required_features: [],
22-
crate_type: None,
43+
cargo_features: None,
44+
workspace: None,
45+
dependencies: None,
46+
dev_dependencies: None,
47+
build_dependencies: None,
48+
target: None,
49+
features: None,
50+
bin: [
51+
Product {
52+
path: Some(
53+
"src/main.rs",
54+
),
55+
name: Some(
56+
"foo",
57+
),
58+
test: true,
59+
doctest: true,
60+
bench: true,
61+
doc: true,
62+
plugin: false,
63+
proc_macro: false,
64+
harness: true,
65+
edition: None,
66+
required_features: [],
67+
crate_type: None,
68+
},
69+
],
70+
bench: [],
71+
test: [],
72+
example: [],
73+
patch: None,
74+
lib: None,
75+
profile: None,
76+
badges: None,
2377
},
24-
]
78+
vcs_info: None,
79+
}
Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,83 @@
11
---
22
source: crates/crates_io_tarball/src/lib.rs
3-
expression: lib
3+
expression: tarball_info
44
---
5-
Product {
6-
path: Some(
7-
"src/lib.rs",
8-
),
9-
name: Some(
10-
"foo",
11-
),
12-
test: true,
13-
doctest: true,
14-
bench: true,
15-
doc: true,
16-
plugin: false,
17-
proc_macro: false,
18-
harness: true,
19-
edition: None,
20-
required_features: [],
21-
crate_type: Some(
22-
[
23-
"lib",
24-
],
25-
),
5+
TarballInfo {
6+
manifest: Manifest {
7+
package: Some(
8+
Package {
9+
name: "foo",
10+
edition: None,
11+
version: Some(
12+
Local(
13+
"0.0.1",
14+
),
15+
),
16+
build: None,
17+
workspace: None,
18+
authors: None,
19+
links: None,
20+
description: None,
21+
homepage: None,
22+
documentation: None,
23+
readme: None,
24+
keywords: None,
25+
categories: None,
26+
license: None,
27+
license_file: None,
28+
repository: None,
29+
metadata: None,
30+
rust_version: None,
31+
exclude: None,
32+
include: None,
33+
default_run: None,
34+
autolib: None,
35+
autobins: None,
36+
autoexamples: None,
37+
autotests: None,
38+
autobenches: None,
39+
publish: None,
40+
resolver: None,
41+
},
42+
),
43+
cargo_features: None,
44+
workspace: None,
45+
dependencies: None,
46+
dev_dependencies: None,
47+
build_dependencies: None,
48+
target: None,
49+
features: None,
50+
bin: [],
51+
bench: [],
52+
test: [],
53+
example: [],
54+
patch: None,
55+
lib: Some(
56+
Product {
57+
path: Some(
58+
"src/lib.rs",
59+
),
60+
name: Some(
61+
"foo",
62+
),
63+
test: true,
64+
doctest: true,
65+
bench: true,
66+
doc: true,
67+
plugin: false,
68+
proc_macro: false,
69+
harness: true,
70+
edition: None,
71+
required_features: [],
72+
crate_type: Some(
73+
[
74+
"lib",
75+
],
76+
),
77+
},
78+
),
79+
profile: None,
80+
badges: None,
81+
},
82+
vcs_info: None,
2683
}

0 commit comments

Comments
 (0)