Skip to content

Commit 0e51ef3

Browse files
authored
Merge pull request #5206 from xbauch/feature/fix-report-order
De-randomize assertion ordering in plain report
2 parents bcde700 + ed498df commit 0e51ef3

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

src/goto-checker/report_util.cpp

+45-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, Peter Schrammel
1515

1616
#include <util/json.h>
1717
#include <util/json_irep.h>
18+
#include <util/string2int.h>
1819
#include <util/ui_message.h>
1920
#include <util/xml.h>
2021
#include <util/xml_irep.h>
@@ -188,8 +189,10 @@ get_sorted_properties(const propertiest &properties)
188189
sorted_properties.push_back(p_it);
189190
// now determine an ordering for those goals:
190191
// 1. alphabetical ordering of file name
191-
// 2. numerical ordering of line number
192-
// 3. alphabetical ordering of goal ID
192+
// 2. alphabetical ordering of function name
193+
// 3. numerical ordering of line number
194+
// 4. alphabetical ordering of goal ID
195+
// 5. number ordering of the goal ID number
193196
std::sort(
194197
sorted_properties.begin(),
195198
sorted_properties.end(),
@@ -198,11 +201,49 @@ get_sorted_properties(const propertiest &properties)
198201
const auto &p2 = pit2->second.pc->source_location;
199202
if(p1.get_file() != p2.get_file())
200203
return id2string(p1.get_file()) < id2string(p2.get_file());
201-
else if(!p1.get_line().empty() && !p2.get_line().empty())
204+
if(p1.get_function() != p2.get_function())
205+
return id2string(p1.get_function()) < id2string(p2.get_function());
206+
else if(
207+
!p1.get_line().empty() && !p2.get_line().empty() &&
208+
p1.get_line() != p2.get_line())
202209
return std::stoul(id2string(p1.get_line())) <
203210
std::stoul(id2string(p2.get_line()));
211+
212+
const auto split_property_id =
213+
[](const irep_idt &property_id) -> std::pair<std::string, std::size_t> {
214+
const auto property_string = id2string(property_id);
215+
const auto last_dot = property_string.rfind('.');
216+
std::string property_name;
217+
std::string property_number;
218+
if(last_dot == std::string::npos)
219+
{
220+
property_name = "";
221+
property_number = property_string;
222+
}
223+
else
224+
{
225+
property_name = property_string.substr(0, last_dot);
226+
property_number = property_string.substr(last_dot + 1);
227+
}
228+
const auto maybe_number = string2optional_size_t(property_number);
229+
if(maybe_number.has_value())
230+
return std::make_pair(property_name, *maybe_number);
231+
else
232+
return std::make_pair(property_name, 0);
233+
};
234+
235+
const auto left_split = split_property_id(pit1->first);
236+
const auto left_id_name = left_split.first;
237+
const auto left_id_number = left_split.second;
238+
239+
const auto right_split = split_property_id(pit2->first);
240+
const auto right_id_name = left_split.first;
241+
const auto right_id_number = left_split.second;
242+
243+
if(left_id_name != right_id_name)
244+
return left_id_name < right_id_name;
204245
else
205-
return id2string(pit1->first) < id2string(pit2->first);
246+
return left_id_number < right_id_number;
206247
});
207248
return sorted_properties;
208249
}

0 commit comments

Comments
 (0)