From 51d61b6a207682edd514cb8c4cee70e52ae0ca32 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Sun, 25 Jun 2023 20:39:10 -0700 Subject: [PATCH] test utilities: `advance_test_rng_seed_to_multiple_of` function --- tests/common/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 028bbec34..00b333e93 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -275,6 +275,18 @@ impl TestEnvironment { }) .to_string() } + + /// Used before mutating operations to create more predictable commit ids + /// and change ids in tests + /// + /// `test_env.advance_test_rng_seed_to_multiple_of(200_000)` can be inserted + /// wherever convenient throughout your test. If desired, you can have + /// "subheadings" with steps of (e.g.) 10_000, 500, 25. + pub fn advance_test_rng_seed_to_multiple_of(&self, step: i64) { + assert!(step > 0, "step must be >0, got {step}"); + let mut command_number = self.command_number.borrow_mut(); + *command_number = step * (*command_number / step) + step; + } } pub fn get_stdout_string(assert: &assert_cmd::assert::Assert) -> String {