diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-04-12 23:29:34 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-04-12 23:29:34 -0700 |
commit | d03028a3035fc514a694a89dcec9429625c9217c (patch) | |
tree | 3e375c345803e175fe390d0124a0084b834423b7 /cpp | |
parent | 0f996b7ba88f988e961a644bb85e3e3b5afe4a41 (diff) | |
download | mu-d03028a3035fc514a694a89dcec9429625c9217c.tar.gz |
1057
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/002trace | 13 | ||||
-rw-r--r-- | cpp/002trace.tests | 5 |
2 files changed, 10 insertions, 8 deletions
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<string, pair<int, string> >(curr_layer, pair<int, string>(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<string, pair<int, string> >(curr_layer, pair<int, string>(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<pair<string, pair<int, string> > >::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", ""); } |