Skip to content

Commit

Permalink
Add tests for unused structs
Browse files Browse the repository at this point in the history
  • Loading branch information
avl committed Aug 3, 2024
1 parent 10c5869 commit 7eee9e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 65 deletions.
9 changes: 8 additions & 1 deletion savefile-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(test)]
#![allow(unused_imports)]
#![cfg_attr(feature = "nightly", feature(test))]
#![deny(warnings)]
#![cfg_attr(miri, allow(dead_code))]

#[cfg(test)]
extern crate insta;
Expand Down Expand Up @@ -1399,6 +1399,13 @@ impl Introspect for ExampleWithoutAutomaticIntrospect {
}
}

#[test]
fn roundtrip_example_without_introspect() {
roundtrip(ExampleWithoutAutomaticIntrospect{
x: 42
});
}

#[cfg(test)]
fn speed(len: usize, time: std::time::Duration) -> String {
let total_seconds = time.as_micros() as f64 * 1e-6;
Expand Down

This file was deleted.

21 changes: 21 additions & 0 deletions savefile-test/src/test_nested_non_repr_c.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(test)]
use roundtrip;
use savefile::prelude::*;

#[derive(Clone, Copy, Debug, PartialEq, Savefile)]
Expand All @@ -22,6 +24,17 @@ fn test_misaligned1() {
assert_eq!(unsafe { CorrectlyAligned::repr_c_optimization_safe(0).is_yes() }, true);
}

#[test]
fn roundtrip_correctly_aligned() {
roundtrip(CorrectlyAligned{
x: 1, y: 2
});
roundtrip(Inner{
misaligner: 43,
x: 42
});
}

#[derive(Clone, Copy, Debug, PartialEq, Savefile)]
//#[savefile_unsafe_and_fast] This now causes compilation failure, so test doesn't really work
struct Inner2 {
Expand All @@ -35,3 +48,11 @@ fn test_misaligned2() {
assert_eq!(unsafe { Inner2::repr_c_optimization_safe(0).is_yes() }, false);
assert_eq!(unsafe { CorrectlyAligned::repr_c_optimization_safe(0).is_yes() }, true);
}

#[test]
fn test_roundtrip_inner2() {
roundtrip(Inner2 {
x: 47,
misaligner: 48
});
}
2 changes: 2 additions & 0 deletions savefile-test/src/test_nested_repr_c.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg(test)]
use savefile::prelude::*;


#[derive(Clone, Copy, Debug, PartialEq, Savefile)]
#[savefile_unsafe_and_fast]
struct Inner {
Expand Down

0 comments on commit 7eee9e2

Please sign in to comment.