@@ -49,4 +49,115 @@ mod tests {
49
49
// Exit the bash session.
50
50
dbg_session. send_line ( "exit" ) . expect ( "Failed to quit bash session" ) ;
51
51
}
52
+
53
+ #[ test]
54
+ fn debugger_expected_call_stack ( ) {
55
+ let nargo_bin =
56
+ cargo_bin ( "nargo" ) . into_os_string ( ) . into_string ( ) . expect ( "Cannot parse nargo path" ) ;
57
+
58
+ let timeout_seconds = 30 ;
59
+ let mut dbg_session =
60
+ spawn_bash ( Some ( timeout_seconds * 1000 ) ) . expect ( "Could not start bash session" ) ;
61
+
62
+ let test_program_path = std:: path:: Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
63
+ . join ( "../../test_programs/execution_success/regression_7195" ) ;
64
+ let test_program_dir = test_program_path. display ( ) ;
65
+
66
+ // Start debugger and test that it loads for the given program.
67
+ dbg_session
68
+ . execute (
69
+ & format ! (
70
+ "{nargo_bin} debug --raw-source-printing true --program-dir {test_program_dir} --force-brillig --expression-width 3"
71
+ ) ,
72
+ ".*\\ Starting debugger.*" ,
73
+ )
74
+ . expect ( "Could not start debugger" ) ;
75
+
76
+ let num_steps = 16 ;
77
+ for _ in 1 ..=num_steps {
78
+ // While running the debugger, issue a "next" cmd,
79
+ // which should run to the program to the next source line given
80
+ // we haven't set any breakpoints.
81
+ // ">" is the debugger's prompt, so finding one
82
+ // after running "next" indicates that the
83
+ // debugger has not panicked for this step.
84
+ dbg_session
85
+ . send_line ( "next" )
86
+ . expect ( "Debugger panicked while attempting to step through program." ) ;
87
+ dbg_session
88
+ . exp_string ( ">" )
89
+ . expect ( "Failed while waiting for debugger to step through program." ) ;
90
+ }
91
+
92
+ let mut lines = vec ! [ ] ;
93
+ while let Ok ( line) = dbg_session. read_line ( ) {
94
+ if !( line. starts_with ( ">next" ) || line. starts_with ( "At " ) || line. starts_with ( "..." ) ) {
95
+ lines. push ( line) ;
96
+ }
97
+ }
98
+
99
+ let lines_expected_to_contain: Vec < & str > = vec ! [
100
+ "> next" ,
101
+ " let x = unsafe { baz(x) };" ,
102
+ "unconstrained fn baz(x: Field) -> Field {" ,
103
+ "> next" ,
104
+ " let x = unsafe { baz(x) };" ,
105
+ "unconstrained fn baz(x: Field) -> Field {" ,
106
+ "> next" ,
107
+ " let x = unsafe { baz(x) };" ,
108
+ "}" ,
109
+ "> next" ,
110
+ " let x = unsafe { baz(x) };" ,
111
+ "> next" ,
112
+ " foo(x);" ,
113
+ "fn foo(x: Field) {" ,
114
+ "> next" ,
115
+ " foo(x);" ,
116
+ "fn foo(x: Field) {" ,
117
+ "> next" ,
118
+ " foo(x);" ,
119
+ " let y = unsafe { baz(x) };" ,
120
+ "unconstrained fn baz(x: Field) -> Field {" ,
121
+ "> next" ,
122
+ " foo(x);" ,
123
+ " let y = unsafe { baz(x) };" ,
124
+ "unconstrained fn baz(x: Field) -> Field {" ,
125
+ "> next" ,
126
+ " foo(x);" ,
127
+ " let y = unsafe { baz(x) };" ,
128
+ "}" ,
129
+ "> next" ,
130
+ " foo(x);" ,
131
+ " let y = unsafe { baz(x) };" ,
132
+ "> next" ,
133
+ " foo(x);" ,
134
+ " bar(y);" ,
135
+ "fn bar(y: Field) {" ,
136
+ "> next" ,
137
+ " foo(x);" ,
138
+ " bar(y);" ,
139
+ "fn bar(y: Field) {" ,
140
+ "> next" ,
141
+ " foo(x);" ,
142
+ " bar(y);" ,
143
+ " assert(y != 0);" ,
144
+ ] ;
145
+
146
+ for ( line, line_expected_to_contain) in lines. into_iter ( ) . zip ( lines_expected_to_contain) {
147
+ let ascii_line: String = line. chars ( ) . filter ( char:: is_ascii) . collect ( ) ;
148
+ let line_expected_to_contain = line_expected_to_contain. trim_start ( ) ;
149
+ assert ! (
150
+ ascii_line. contains( line_expected_to_contain) ,
151
+ "{:?}\n did not contain\n {:?}" ,
152
+ ascii_line,
153
+ line_expected_to_contain,
154
+ ) ;
155
+ }
156
+
157
+ // Run the "quit" command
158
+ dbg_session. send_line ( "quit" ) . expect ( "Failed to quit debugger" ) ;
159
+
160
+ // Exit the bash session.
161
+ dbg_session. send_line ( "exit" ) . expect ( "Failed to quit bash session" ) ;
162
+ }
52
163
}
0 commit comments