Skip to content

Add pretty printing for exprts in Catch assertions #5358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions unit/testing-utils/catch_pretty_print_expr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************\

Module: Pretty print exprts in Catch assertions

Author: Diffblue Ltd.

\*******************************************************************/

#ifndef CPROVER_TESTING_UTILS_CATCH_PRETTY_PRINT_EXPR_H
#define CPROVER_TESTING_UTILS_CATCH_PRETTY_PRINT_EXPR_H

// this file is expected to be included from `use_catch.hpp`,
// this include is only here to make editor syntax highlighting
// work better
#include <catch/catch.hpp>

#include <ansi-c/expr2c.h>
#include <util/expr.h>
#include <util/namespace.h>
#include <util/symbol_table.h>

namespace Catch // NOLINT
{
template <>
struct StringMaker<exprt> // NOLINT
{
static std::string convert(const exprt &expr)
{
// expr2c doesn’t capture everything that’s contained
// within an expr, but it’s fairly compact.
// expr.pretty() could also work and is more precise,
// but leads to very large output multiple lines which
// makes it hard to see differences.
return expr2c(expr, namespacet{symbol_tablet{}});
}
};
} // namespace Catch

#endif // CPROVER_TESTING_UTILS_CATCH_PRETTY_PRINT_EXPR_H
2 changes: 2 additions & 0 deletions unit/testing-utils/use_catch.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ Author: Michael Tautschnig
/// Add to the end of test tags to mark a test that is expected to fail
#define XFAIL "[.][!shouldfail]"

#include "catch_pretty_print_expr.h"

#endif // CPROVER_TESTING_UTILS_USE_CATCH_H