Skip to content
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
182 changes: 178 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ datasketches = { path = "datasketches" }

# Crates.io dependencies
clap = { version = "4.5.20", features = ["derive"] }
insta = { version = "1.46.1" }
googletest = { version = "0.14.2" }
which = { version = "8.0.0" }

Expand Down
3 changes: 1 addition & 2 deletions datasketches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ keywords = ["sketch", "hyperloglog", "probabilistic"]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]

[dev-dependencies]
googletest = { workspace = true }
insta = { workspace = true }

[lints]
workspace = true
22 changes: 4 additions & 18 deletions datasketches/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,21 @@ impl std::error::Error for Error {}

#[cfg(test)]
mod tests {
use insta::assert_snapshot;

use super::*;

#[test]
fn test_format_consistency() {
// Case 1: Test basic error message
let err = Error::new(ErrorKind::InvalidArgument, "something went wrong");
assert_eq!(
format!("{}", err),
"InvalidArgument => something went wrong",
"Basic error formatting mismatch"
);
assert_snapshot!(err, @"InvalidArgument => something went wrong",);
}

#[test]
fn test_format_with_multiple_contexts() {
// Case 2: Test with multiple contexts
// This validates the comma separation logic which is prone to regression
let err = Error::new(ErrorKind::InvalidData, "parsing failed")
.with_context("index", 42)
.with_context("file", "foo");

let output = format!("{}", err);

// Expected full string
let expected = "InvalidData, context: { index: 42, file: foo } => parsing failed";

assert_eq!(
output, expected,
"Formatted output with context does not match expectation"
);
assert_snapshot!(err, @"InvalidData, context: { index: 42, file: foo } => parsing failed");
}
}