memscope_rs/core/
test_optimized_locks.rs1#[cfg(test)]
4mod tests {
5 use crate::core::scope_tracker::{get_global_scope_tracker, ScopeGuard};
6
7 #[test]
8 fn test_optimized_scope_tracker_basic() {
9 let tracker = get_global_scope_tracker();
10
11 let scope_id = tracker
13 .enter_scope("test_scope".to_string())
14 .expect("Failed to enter scope");
15
16 tracker
18 .associate_variable("test_var".to_string(), 64)
19 .expect("Failed to track allocation");
20
21 tracker.exit_scope(scope_id).expect("Failed to exit scope");
23
24 let analysis = tracker
26 .get_scope_analysis()
27 .expect("Failed to get scope analysis");
28 assert!(analysis.total_scopes > 0);
29 }
30
31 #[test]
32 fn test_scope_guard_raii() {
33 let result = std::panic::catch_unwind(|| {
35 let _guard = ScopeGuard::enter("raii_test_scope").expect("Failed to enter RAII scope");
36 true
38 });
39
40 assert!(
41 result.is_ok(),
42 "ScopeGuard creation and drop should not panic"
43 );
44
45 let result2 = std::panic::catch_unwind(|| {
47 let _guard1 =
48 ScopeGuard::enter("raii_test_scope_1").expect("Failed to enter RAII scope 1");
49 let _guard2 =
50 ScopeGuard::enter("raii_test_scope_2").expect("Failed to enter RAII scope 2");
51 true
53 });
54
55 assert!(
56 result2.is_ok(),
57 "Multiple ScopeGuards should work correctly"
58 );
59 }
60}