-
Notifications
You must be signed in to change notification settings - Fork 18
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
Easier to diff, prettier rendering for jsonlines #348
Comments
I think doing exactly what cargo-test-support wouldn't align well with snapbox. However, what we could do is allow the test-author to separately specify the expected-format from the actual-format and allow them if the internal structure is similar. This would be leveraging the fact that we store jsonlines as a This means the "expected" would be pretty-printed json, rather than a bespoke format. The result is mostly the same, with the main difference being extra indentation and json's inconsistent comma between entries. One potential API: assert_data_eq!(actual.jsonlines(), expected.json()); The problem with trait methods on So I'd probably go with assert_data_eq!(actual, expected.is_json().against_jsonlines()); Note I renamed |
This looks good. So does the rename. (little concerns around rename as people usually dont like it, but I feel like the major consumers of snapbox should be fine with it) |
I've implemented #350 but it looks like it won't be sufficient for Cargo as it tries to filter out "invalid" jsonlines let actual_objs: Vec<_> = actual
.lines()
.filter(|line| line.starts_with('{'))
.map(|line| {
line.parse()
.with_context(|| format!("failed to parse JSON object:\n{}", line))
})
.collect::<Result<_>>()?; |
|
test: Migrate some json tests to snapbox ### What does this PR try to resolve? This builds on assert-rs/snapbox#348 and is part of #14039. Note: this also updates existing `.is_jsonlines()` usage to `.is_json().against_jsonlines()`. ### How should we test and review this PR? ### Additional information
cargo-test-support
s built-in assertions for jsonlines would perform the following transformation to the "expected" valueso instead of
you'd get
This makes it easier to inspect the jsonlines data and to view the diffs.
For Cargo to adopt snapbox, we need something similar, see rust-lang/cargo#14039
The text was updated successfully, but these errors were encountered: