Skip to content

Commit 1eedc80

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Added unit test
Checks that assert condition evaluates to bool.
1 parent 14757e2 commit 1eedc80

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SRC += analyses/ai/ai.cpp \
1515
analyses/does_remove_const/does_type_preserve_const_correctness.cpp \
1616
analyses/does_remove_const/is_type_at_least_as_const_as.cpp \
1717
goto-programs/goto_trace_output.cpp \
18+
goto-programs/goto_program_assign.cpp \
1819
interpreter/interpreter.cpp \
1920
json/json_parser.cpp \
2021
path_strategies.cpp \
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for goto_program::validate
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <goto-programs/goto_function.h>
10+
#include <testing-utils/catch.hpp>
11+
#include <util/arith_tools.h>
12+
13+
SCENARIO(
14+
"Validation of well-formed assert/assume codes",
15+
"[core][goto-programs][validate]")
16+
{
17+
GIVEN("A program with one assertion")
18+
{
19+
symbol_tablet symbol_table;
20+
const typet type1 = signedbv_typet(32);
21+
symbolt symbol;
22+
irep_idt symbol_name = "a";
23+
symbol.name = symbol_name;
24+
symbol_exprt varx(symbol_name, type1);
25+
exprt val10 = from_integer(10, type1);
26+
plus_exprt x_plus_10(varx, val10);
27+
binary_relation_exprt x_le_10(varx, ID_le, val10);
28+
29+
goto_functiont goto_function;
30+
auto &instructions = goto_function.body.instructions;
31+
instructions.emplace_back(goto_program_instruction_typet::ASSERT);
32+
33+
symbol.type = type1;
34+
symbol_table.insert(symbol);
35+
namespacet ns(symbol_table);
36+
37+
WHEN("Condition evaluates to a Boolean")
38+
{
39+
instructions.back().make_assertion(x_le_10);
40+
THEN("The consistency check succeeds")
41+
{
42+
goto_function.body.validate(ns, validation_modet::INVARIANT);
43+
REQUIRE(true);
44+
}
45+
}
46+
47+
WHEN("Condition does not evaluate to a Boolean")
48+
{
49+
instructions.back().make_assertion(x_plus_10);
50+
51+
THEN("The consistency check fails")
52+
{
53+
bool caught = false;
54+
try
55+
{
56+
goto_function.body.validate(ns, validation_modet::EXCEPTION);
57+
}
58+
catch(incorrect_goto_program_exceptiont &e)
59+
{
60+
caught = true;
61+
}
62+
REQUIRE(caught);
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)