Skip to content

Fix duplicate message output in json-ui #2039

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
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
6 changes: 6 additions & 0 deletions regression/cbmc/json1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main()
{
unsigned x;
assert(x==0);
return 0;
}
12 changes: 12 additions & 0 deletions regression/cbmc/json1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--json-ui --stop-on-fail
activate-multi-line-match
EXIT=10
SIGNAL=0
\[\n \{\n "program": "CBMC .*"\n \},\n \{\n "messageText": "CBMC .*",\n "messageType": "STATUS-MESSAGE"\n \},\n \{\n "messageText": "Parsing main\.c",\n "messageType": "STATUS-MESSAGE"\n \},
\]\n \},\n \{\n "messageText": "VERIFICATION FAILED",\n "messageType": "STATUS-MESSAGE"\n \},\n \{\n "cProverStatus": "failure"\n \}\n\]
--
--
The purpose of this test is to catch duplicate output of messages and
output of empty messages on flushing the message stream.
9 changes: 6 additions & 3 deletions src/util/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ class messaget

mstreamt &operator << (const xmlt &data)
{
*this << eom; // force end of previous message
if(this->tellp() > 0)
*this << eom; // force end of previous message
if(message.message_handler)
{
message.message_handler->print(message_level, data);
Expand All @@ -219,7 +220,8 @@ class messaget

mstreamt &operator << (const json_objectt &data)
{
*this << eom; // force end of previous message
if(this->tellp() > 0)
*this << eom; // force end of previous message
if(message.message_handler)
{
message.message_handler->print(message_level, data);
Expand All @@ -243,7 +245,8 @@ class messaget
/// Returns a reference to the top-level JSON array stream
json_stream_arrayt &json_stream()
{
*this << eom; // force end of previous message
if(this->tellp() > 0)
*this << eom; // force end of previous message
return message.message_handler->get_json_stream();
}

Expand Down
5 changes: 0 additions & 5 deletions src/util/ui_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,6 @@ void ui_message_handlert::json_ui_msg(
const std::string timestamp = time->stamp();
if(!timestamp.empty())
result["timestamp"] = json_stringt(timestamp);

// By convention a leading comma is created by every new array entry.
// The first entry is generated in the constructor and does not have
// a trailing comma.
std::cout << ",\n" << result;
}

void ui_message_handlert::flush(unsigned level)
Expand Down