From d7494165ec7ae507c7340dcaad2e2c95fda5ee11 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 21 May 2015 12:36:59 -0700 Subject: 1414 - traces now robust to new recipes/types --- 003trace.cc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to '003trace.cc') diff --git a/003trace.cc b/003trace.cc index 4b6c0141..ccb3265f 100644 --- a/003trace.cc +++ b/003trace.cc @@ -107,8 +107,7 @@ struct trace_stream { void newline() { if (!curr_stream) return; 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, curr_contents)); + past_lines.push_back(pair(trim(curr_layer), curr_contents)); // preserve indent in contents if (curr_layer == dump_layer || curr_layer == "dump" || dump_layer == "all" || (!Hide_warnings && curr_layer == "warn")) //? if (dump_layer == "all" && (Current_routine->id == 3 || curr_layer == "schedule")) //? 1 @@ -197,12 +196,15 @@ bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expecte string layer, contents; split_layer_contents(expected_lines.at(curr_expected_line), &layer, &contents); for (vector >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { +//? cerr << "AAA " << layer << ' ' << p->first << '\n'; //? 1 if (layer != p->first) continue; - if (contents != p->second) +//? cerr << "BBB ^" << contents << "$ ^" << p->second << "$\n"; //? 1 + if (contents != trim(p->second)) continue; +//? cerr << "CCC\n"; //? 1 ++curr_expected_line; while (curr_expected_line < SIZE(expected_lines) && expected_lines.at(curr_expected_line).empty()) ++curr_expected_line; @@ -213,6 +215,7 @@ bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expecte ++Num_failures; cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << contents << "] in trace:\n"; DUMP(layer); +//? exit(0); //? 1 Passed = false; return false; } @@ -222,11 +225,11 @@ void split_layer_contents(const string& s, string* layer, string* contents) { size_t pos = s.find(delim); if (pos == string::npos) { *layer = ""; - *contents = s; + *contents = trim(s); } else { - *layer = s.substr(0, pos); - *contents = s.substr(pos+SIZE(delim)); + *layer = trim(s.substr(0, pos)); + *contents = trim(s.substr(pos+SIZE(delim))); } } @@ -308,6 +311,19 @@ bool headmatch(const string& s, const string& pat) { return std::mismatch(pat.begin(), pat.end(), s.begin()).first == pat.end(); } +string trim(const string& s) { + string::const_iterator first = s.begin(); + while (first != s.end() && isspace(*first)) + ++first; + if (first == s.end()) return ""; + + string::const_iterator last = --s.end(); + while (last != s.begin() && isspace(*last)) + --last; + ++last; + return string(first, last); +} + :(before "End Includes") #include using std::vector; -- cgit 1.4.1-2-gfad0