From d03028a3035fc514a694a89dcec9429625c9217c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 12 Apr 2015 23:29:34 -0700 Subject: 1057 --- cpp/002trace | 13 +++++-------- cpp/002trace.tests | 5 +++++ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'cpp') diff --git a/cpp/002trace b/cpp/002trace index 3a25502f..2e906b29 100644 --- a/cpp/002trace +++ b/cpp/002trace @@ -111,10 +111,12 @@ struct trace_stream { // be sure to call this before messing with curr_stream or curr_layer or frame void newline() { if (!curr_stream) return; - past_lines.push_back(pair >(curr_layer, pair(frame[curr_layer], curr_stream->str()))); + string curr_contents = curr_stream->str(); + curr_contents.erase(curr_contents.find_last_not_of("\r\n")+1); + past_lines.push_back(pair >(curr_layer, pair(frame[curr_layer], curr_contents))); if (curr_layer == dump_layer || curr_layer == "dump" || dump_layer == "all" || (!Hide_warnings && curr_layer == "warn")) - cerr << curr_layer << '/' << frame[curr_layer] << ": " << with_newline(curr_stream->str()); + cerr << curr_layer << '/' << frame[curr_layer] << ": " << curr_contents << '\n'; delete curr_stream; curr_stream = NULL; } @@ -127,7 +129,7 @@ struct trace_stream { parse_layer_and_frame(layer, &real_layer, &frame); for (vector > >::iterator p = past_lines.begin(); p != past_lines.end(); ++p) if (layer.empty() || prefix_match(real_layer, p->first)) - output << p->first << "/" << p->second.first << ": " << with_newline(p->second.second); + output << p->first << "/" << p->second.first << ": " << p->second.second << '\n'; return output.str(); } @@ -145,11 +147,6 @@ struct trace_stream { } dump.close(); } - - string with_newline(string s) { - if (s[s.size()-1] != '\n') return s+'\n'; - return s; - } }; diff --git a/cpp/002trace.tests b/cpp/002trace.tests index 00705346..0acf8807 100644 --- a/cpp/002trace.tests +++ b/cpp/002trace.tests @@ -16,6 +16,11 @@ void test_trace_check_ignores_other_lines() { CHECK_TRACE_CONTENTS("test layer 1", "foo"); } +void test_trace_ignores_trailing_whitespace() { + trace("test layer 1") << "foo\n"; + CHECK_TRACE_CONTENTS("test layer 1", "foo"); +} + void test_trace_check_always_finds_empty_lines() { CHECK_TRACE_CONTENTS("test layer 1", ""); } -- cgit 1.4.1-2-gfad0