Skip to content

Commit 4784a86

Browse files
authored
Merge pull request #506 from ethereum/smt_cex
Prepare SMT comparison for counterexamples
2 parents 94e1b7e + 0df18f6 commit 4784a86

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

test/smtcallback.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function collectErrors (solOutput) {
2525
return errors;
2626
}
2727

28-
function expectErrors (errors, expectations) {
28+
function expectErrors (expectations, errors, ignoreCex) {
2929
if (errors.length !== expectations.length) {
3030
return false;
3131
}
@@ -34,8 +34,19 @@ function expectErrors (errors, expectations) {
3434
if (errors[i].includes('Error trying to invoke SMT solver') || expectations[i].includes('Error trying to invoke SMT solver')) {
3535
continue;
3636
}
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])) {
3950
return false;
4051
}
4152
}
@@ -157,7 +168,8 @@ tape('SMTCheckerCallback', function (t) {
157168
}
158169
tests[sources[i]] = {
159170
expectations: expected,
160-
solidity: { test: { content: preamble + source } }
171+
solidity: { test: { content: preamble + source } },
172+
ignoreCex: source.includes('// SMTIgnoreCex: yes')
161173
};
162174
}
163175

@@ -201,7 +213,7 @@ tape('SMTCheckerCallback', function (t) {
201213
}
202214

203215
// Compare expected vs obtained errors
204-
st.ok(expectErrors(test.expectations, test.errors));
216+
st.ok(expectErrors(test.expectations, test.errors, test.ignoreCex));
205217
}
206218

207219
st.end();

0 commit comments

Comments
 (0)