about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/002trace13
-rw-r--r--cpp/002trace.tests5
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", "");
 }