Skip to content

Commit 690b606

Browse files
Merge pull request #2039 from peterschrammel/fix-duplicate-msg-json-ui
Fix duplicate message output in json-ui
2 parents bba17d9 + 822c757 commit 690b606

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

regression/cbmc/json1/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int main()
2+
{
3+
unsigned x;
4+
assert(x==0);
5+
return 0;
6+
}

regression/cbmc/json1/test.desc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--json-ui --stop-on-fail
4+
activate-multi-line-match
5+
EXIT=10
6+
SIGNAL=0
7+
\[\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 \},
8+
\]\n \},\n \{\n "messageText": "VERIFICATION FAILED",\n "messageType": "STATUS-MESSAGE"\n \},\n \{\n "cProverStatus": "failure"\n \}\n\]
9+
--
10+
--
11+
The purpose of this test is to catch duplicate output of messages and
12+
output of empty messages on flushing the message stream.

src/util/message.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ class messaget
209209

210210
mstreamt &operator << (const xmlt &data)
211211
{
212-
*this << eom; // force end of previous message
212+
if(this->tellp() > 0)
213+
*this << eom; // force end of previous message
213214
if(message.message_handler)
214215
{
215216
message.message_handler->print(message_level, data);
@@ -219,7 +220,8 @@ class messaget
219220

220221
mstreamt &operator << (const json_objectt &data)
221222
{
222-
*this << eom; // force end of previous message
223+
if(this->tellp() > 0)
224+
*this << eom; // force end of previous message
223225
if(message.message_handler)
224226
{
225227
message.message_handler->print(message_level, data);
@@ -243,7 +245,8 @@ class messaget
243245
/// Returns a reference to the top-level JSON array stream
244246
json_stream_arrayt &json_stream()
245247
{
246-
*this << eom; // force end of previous message
248+
if(this->tellp() > 0)
249+
*this << eom; // force end of previous message
247250
return message.message_handler->get_json_stream();
248251
}
249252

src/util/ui_message.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,6 @@ void ui_message_handlert::json_ui_msg(
294294
const std::string timestamp = time->stamp();
295295
if(!timestamp.empty())
296296
result["timestamp"] = json_stringt(timestamp);
297-
298-
// By convention a leading comma is created by every new array entry.
299-
// The first entry is generated in the constructor and does not have
300-
// a trailing comma.
301-
std::cout << ",\n" << result;
302297
}
303298

304299
void ui_message_handlert::flush(unsigned level)

0 commit comments

Comments
 (0)