Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: unittests/Bitcode/NaClMungeTest.cpp

Issue 1310883003: Install notion of diagnostic handler into PNaCl bitcode readers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in patch set 2. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « unittests/Bitcode/NaClMungeTest.h ('k') | unittests/Bitcode/NaClMungeWriteErrorTests.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: unittests/Bitcode/NaClMungeTest.cpp
diff --git a/unittests/Bitcode/NaClMungeTest.cpp b/unittests/Bitcode/NaClMungeTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f5c55354ffd6d092cae72776d125d6bfea90bfa0
--- /dev/null
+++ b/unittests/Bitcode/NaClMungeTest.cpp
@@ -0,0 +1,62 @@
+//===- llvm/unittests/Bitcode/NaClMungeTest.cpp - Test munging utils ------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements stringify methods for munging tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "NaClMungeTest.h"
+#include <regex>
+
+using namespace llvm;
+
+namespace naclmungetest {
+
+static bool matchErrorPrefixForLine(const std::string &Line, std::regex &Exp,
+ std::string &Suffix) {
+ std::smatch Match;
+ if (std::regex_search(Line, Match, Exp)) {
+ // Note: Element 0 is the original string.
+ Suffix = Match[2];
+ return true;
+ }
+ Suffix.clear();
+ return false;
+}
+
+static std::string stripErrorPrefixForLine(const std::string &Line) {
+ std::string Suffix;
+ std::regex ErrorExp("[Ee]rror: (\\(.*\\) )?(.*)");
+ if (matchErrorPrefixForLine(Line, ErrorExp, Suffix))
+ return Suffix;
+ std::regex WarningExp("[Ww]arning: (\\(.*\\) )?(.*)");
+ if (matchErrorPrefixForLine(Line, WarningExp, Suffix))
+ return Suffix;
+ return Line;
+}
+
+std::string stripErrorPrefix(const std::string &Message) {
+ std::string Result;
+ size_t StartPos = 0;
+ size_t NextEoln = Message.find('\n', StartPos);
+ while (NextEoln != std::string::npos) {
+ std::string Line(Message.c_str() + StartPos, NextEoln - StartPos);
+ Result.append(stripErrorPrefixForLine(Line)).push_back('\n');
+ StartPos = NextEoln + 1;
+ NextEoln = Message.find_first_of("\n", StartPos);
+ }
+ if (StartPos < Message.size()) {
+ std::string Remainder(Message.c_str() + StartPos,
+ Message.size() - StartPos);
+ Result.append(stripErrorPrefixForLine(Remainder));
+ }
+ return Result;
+}
+
+} // end of naclmungetest namespace
« no previous file with comments | « unittests/Bitcode/NaClMungeTest.h ('k') | unittests/Bitcode/NaClMungeWriteErrorTests.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698