Skip to content

Commit 94c12bc

Browse files
authored
Merge pull request #5358 from hannes-steffenhagen-diffblue/feature/catch-pretty-print-expr
Add pretty printing for exprts in Catch assertions
2 parents c9eb13a + 997b51a commit 94c12bc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*******************************************************************\
2+
3+
Module: Pretty print exprts in Catch assertions
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_TESTING_UTILS_CATCH_PRETTY_PRINT_EXPR_H
10+
#define CPROVER_TESTING_UTILS_CATCH_PRETTY_PRINT_EXPR_H
11+
12+
// this file is expected to be included from `use_catch.hpp`,
13+
// this include is only here to make editor syntax highlighting
14+
// work better
15+
#include <catch/catch.hpp>
16+
17+
#include <ansi-c/expr2c.h>
18+
#include <util/expr.h>
19+
#include <util/namespace.h>
20+
#include <util/symbol_table.h>
21+
22+
namespace Catch // NOLINT
23+
{
24+
template <>
25+
struct StringMaker<exprt> // NOLINT
26+
{
27+
static std::string convert(const exprt &expr)
28+
{
29+
// expr2c doesn’t capture everything that’s contained
30+
// within an expr, but it’s fairly compact.
31+
// expr.pretty() could also work and is more precise,
32+
// but leads to very large output multiple lines which
33+
// makes it hard to see differences.
34+
return expr2c(expr, namespacet{symbol_tablet{}});
35+
}
36+
};
37+
} // namespace Catch
38+
39+
#endif // CPROVER_TESTING_UTILS_CATCH_PRETTY_PRINT_EXPR_H

unit/testing-utils/use_catch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ Author: Michael Tautschnig
3939
/// Add to the end of test tags to mark a test that is expected to fail
4040
#define XFAIL "[.][!shouldfail]"
4141

42+
#include "catch_pretty_print_expr.h"
43+
4244
#endif // CPROVER_TESTING_UTILS_USE_CATCH_H

0 commit comments

Comments
 (0)