Skip to content
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

test: add insta snapshots to borsh/tests #157

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

dj8yfo
Copy link
Collaborator

@dj8yfo dj8yfo commented Jun 22, 2023

Resolves #152

@dj8yfo dj8yfo requested a review from frol as a code owner June 22, 2023 11:40
@dj8yfo dj8yfo force-pushed the insta_snapshot_testing branch 2 times, most recently from d28d93f to 6a31c3c Compare June 22, 2023 12:00
@dj8yfo dj8yfo changed the title test: add insta snapshots to borsh/tests [wip] test: add insta snapshots to borsh/tests Jun 22, 2023
@dj8yfo dj8yfo force-pushed the insta_snapshot_testing branch 6 times, most recently from e223169 to 148ab11 Compare June 22, 2023 13:04
@dj8yfo dj8yfo changed the title [wip] test: add insta snapshots to borsh/tests test: add insta snapshots to borsh/tests Jun 22, 2023
@dj8yfo
Copy link
Collaborator Author

dj8yfo commented Jun 22, 2023

  • borsh::test_arrays:
  • borsh::test_tuple:
  • borsh::test_primitives:
  • borsh::test_bson_object_ids:
  • borsh::test_vecs:
  • borsh::test_strings:
  • borsh::test_hash_map:
  • borsh::test_schema_enums:
    • complex_enum_with_schema?
  • borsh::test_simple_structs:
  • borsh::test_generic_struct:
  • borsh::test_binary_heaps:

Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dj8yfo Looks good to me! Let's rebase/resolve merge conflict and address the only comment I left before merging.

@@ -148,6 +148,7 @@ pub fn complex_enum_with_schema() {
// Then check that we serialize and deserialize with schema.
let obj = A::default();
let data = try_to_vec_with_schema(&obj).unwrap();
// insta::assert_debug_snapshot!(buf);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it commented out? Is it too big? Is it not stable?

Copy link
Collaborator Author

@dj8yfo dj8yfo Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've mentioned that this example of schema derivation https://github.com/near/borsh-rs/blob/master/borsh-schema-derive-internal/src/enum_schema.rs#L365 is suboptimal, as structs representing enum variants depend on more generic params than their counterparts in original enum.
There may be more of such details, which would affect schema serialization if changed.

@dj8yfo dj8yfo force-pushed the insta_snapshot_testing branch 2 times, most recently from c59dfe5 to e8a519f Compare June 22, 2023 17:33
Comment on lines +174 to +175
#[cfg(feature = "std")]
insta::assert_debug_snapshot!(encoded_a);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pity that we skip the format safety checks for no-std. Is there anything we can do about it? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, not with insta crate . it explicitly imports std in expanded macros

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://crates.io/crates/expect-test and https://crates.io/crates/k9 and don't feature no_std as far as i can see as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's live with this for now. Maybe someone will contribute no_std support to insta or some other similar tool.

@frol frol merged commit a7de2f7 into near:master Jun 23, 2023
@dj8yfo dj8yfo mentioned this pull request Aug 2, 2023
@frol frol mentioned this pull request Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce snapshot testing for all the serialized results
2 participants