Skip to content

Commit c110dcf

Browse files
committed
Fix printing of SMT data structures in failed unit tests
The operator needed for the printing is defined in `smt_to_smt2_string.cpp`, but it needs to be forward declared for the catch framework to find and use it, instead of printing SMT data structures as `{?}`. A regression test of a failing unit test is included in this PR to ensure that this functionality for fault finding of failing unit tests works as intended.
1 parent 24e9d5f commit c110dcf

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
[smt_error_printing]
3+
4+
Bool \=\= \(_ BitVec 8\)
5+
\(_ bv42 8\) \=\= false
6+
\(check\-sat\) \=\= \(set\-logic ALL\)
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
\{\?\}
11+
--
12+
Test that when unit tests fail on mismatching smt data structures, the ireps are
13+
pretty-printed and not printed as catch's default of {?}.

unit/solvers/smt2_incremental/smt_to_smt2_string.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,16 @@ TEST_CASE("SMT exists term to string conversion", "[core][smt2_incremental]")
244244
"(exists ((i (_ BitVec 8)) (j Bool)) (or (= i i) j))");
245245
}
246246
}
247+
248+
// This test is expected to fail so that we can test the error printing of the
249+
// unit test framework for regressions. It is not included in the [core] or
250+
// default set of tests, so that the usual output is not polluted with
251+
// irrelevant error messages.
252+
TEST_CASE(
253+
"Catch2 printing of SMT data structures for test failures.",
254+
"[smt_error_printing]" XFAIL)
255+
{
256+
CHECK(smt_bool_sortt{} == smt_bit_vector_sortt{8});
257+
CHECK(smt_bit_vector_constant_termt{42, 8} == smt_bool_literal_termt{false});
258+
CHECK(smt_check_sat_commandt{} == smt_set_logic_commandt{smt_logic_allt{}});
259+
}

unit/testing-utils/use_catch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ Author: Michael Tautschnig
4242
class irept;
4343
std::ostream &operator<<(std::ostream &os, const irept &value);
4444

45+
#include <solvers/smt2_incremental/smt_to_smt2_string.h>
46+
4547
#endif // CPROVER_TESTING_UTILS_USE_CATCH_H

0 commit comments

Comments
 (0)