diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6b23f72f..474a8c57 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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", diff --git a/compatibility/Cargo.toml b/compatibility/Cargo.toml index 10d945e9..2c4a60e0 100644 --- a/compatibility/Cargo.toml +++ b/compatibility/Cargo.toml @@ -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" diff --git a/compatibility/src/lib.rs b/compatibility/src/lib.rs index 25d87311..8c56cad2 100644 --- a/compatibility/src/lib.rs +++ b/compatibility/src/lib.rs @@ -18,25 +18,33 @@ where C: bincode_2::config::Config, 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 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);