Skip to content

Commit

Permalink
Merge pull request #3 from alecmocatta/fewer-debug-iterations
Browse files Browse the repository at this point in the history
Fewer debug iterations
  • Loading branch information
alecmocatta authored Oct 17, 2018
2 parents d09c240 + a7249af commit 0bf434b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
license = "Apache-2.0"
authors = ["Alec Mocatta <alec@mocatta.net>"]
categories = ["development-tools"]
keywords = ["env"]
keywords = ["serde","serialize","pipe"]
description = """
Turn serde+bincode into a pipe: push `T`s and pull `u8`s, or vice versa.
Expand Down
55 changes: 33 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,13 @@ mod tests {
fn serializer() {
let mut rng =
XorShiftRng::from_seed([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
for _ in 0..50_000 {
// hack until https://internals.rust-lang.org/t/idea-allow-to-query-current-optimization-level-using-cfg-opt-level/7089
let iterations = if cfg!(debug_assertions) {
5_000
} else {
50_000
};
for _ in 0..iterations {
let mut serializer = Serializer::new();
let mut queue = VecDeque::new();
for _ in 0..rng.gen_range(0, 10_000) {
Expand Down Expand Up @@ -892,24 +898,26 @@ mod tests {
}
}
}
// if let Some(ref mut empty) = serializer.empty() { https://github.com/rust-lang/rust/issues/52706
// empty();
// }
let empty = serializer.empty();
if empty.is_some() {
if let Some(empty) = serializer.empty() {
assert_ne!(queue.len(), 0);
empty.unwrap()();
empty();
} else {
assert_eq!(queue, vec![]);
}
};
}
}

#[test]
fn deserializer() {
let mut rng =
XorShiftRng::from_seed([15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]);
for _ in 0..50_000 {
// hack until https://internals.rust-lang.org/t/idea-allow-to-query-current-optimization-level-using-cfg-opt-level/7089
let iterations = if cfg!(debug_assertions) {
5_000
} else {
50_000
};
for _ in 0..iterations {
let mut deserializer = Deserializer::new();
let mut queue = VecDeque::new();
let mut pipe = VecDeque::new();
Expand Down Expand Up @@ -1017,17 +1025,22 @@ mod tests {
_ => unreachable!(),
}
}
let empty = deserializer.empty();
if empty.is_some() {
empty.unwrap()();
}
if let Some(empty) = deserializer.empty() {
empty();
};
}
}

#[test]
fn both() {
let mut rng = XorShiftRng::from_seed([0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0]);
for _ in 0..50_000 {
// hack until https://internals.rust-lang.org/t/idea-allow-to-query-current-optimization-level-using-cfg-opt-level/7089
let iterations = if cfg!(debug_assertions) {
5_000
} else {
50_000
};
for _ in 0..iterations {
let mut serializer = Serializer::new();
let mut deserializer = Deserializer::new();
let mut queue = VecDeque::new();
Expand Down Expand Up @@ -1135,14 +1148,12 @@ mod tests {
_ => unreachable!(),
}
}
let empty = serializer.empty();
if empty.is_some() {
empty.unwrap()();
}
let empty = deserializer.empty();
if empty.is_some() {
empty.unwrap()();
}
if let Some(empty) = serializer.empty() {
empty();
};
if let Some(empty) = deserializer.empty() {
empty();
};
}
}
}

0 comments on commit 0bf434b

Please sign in to comment.