From 0d7784e1829acaa38c4a54c2979464ddab3e60f2 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 4 Jul 2013 13:04:23 -0700 Subject: [PATCH] 3063 - trace handles trailing newlines Unlike other traces, RAISE requires a trailing newline since it might be printed to screen. --- 001trace.cc | 9 +++++++-- 001trace.test.cc | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/001trace.cc b/001trace.cc index 563a203a..c6d2354d 100644 --- a/001trace.cc +++ b/001trace.cc @@ -23,7 +23,7 @@ struct trace_stream { past_lines.push_back(pair >(curr_layer, pair(frame[curr_layer], curr_stream->str()))); if (curr_layer == dump_layer || curr_layer == "dump" || (!Hide_warnings && curr_layer == "warn")) - cerr << frame[curr_layer] << ": " << curr_stream->str() << '\n'; + cerr << frame[curr_layer] << ": " << with_newline(curr_stream->str()); delete curr_stream; curr_stream = NULL; } @@ -33,7 +33,7 @@ struct trace_stream { ostringstream output; for (vector > >::iterator p = past_lines.begin(); p != past_lines.end(); ++p) if (layer.empty() || prefix_match(layer, p->first)) - output << p->first << "/" << p->second.first << ": " << p->second.second << '\n'; + output << p->first << "/" << p->second.first << ": " << with_newline(p->second.second); return output.str(); } @@ -50,6 +50,11 @@ struct trace_stream { } dump.close(); } + + string with_newline(string s) { + if (s[s.size()-1] != '\n') return s+'\n'; + return s; + } }; diff --git a/001trace.test.cc b/001trace.test.cc index a3a2e36c..ae4eadce 100644 --- a/001trace.test.cc +++ b/001trace.test.cc @@ -97,6 +97,7 @@ void test_trace_supports_count2() { CHECK_EQ(trace_count("test layer 1"), 2); } +// pending: readable_contents() adds newline if necessary. // pending: RAISE also prints to stderr. // pending: RAISE doesn't print to stderr if Hide_warnings is set. // pending: RAISE prints to stderr if Trace_stream is NULL.