Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
3063 - trace handles trailing newlines
Browse files Browse the repository at this point in the history
Unlike other traces, RAISE requires a trailing newline since it might
be printed to screen.
  • Loading branch information
akkartik committed Jul 4, 2013
1 parent e8bbdf4 commit 0d7784e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions 001trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct trace_stream {
past_lines.push_back(pair<string, pair<int, string> >(curr_layer, pair<int, string>(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;
}
Expand All @@ -33,7 +33,7 @@ struct trace_stream {
ostringstream output;
for (vector<pair<string, pair<int, string> > >::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();
}

Expand All @@ -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;
}
};


Expand Down
1 change: 1 addition & 0 deletions 001trace.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0d7784e

Please sign in to comment.