@@ -25,7 +25,7 @@ function collectErrors (solOutput) {
25
25
return errors ;
26
26
}
27
27
28
- function expectErrors ( errors , expectations ) {
28
+ function expectErrors ( expectations , errors , ignoreCex ) {
29
29
if ( errors . length !== expectations . length ) {
30
30
return false ;
31
31
}
@@ -34,8 +34,19 @@ function expectErrors (errors, expectations) {
34
34
if ( errors [ i ] . includes ( 'Error trying to invoke SMT solver' ) || expectations [ i ] . includes ( 'Error trying to invoke SMT solver' ) ) {
35
35
continue ;
36
36
}
37
- expectations [ i ] = expectations [ i ] . replace ( 'happens here.' , 'happens here' ) ;
38
- if ( ! errors [ i ] . includes ( expectations [ i ] ) ) {
37
+ // Expectations containing counterexamples might have many '\n' in a single line.
38
+ // These are stored escaped in the test format (as '\\n'), whereas the actual error from the compiler has '\n'.
39
+ // Therefore we need to replace '\\n' by '\n' in the expectations.
40
+ // Function `replace` only replaces the first occurrence, and `replaceAll` is not standard yet.
41
+ // Replace all '\\n' by '\n' via split & join.
42
+ expectations [ i ] = expectations [ i ] . split ( '\\n' ) . join ( '\n' ) ;
43
+ if ( ignoreCex ) {
44
+ expectations [ i ] = expectations [ i ] . split ( '\nCounterexample' ) [ 0 ] ;
45
+ errors [ i ] = errors [ i ] . split ( '\nCounterexample' ) [ 0 ] ;
46
+ }
47
+ // `expectations` have "// Warning ... " before the actual message,
48
+ // whereas `errors` have only the message.
49
+ if ( ! expectations [ i ] . includes ( errors [ i ] ) ) {
39
50
return false ;
40
51
}
41
52
}
@@ -157,7 +168,8 @@ tape('SMTCheckerCallback', function (t) {
157
168
}
158
169
tests [ sources [ i ] ] = {
159
170
expectations : expected ,
160
- solidity : { test : { content : preamble + source } }
171
+ solidity : { test : { content : preamble + source } } ,
172
+ ignoreCex : source . includes ( '// SMTIgnoreCex: yes' )
161
173
} ;
162
174
}
163
175
@@ -201,7 +213,7 @@ tape('SMTCheckerCallback', function (t) {
201
213
}
202
214
203
215
// Compare expected vs obtained errors
204
- st . ok ( expectErrors ( test . expectations , test . errors ) ) ;
216
+ st . ok ( expectErrors ( test . expectations , test . errors , test . ignoreCex ) ) ;
205
217
}
206
218
207
219
st . end ( ) ;
0 commit comments