Skip to content

Commit 5cfbeb8

Browse files
Merge pull request #6584 from thomasspriggs/tas/fix_irep_unit_test_printing
Fix `irept` printing in failed unit tests
2 parents 49fb197 + 724de82 commit 5cfbeb8

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

regression/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ endif()
8787
if(NOT WIN32)
8888
add_subdirectory(crangler)
8989
endif()
90+
91+
add_subdirectory(catch-framework)

regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ DIRS = cbmc \
5151
goto-interpreter \
5252
cbmc-sequentialization \
5353
cpp-linter \
54+
catch-framework \
5455
# Empty last line
5556

5657
ifeq ($(OS),Windows_NT)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
add_test_pl_tests(
3+
"$<TARGET_FILE:unit>"
4+
)

regression/catch-framework/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
default: test
2+
3+
test:
4+
@../test.pl -e -p -c "../../../unit/unit_tests"
5+
6+
tests.log: ../test.pl test
7+
8+
clean:
9+
$(RM) tests*.log
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
[irep_error_printing]
3+
4+
REQUIRE\( foo == bar \)
5+
key: value
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
\{\?\}
10+
--
11+
Test that when unit tests fail on mismatching ireps, the ireps are
12+
pretty-printed and not printed as catch's default of {?}.

unit/testing-utils/use_catch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ 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+
class irept;
43+
std::ostream &operator<<(std::ostream &os, const irept &value);
44+
4245
#endif // CPROVER_TESTING_UTILS_USE_CATCH_H

unit/util/irep.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,16 @@ SCENARIO("irept_memory", "[core][utils][irept]")
302302
}
303303
}
304304
}
305+
306+
// This test is expected to fail so that we can test the error printing of the
307+
// unit test framework for regressions. It is not included in the [core] or
308+
// default set of tests, so that the usual output is not polluted with
309+
// irrelevant error messages.
310+
TEST_CASE(
311+
"Catch2 printing of `irept` for test failures.",
312+
"[irep_error_printing]" XFAIL)
313+
{
314+
const irept foo{"foo", irept::named_subt{{"key", irept{"value"}}}, {}};
315+
const irept bar{"bar"};
316+
REQUIRE(foo == bar);
317+
}

0 commit comments

Comments
 (0)