Skip to content

Commit

Permalink
test: reorg tests (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yfo authored Mar 25, 2024
1 parent 5f33c59 commit f65fcce
Show file tree
Hide file tree
Showing 287 changed files with 2,760 additions and 2,775 deletions.
42 changes: 37 additions & 5 deletions .github/test.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
#!/usr/bin/env bash

# NOTE: `cargo test [TESTNAME]` is used to filter only the submodule with tests to test a
# specific feature or features' combination
# e.g. `cargo test --features rc,unstable__schema 'schema::test_rc'` is used to test `BorshSchema`
# implementation of `std::rc::Rc` and `std::sync::Arc`,
# where `[TESTNAME]` argument is set to `schema::test_rc`, which includes tests from `schema::test_rc`
# submodule of `borsh/tests/tests.rs` to be run.
set -e
set -x
export INSTA_UPDATE=no
pushd borsh
############################ borsh `default-features = true` group #########################
########## general group
cargo test --no-run
cargo test
cargo test --features unstable__schema,ascii --test test_ascii_strings
cargo test --features derive
cargo test --features unstable__schema
cargo test --test test_rc --features unstable__schema,rc
cargo test --test test_hash_map --test test_btree_map --features de_strict_order
########## features = ["ascii"] group
cargo test --features ascii 'roundtrip::test_ascii_strings'
cargo test --features ascii 'deserialization_errors::test_ascii_strings'
cargo test --features ascii,unstable__schema 'schema::test_ascii_strings'
########## features = ["rc"] group
cargo test --features rc 'roundtrip::test_rc'
cargo test --features rc,unstable__schema 'schema::test_rc'
########## features = ["de_strict_order"] group
cargo test --features de_strict_order 'roundtrip::test_hash_map'
cargo test --features de_strict_order 'roundtrip::test_btree_map'
########## features = ["bson"] group
cargo test --features bson,derive 'roundtrip::requires_derive_category::test_bson_object_ids'
########## features = ["bytes"] group
cargo test --features bytes,derive 'roundtrip::requires_derive_category::test_ultimate_many_features_combined'


############################ borsh `default-features = false` group #########################
########## general group
cargo test --no-default-features
cargo test --no-default-features --features unstable__schema,ascii --test test_ascii_strings
cargo test --no-default-features --features derive
cargo test --no-default-features --features unstable__schema
cargo test --no-default-features --test test_rc --features unstable__schema,rc
########## features = ["ascii"] group
cargo test --no-default-features --features ascii 'roundtrip::test_ascii_strings'
cargo test --no-default-features --features ascii 'deserialization_errors::test_ascii_strings'
cargo test --no-default-features --features ascii,unstable__schema 'schema::test_ascii_strings'
########## features = ["rc"] group
cargo test --no-default-features --features rc 'roundtrip::test_rc'
cargo test --no-default-features --features rc,unstable__schema 'schema::test_rc'
########## features = ["hashbrown"] group
cargo test --no-default-features --features hashbrown
cargo test --no-default-features --features hashbrown,derive
cargo test --no-default-features --features hashbrown,unstable__schema
popd
pushd borsh-derive
############################ borsh-derive group #########################
cargo test --features schema
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ enum A {
}
```

## Testing

Integration tests should generally be preferred to unit ones. Root module of integration tests of `borsh` crate is [linked](./borsh/tests/tests.rs) here.

## Releasing

The versions of all public crates in this repository are collectively managed by a single version in the [workspace manifest](https://github.com/near/borsh-rs/blob/master/Cargo.toml).
Expand Down
6 changes: 1 addition & 5 deletions borsh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://borsh.io"
description = """
Binary Object Representation Serializer for Hashing
"""
exclude = ["tests/snapshots"]
exclude = ["*.snap"]

[lib]
name = "borsh"
Expand All @@ -38,10 +38,6 @@ bytes = { version = "1", optional = true }
bson = { version = "2", optional = true }

[dev-dependencies]
bytes = "1"
bson = "2"
# Enable the "bytes" and "bson" features in integ tests: https://github.com/rust-lang/cargo/issues/2911#issuecomment-1464060655
borsh = { path = ".", default_features = false, features = ["bytes", "bson"] }
insta = "1.29.0"

[package.metadata.docs.rs]
Expand Down
9 changes: 5 additions & 4 deletions borsh/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::{
mem::size_of,
};

#[cfg(any(test, feature = "bytes"))]
#[cfg(feature = "bytes")]
use bytes::{BufMut, BytesMut};

use crate::__private::maybestd::{
Expand Down Expand Up @@ -421,7 +421,7 @@ where
}
}

#[cfg(any(test, feature = "bytes"))]
#[cfg(feature = "bytes")]
impl BorshDeserialize for bytes::Bytes {
#[inline]
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self> {
Expand All @@ -430,7 +430,7 @@ impl BorshDeserialize for bytes::Bytes {
}
}

#[cfg(any(test, feature = "bytes"))]
#[cfg(feature = "bytes")]
impl BorshDeserialize for bytes::BytesMut {
#[inline]
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self> {
Expand All @@ -443,7 +443,7 @@ impl BorshDeserialize for bytes::BytesMut {
}
}

#[cfg(any(test, feature = "bson"))]
#[cfg(feature = "bson")]
impl BorshDeserialize for bson::oid::ObjectId {
#[inline]
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self> {
Expand Down Expand Up @@ -779,6 +779,7 @@ fn array_deserialization_doesnt_leak() {
static DESERIALIZE_COUNT: AtomicUsize = AtomicUsize::new(0);
static DROP_COUNT: AtomicUsize = AtomicUsize::new(0);

#[allow(unused)]
struct MyType(u8);
impl BorshDeserialize for MyType {
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self> {
Expand Down
4 changes: 2 additions & 2 deletions borsh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
This feature is set to be mutually exclusive with **std** feature.
* **bytes** -
Gates implementation of [BorshSerialize] and [BorshDeserialize]
for [Bytes](bytes::Bytes) and [BytesMut](bytes::BytesMut).
for [Bytes](https://docs.rs/bytes/1.5.0/bytes/struct.Bytes.html) and [BytesMut](https://docs.rs/bytes/1.5.0/bytes/struct.BytesMut.html).
* **bson** -
Gates implementation of [BorshSerialize] and [BorshDeserialize]
for [ObjectId](bson::oid::ObjectId).
for [ObjectId](https://docs.rs/bson/2.9.0/bson/oid/struct.ObjectId.html).
* **ascii** -
Gates implementation of [BorshSerialize], [BorshDeserialize], [BorshSchema] for
types from [ascii](https://docs.rs/ascii/1.1.0/ascii/) crate.
Expand Down
Loading

0 comments on commit f65fcce

Please sign in to comment.