Skip to content

Commit f639b89

Browse files
author
Thomas Kiley
committed
Tidy up the unit test so easier to see intent
1 parent 4a23411 commit f639b89

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

unit/goto-programs/structured_trace_util.cpp

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,53 @@ void link_edges(goto_programt::targett source, goto_programt::targett target)
1616
target->incoming_edges.insert(source);
1717
}
1818

19+
source_locationt simple_location(const std::string &file, unsigned line)
20+
{
21+
source_locationt location;
22+
location.set_file(file);
23+
location.set_line(line);
24+
return location;
25+
}
26+
27+
goto_programt::targett add_instruction(
28+
const source_locationt &location,
29+
goto_programt::instructionst &instructions)
30+
{
31+
goto_programt::instructiont instruction;
32+
instruction.location_number = instructions.size();
33+
instruction.source_location = location;
34+
instructions.push_back(instruction);
35+
return std::next(instructions.begin(), instruction.location_number);
36+
}
37+
1938
TEST_CASE("structured_trace_util", "[core][util][trace]")
2039
{
2140
goto_programt::instructionst instructions;
2241

2342
source_locationt nil_location;
2443

25-
source_locationt unrelated_location;
26-
unrelated_location.set_file("foo.c");
27-
unrelated_location.set_line(1);
44+
const source_locationt unrelated_location = simple_location("foo.c", 1);
2845

2946
source_locationt no_file_location;
30-
unrelated_location.set_line(1);
31-
32-
source_locationt basic_location;
33-
basic_location.set_file("test.c");
34-
basic_location.set_line(1);
35-
36-
source_locationt loop_head_location;
37-
loop_head_location.set_file("test.c");
38-
loop_head_location.set_line(2);
47+
no_file_location.set_line(1);
3948

40-
source_locationt back_edge_location;
41-
back_edge_location.set_file("test.c");
42-
back_edge_location.set_line(3);
49+
const source_locationt basic_location = simple_location("test.c", 1);
50+
const source_locationt loop_head_location = simple_location("test.c", 2);
51+
const source_locationt back_edge_location = simple_location("test.c", 3);
4352

4453
// 0 # normal_location
54+
add_instruction(basic_location, instructions);
4555
// 1 # loop_head
56+
add_instruction(loop_head_location, instructions);
4657
// 2: goto 1 # back_edge
58+
const auto back_edge = add_instruction(back_edge_location, instructions);
59+
back_edge->type = GOTO;
4760
// 3: no_location
48-
// 4: no_file
49-
goto_programt::instructiont normal_instruction;
50-
normal_instruction.location_number = 0;
51-
normal_instruction.source_location = basic_location;
52-
instructions.push_back(normal_instruction);
53-
54-
goto_programt::instructiont loop_head;
55-
loop_head.location_number = 1;
56-
loop_head.source_location = loop_head_location;
57-
instructions.push_back(loop_head);
58-
59-
goto_programt::instructiont back_edge;
60-
back_edge.source_location = back_edge_location;
61-
back_edge.location_number = 2;
62-
back_edge.type = GOTO;
63-
instructions.push_back(back_edge);
64-
6561
goto_programt::instructiont no_location;
6662
no_location.location_number = 3;
6763
instructions.push_back(no_location);
68-
69-
goto_programt::instructiont no_file;
70-
no_file.location_number = 4;
71-
no_file.source_location = no_file_location;
72-
instructions.push_back(no_file);
64+
// 4: no_file
65+
add_instruction(no_file_location, instructions);
7366

7467
link_edges(
7568
std::next(instructions.begin(), 2), std::next(instructions.begin(), 1));
@@ -133,7 +126,7 @@ TEST_CASE("structured_trace_util", "[core][util][trace]")
133126
goto_trace_stept step;
134127
step.step_nr = 1;
135128
step.thread_nr = 2;
136-
step.hidden = true;
129+
step.hidden = false;
137130
step.pc = std::next(instructions.begin(), 1);
138131
SECTION("Simple step")
139132
{
@@ -142,7 +135,7 @@ TEST_CASE("structured_trace_util", "[core][util][trace]")
142135
REQUIRE(parsed_step);
143136
REQUIRE(parsed_step->step_number == 1);
144137
REQUIRE(parsed_step->thread_number == 2);
145-
REQUIRE(parsed_step->hidden);
138+
REQUIRE_FALSE(parsed_step->hidden);
146139
REQUIRE(parsed_step->kind == default_step_kindt::LOOP_HEAD);
147140
REQUIRE(parsed_step->location == loop_head_location);
148141
}
@@ -153,7 +146,7 @@ TEST_CASE("structured_trace_util", "[core][util][trace]")
153146
REQUIRE(parsed_step);
154147
REQUIRE(parsed_step->step_number == 1);
155148
REQUIRE(parsed_step->thread_number == 2);
156-
REQUIRE(parsed_step->hidden);
149+
REQUIRE_FALSE(parsed_step->hidden);
157150
REQUIRE(parsed_step->kind == default_step_kindt::LOOP_HEAD);
158151
REQUIRE(parsed_step->location == loop_head_location);
159152
}

0 commit comments

Comments
 (0)