Skip to content

Commit

Permalink
buff unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Sep 2, 2024
1 parent 1453507 commit 32eaa25
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
43 changes: 39 additions & 4 deletions core/src/utils/racy_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,52 @@ where

#[cfg(test)]
mod tests {
use alloc::vec::Vec;

use super::*;

#[test]
fn test_lazylock_copy() {
fn test_racy_lock_copy() {
// Lock a copy type and validate value.
let lock = RacyLock::new(|| 42);
assert_eq!(*lock, 42);
}

#[test]
fn test_lazylock_move() {
let lock = RacyLock::new(|| vec![1, 2, 3]);
assert_eq!(*lock, vec![1, 2, 3]);
fn test_racy_lock_clone() {
// Lock a no copy type.
let lock = RacyLock::new(|| Vec::from([1, 2, 3]));

// Use the value so that the compiler forces us to clone.
let mut v = lock.clone();
v.push(4);

// Validate the value.
assert_eq!(v, Vec::from([1, 2, 3, 4]));
}

#[test]
fn test_racy_lock_static() {
// Create a static lock.
static VEC: RacyLock<Vec<i32>> = RacyLock::new(|| Vec::from([1, 2, 3]));

// Validate that the address of the value does not change.
let addr = &*VEC as *const Vec<i32>;
for _ in 0..5 {
assert_eq!(*VEC, [1, 2, 3]);
assert_eq!(addr, &(*VEC) as *const Vec<i32>)
}
}

#[test]
fn lazy_type_inference() {
// Check that we can infer `T` from closure's type.
let _ = RacyLock::new(|| ());
}

#[test]
fn is_sync_send() {
fn assert_traits<T: Send + Sync>() {}
assert_traits::<RacyLock<Vec<i32>>>();
}
}
2 changes: 1 addition & 1 deletion processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std = ["vm-core/std", "winter-prover/std"]

[dependencies]
miden-air = { package = "miden-air", path = "../air", version = "0.10", default-features = false }
tracing = { version = "0.1", default-features = false, features = [ "attributes", ] }
tracing = { version = "0.1", default-features = false, features = ["attributes"] }
vm-core = { package = "miden-core", path = "../core", version = "0.10", default-features = false }
winter-prover = { package = "winter-prover", version = "0.9", default-features = false }

Expand Down

0 comments on commit 32eaa25

Please sign in to comment.