mirror of https://git.sr.ht/~stygianentity/bincode
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:
parent
bef1f47f0f
commit
a8bdffa844
|
|
@ -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": {
|
"coverage": {
|
||||||
"name": "Code Coverage",
|
"name": "Code Coverage",
|
||||||
"runs-on": "ubuntu-latest",
|
"runs-on": "ubuntu-latest",
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bincode_2 = { path = "..", package = "bincode" }
|
bincode_2 = { path = "..", package = "bincode", features = ["serde"] }
|
||||||
bincode_1 = { version = "1", package = "bincode" }
|
bincode_1 = { version = "1", package = "bincode" }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
|
|
||||||
|
|
@ -17,25 +17,33 @@ where
|
||||||
C: bincode_2::config::Config,
|
C: bincode_2::config::Config,
|
||||||
O: bincode_1::Options + Copy,
|
O: bincode_1::Options + Copy,
|
||||||
{
|
{
|
||||||
let bincode_1_output = bincode_1_options.serialize(t).unwrap();
|
// This is what bincode 1 serializes to. This will be our comparison value.
|
||||||
let bincode_2_output = bincode_2::encode_to_vec(t, bincode_2_config).unwrap();
|
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!(
|
assert_eq!(
|
||||||
bincode_1_output, bincode_2_output,
|
encoded, bincode_2_serde_output,
|
||||||
"{:?} serializes differently",
|
"{:?} serializes differently",
|
||||||
t
|
t
|
||||||
);
|
);
|
||||||
|
|
||||||
let decoded: T = bincode_1_options.deserialize(&bincode_1_output).unwrap();
|
// Test bincode 1 deserialize
|
||||||
assert_eq!(&decoded, t);
|
let decoded: T = bincode_1_options.deserialize(&encoded).unwrap();
|
||||||
let decoded: T = bincode_1_options.deserialize(&bincode_2_output).unwrap();
|
|
||||||
assert_eq!(&decoded, t);
|
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()
|
.unwrap()
|
||||||
.0;
|
.0;
|
||||||
assert_eq!(&decoded, t);
|
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()
|
.unwrap()
|
||||||
.0;
|
.0;
|
||||||
assert_eq!(&decoded, t);
|
assert_eq!(&decoded, t);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue