Made the compatibility check also include bincode 2 serde, and added comments (#501)

* Made the compatibility check also include bincode 2 serde, and added comments

* Added a CI step to run the compatibility tests
This commit is contained in:
Trangar 2022-02-06 09:50:16 +01:00 committed by GitHub
parent bef1f47f0f
commit a8bdffa844
3 changed files with 44 additions and 9 deletions

View File

@ -158,6 +158,33 @@ fi",
}
]
},
"compatibility": {
"name": "Compatibility",
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v2",
"name": "Checkout"
},
{
"uses": "actions-rs/toolchain@v1",
"with": {
"profile": "minimal",
"toolchain": "stable",
"override": true,
},
"name": "Install Rust stable"
},
{
"uses": "actions-rs/cargo@v1",
"with": {
"command": "test",
"args": "--manifest-path compatibility/Cargo.toml"
},
"name": "Run compatibility tests"
}
]
},
"coverage": {
"name": "Code Coverage",
"runs-on": "ubuntu-latest",

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bincode_2 = { path = "..", package = "bincode" }
bincode_2 = { path = "..", package = "bincode", features = ["serde"] }
bincode_1 = { version = "1", package = "bincode" }
serde = { version = "1", features = ["derive"] }
rand = "0.8"

View File

@ -17,25 +17,33 @@ where
C: bincode_2::config::Config,
O: bincode_1::Options + Copy,
{
let bincode_1_output = bincode_1_options.serialize(t).unwrap();
let bincode_2_output = bincode_2::encode_to_vec(t, bincode_2_config).unwrap();
// This is what bincode 1 serializes to. This will be our comparison value.
let encoded = bincode_1_options.serialize(t).unwrap();
// Test bincode 2 encode
let bincode_2_output = bincode_2::encode_to_vec(t, bincode_2_config).unwrap();
assert_eq!(encoded, bincode_2_output, "{:?} serializes differently", t);
// Test bincode 2 serde serialize
let bincode_2_serde_output = bincode_2::serde::encode_to_vec(t, bincode_2_config).unwrap();
assert_eq!(
bincode_1_output, bincode_2_output,
encoded, bincode_2_serde_output,
"{:?} serializes differently",
t
);
let decoded: T = bincode_1_options.deserialize(&bincode_1_output).unwrap();
assert_eq!(&decoded, t);
let decoded: T = bincode_1_options.deserialize(&bincode_2_output).unwrap();
// Test bincode 1 deserialize
let decoded: T = bincode_1_options.deserialize(&encoded).unwrap();
assert_eq!(&decoded, t);
let decoded: T = bincode_2::decode_from_slice(&bincode_1_output, bincode_2_config)
// Test bincode 2 decode
let decoded: T = bincode_2::decode_from_slice(&encoded, bincode_2_config)
.unwrap()
.0;
assert_eq!(&decoded, t);
let decoded: T = bincode_2::decode_from_slice(&bincode_2_output, bincode_2_config)
// Test bincode 2 serde deserialize
let decoded: T = bincode_2::serde::decode_from_slice(&encoded, bincode_2_config)
.unwrap()
.0;
assert_eq!(&decoded, t);