Created
December 15, 2025 14:31
-
-
Save huitseeker/498b879b6a06427f1343dc57df9a34c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::println; | |
| use miden_utils_testing::build_debug_test; | |
| /// Test case to reproduce issue #2404 where only some debug.stack calls print | |
| #[test] | |
| fn test_debug_stack_issue_2404() { | |
| let stack_inputs = [1, 2, 3, 4]; | |
| let source = " | |
| proc set_pool_state | |
| debug.stack.1 | |
| # Some operations | |
| dup.3 | |
| dup.5 | |
| lte | |
| debug.stack.2 | |
| # More operations | |
| dup.4 | |
| dup.3 mul | |
| debug.stack.3 | |
| # More operations | |
| lt | |
| drop drop | |
| debug.stack.4 | |
| # More operations | |
| push.42 swap drop | |
| debug.stack.5 | |
| # More operations | |
| swap.2 drop swap.2 drop drop | |
| debug.stack.6 | |
| # More operations | |
| push.0 swap.1 | |
| debug.stack.7 | |
| # More operations | |
| drop dropw dropw | |
| debug.stack.8 | |
| # End | |
| end | |
| begin | |
| exec.set_pool_state | |
| end"; | |
| // Execute with debug buffer | |
| let test = build_debug_test!(source, &stack_inputs); | |
| let (_stack, output) = test.execute_with_debug_buffer().expect("execution failed"); | |
| println!("Debug output:\n{}", output); | |
| // Count how many debug.stack outputs we got | |
| let debug_count = output.matches("Stack state").count(); | |
| println!("\nTotal debug.stack outputs: {}/8", debug_count); | |
| // This should print 8 times but issue #2404 reports only 2 print | |
| assert_eq!(debug_count, 8, "Expected 8 debug.stack outputs but got {}", debug_count); | |
| } | |
| /// Simpler test with just operations between debug statements | |
| #[test] | |
| fn test_debug_stack_simple_ops() { | |
| let stack_inputs = [1, 2, 3, 4]; | |
| let source = " | |
| begin | |
| debug.stack.1 | |
| push.1 drop | |
| debug.stack.2 | |
| push.2 drop | |
| debug.stack.3 | |
| push.3 drop | |
| debug.stack.4 | |
| push.4 drop | |
| debug.stack.5 | |
| push.5 drop | |
| debug.stack.6 | |
| push.6 drop | |
| debug.stack.7 | |
| push.7 drop | |
| debug.stack.8 | |
| end"; | |
| let test = build_debug_test!(source, &stack_inputs); | |
| let (_stack, output) = test.execute_with_debug_buffer().expect("execution failed"); | |
| println!("Debug output:\n{}", output); | |
| let debug_count = output.matches("Stack state").count(); | |
| println!("\nTotal debug.stack outputs: {}/8", debug_count); | |
| assert_eq!(debug_count, 8, "Expected 8 debug.stack outputs but got {}", debug_count); | |
| } | |
| /// Test with identical operations between debug statements (to test deduplication) | |
| #[test] | |
| fn test_debug_stack_identical_ops() { | |
| let stack_inputs = [1, 2, 3, 4]; | |
| let source = " | |
| begin | |
| debug.stack.1 | |
| dup.0 drop | |
| debug.stack.2 | |
| dup.0 drop | |
| debug.stack.3 | |
| dup.0 drop | |
| debug.stack.4 | |
| dup.0 drop | |
| debug.stack.5 | |
| dup.0 drop | |
| debug.stack.6 | |
| dup.0 drop | |
| debug.stack.7 | |
| dup.0 drop | |
| debug.stack.8 | |
| end"; | |
| let test = build_debug_test!(source, &stack_inputs); | |
| let (_stack, output) = test.execute_with_debug_buffer().expect("execution failed"); | |
| println!("Debug output:\n{}", output); | |
| let debug_count = output.matches("Stack state").count(); | |
| println!("\nTotal debug.stack outputs: {}/8", debug_count); | |
| assert_eq!(debug_count, 8, "Expected 8 debug.stack outputs but got {}", debug_count); | |
| } | |
| /// Test with NO operations between debug statements (most likely to trigger dedup issue) | |
| #[test] | |
| fn test_debug_stack_no_ops_between() { | |
| let stack_inputs = [1, 2, 3, 4]; | |
| let source = " | |
| begin | |
| debug.stack.1 | |
| debug.stack.2 | |
| debug.stack.3 | |
| debug.stack.4 | |
| debug.stack.5 | |
| debug.stack.6 | |
| debug.stack.7 | |
| debug.stack.8 | |
| end"; | |
| let test = build_debug_test!(source, &stack_inputs); | |
| let (_stack, output) = test.execute_with_debug_buffer().expect("execution failed"); | |
| println!("Debug output:\n{}", output); | |
| let debug_count = output.matches("Stack state").count(); | |
| println!("\nTotal debug.stack outputs: {}/8", debug_count); | |
| // If this fails, it means decorators are being deduplicated/lost | |
| assert_eq!(debug_count, 8, "Expected 8 debug.stack outputs but got {}", debug_count); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment