From 47f1dbe56c8dbc1498ee5fae87458b68ba30ec58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20H=C3=B8rl=C3=BCck=20Berg?= <36937807+henrikhorluck@users.noreply.github.com> Date: Wed, 5 Jul 2023 01:24:55 +0200 Subject: [PATCH] Make test_convert seedable, but generate the seed --- fish-rust/src/tests/string_escape.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fish-rust/src/tests/string_escape.rs b/fish-rust/src/tests/string_escape.rs index 96ce18858..f1c5c517f 100644 --- a/fish-rust/src/tests/string_escape.rs +++ b/fish-rust/src/tests/string_escape.rs @@ -164,12 +164,14 @@ fn str2hex(input: &[u8]) -> String { #[test] fn test_convert() { use rand::random; + + let seed: u128 = random::(); + let mut rng = Pcg64Mcg::new(seed); + for _ in 0..ESCAPE_TEST_COUNT { - let mut origin: Vec = vec![]; - while (random::() % ESCAPE_TEST_LENGTH) != 0 { - let byte = random(); - origin.push(byte); - } + let length = rng.gen_range(0..=(2 * ESCAPE_TEST_LENGTH)); + let mut origin: Vec = vec![0; length]; + rng.fill_bytes(&mut origin); let w = str2wcstring(&origin[..]); let n = wcs2string(&w); @@ -178,11 +180,13 @@ fn test_convert() { n, "Conversion cycle of string:\n{:4} chars: {}\n\ produced different string:\n\ - {:4} chars: {}", + {:4} chars: {}\n + Use this seed to reproduce: {}", origin.len(), &str2hex(&origin), n.len(), - &str2hex(&n) + &str2hex(&n), + seed, ); } }