Skip to content

tarball: Use snapshot testing for more tests #11450

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 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 13 additions & 32 deletions crates/crates_io_tarball/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ impl AbstractFilesystem for PathsFileSystem {
mod tests {
use super::process_tarball;
use crate::TarballBuilder;
use cargo_manifest::{MaybeInherited, StringOrBool};
use insta::{assert_debug_snapshot, assert_snapshot};

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

let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
assert_none!(tarball_info.vcs_info);
assert_none!(tarball_info.manifest.lib);
assert_eq!(tarball_info.manifest.bin, vec![]);
assert_eq!(tarball_info.manifest.example, vec![]);
assert_debug_snapshot!(tarball_info);

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

let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
let vcs_info = assert_some!(tarball_info.vcs_info);
assert_eq!(vcs_info.path_in_vcs, "");
assert_some!(&tarball_info.vcs_info);
assert_debug_snapshot!(tarball_info);
}

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

let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
let vcs_info = assert_some!(tarball_info.vcs_info);
assert_eq!(vcs_info.path_in_vcs, "path/in/vcs");
assert_some!(&tarball_info.vcs_info);
assert_debug_snapshot!(tarball_info);
}

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

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

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

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

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

let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
let package = assert_some!(tarball_info.manifest.package);
assert_none!(package.readme);
assert_debug_snapshot!(tarball_info);
}

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

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

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

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

#[tokio::test]
Expand Down Expand Up @@ -372,10 +361,7 @@ mod tests {
.build();

let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
let lib = assert_some!(tarball_info.manifest.lib);
assert_debug_snapshot!(lib);
assert_eq!(tarball_info.manifest.bin, vec![]);
assert_eq!(tarball_info.manifest.example, vec![]);
assert_debug_snapshot!(tarball_info);
}

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

let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
let lib = assert_some!(tarball_info.manifest.lib);
assert_debug_snapshot!(lib);
assert_debug_snapshot!(tarball_info.manifest.bin);
assert_debug_snapshot!(tarball_info.manifest.example);
assert_debug_snapshot!(tarball_info);
}

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

let tarball_info = assert_ok!(process_tarball("foo-0.0.1", &*tarball, MAX_SIZE).await);
assert_none!(tarball_info.manifest.lib);
assert_debug_snapshot!(tarball_info.manifest.bin);
assert_eq!(tarball_info.manifest.example, vec![]);
assert_debug_snapshot!(tarball_info);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,79 @@
---
source: crates/crates_io_tarball/src/lib.rs
expression: tarball_info.manifest.bin
expression: tarball_info
---
[
Product {
path: Some(
"src/main.rs",
TarballInfo {
manifest: Manifest {
package: Some(
Package {
name: "foo",
edition: None,
version: Some(
Local(
"0.0.1",
),
),
build: None,
workspace: None,
authors: None,
links: None,
description: None,
homepage: None,
documentation: None,
readme: None,
keywords: None,
categories: None,
license: None,
license_file: None,
repository: None,
metadata: None,
rust_version: None,
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
autobenches: None,
publish: None,
resolver: None,
},
),
name: Some(
"foo",
),
test: true,
doctest: true,
bench: true,
doc: true,
plugin: false,
proc_macro: false,
harness: true,
edition: None,
required_features: [],
crate_type: None,
cargo_features: None,
workspace: None,
dependencies: None,
dev_dependencies: None,
build_dependencies: None,
target: None,
features: None,
bin: [
Product {
path: Some(
"src/main.rs",
),
name: Some(
"foo",
),
test: true,
doctest: true,
bench: true,
doc: true,
plugin: false,
proc_macro: false,
harness: true,
edition: None,
required_features: [],
crate_type: None,
},
],
bench: [],
test: [],
example: [],
patch: None,
lib: None,
profile: None,
badges: None,
},
]
vcs_info: None,
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
---
source: crates/crates_io_tarball/src/lib.rs
expression: lib
expression: tarball_info
---
Product {
path: Some(
"src/lib.rs",
),
name: Some(
"foo",
),
test: true,
doctest: true,
bench: true,
doc: true,
plugin: false,
proc_macro: false,
harness: true,
edition: None,
required_features: [],
crate_type: Some(
[
"lib",
],
),
TarballInfo {
manifest: Manifest {
package: Some(
Package {
name: "foo",
edition: None,
version: Some(
Local(
"0.0.1",
),
),
build: None,
workspace: None,
authors: None,
links: None,
description: None,
homepage: None,
documentation: None,
readme: None,
keywords: None,
categories: None,
license: None,
license_file: None,
repository: None,
metadata: None,
rust_version: None,
exclude: None,
include: None,
default_run: None,
autolib: None,
autobins: None,
autoexamples: None,
autotests: None,
autobenches: None,
publish: None,
resolver: None,
},
),
cargo_features: None,
workspace: None,
dependencies: None,
dev_dependencies: None,
build_dependencies: None,
target: None,
features: None,
bin: [],
bench: [],
test: [],
example: [],
patch: None,
lib: Some(
Product {
path: Some(
"src/lib.rs",
),
name: Some(
"foo",
),
test: true,
doctest: true,
bench: true,
doc: true,
plugin: false,
proc_macro: false,
harness: true,
edition: None,
required_features: [],
crate_type: Some(
[
"lib",
],
),
},
),
profile: None,
badges: None,
},
vcs_info: None,
}
Loading