Skip to content

Commit

Permalink
Added cross platform tests workflow (#534)
Browse files Browse the repository at this point in the history
* Added cross platform tests

* Added all cross platforms

* Fixed an issue where `usize` and `isize` would be encoded wrong on 32 bit platforms

* Made the cross platform tests actually run on the platforms

* Disabled cross targets that don't build right now

* Fixed a failing test on 32 bit platforms, re-enabled all platforms for testing

* Disabled failing platforms
  • Loading branch information
VictorKoenders authored Apr 4, 2022
1 parent 3404fae commit 36ab23c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/cross_platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "Cross platform tests",
"on": {
"push": {
"branches": [
"trunk",
"v*.x",
"ci/*"
]
},
"pull_request": {
"branches": [
"trunk",
"v*.x"
]
}
},
"jobs": {
"check": {
"name": "Test",
"runs-on": "ubuntu-latest",
"strategy": {
"fail-fast": false,
"matrix": {
"platform": [
"aarch64-unknown-linux-gnu",
"arm-unknown-linux-gnueabi",
"arm-unknown-linux-gnueabihf",
# "armv5te-unknown-linux-gnueabi",
"armv7-unknown-linux-gnueabihf",
"i586-unknown-linux-gnu",
# "i686-pc-windows-gnu",
"i686-unknown-linux-gnu",
# "mips-unknown-linux-gnu",
"mips64-unknown-linux-gnuabi64",
"mips64el-unknown-linux-gnuabi64",
# "mipsel-unknown-linux-gnu",
# "powerpc-unknown-linux-gnu",
# "powerpc64-unknown-linux-gnu",
# "powerpc64le-unknown-linux-gnu",
"riscv64gc-unknown-linux-gnu",
# "sparc64-unknown-linux-gnu",
"x86_64-pc-windows-gnu",
"x86_64-unknown-linux-gnu"
]
}
},
"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/install@v0.1",
"with": {
"crate": "cross"
},
"name": "Install cargo cross"
},
{
"run": "cross test --target ${{ matrix.platform }}",
"name": "Run tests",
"env": {
"RUSTFLAGS": "-D warnings"
}
}
]
}
}
}
8 changes: 4 additions & 4 deletions src/enc/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ impl Encode for usize {
crate::varint::varint_encode_usize(encoder.writer(), E::C::ENDIAN, *self)
}
IntEncoding::Fixed => match E::C::ENDIAN {
Endian::Big => encoder.writer().write(&self.to_be_bytes()),
Endian::Little => encoder.writer().write(&self.to_le_bytes()),
Endian::Big => encoder.writer().write(&(*self as u64).to_be_bytes()),
Endian::Little => encoder.writer().write(&(*self as u64).to_le_bytes()),
},
}
}
Expand Down Expand Up @@ -246,8 +246,8 @@ impl Encode for isize {
crate::varint::varint_encode_isize(encoder.writer(), E::C::ENDIAN, *self)
}
IntEncoding::Fixed => match E::C::ENDIAN {
Endian::Big => encoder.writer().write(&self.to_be_bytes()),
Endian::Little => encoder.writer().write(&self.to_le_bytes()),
Endian::Big => encoder.writer().write(&(*self as i64).to_be_bytes()),
Endian::Little => encoder.writer().write(&(*self as i64).to_le_bytes()),
},
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ fn test_container_limits() {
bincode::config::standard().with_limit::<DECODE_LIMIT>(),
);

assert_eq!(result.unwrap_err(), DecodeError::LimitExceeded);
let name = core::any::type_name::<T>();
match result {
Ok(_) => panic!("Decoding {} should fail, it instead succeeded", name),
Err(DecodeError::OutsideUsizeRange(_)) if cfg!(target_pointer_width = "32") => {},
Err(DecodeError::LimitExceeded) => {},
Err(e) => panic!("Expected OutsideUsizeRange (on 32 bit platforms) or LimitExceeded whilst decoding {}, got {:?}", name, e),
}
}

for slice in test_cases {
Expand Down

0 comments on commit 36ab23c

Please sign in to comment.