[llvm] r375011 - [Remarks] Use StringRef::contains to avoid differences in error string
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 09:18:12 PDT 2019
Author: thegameg
Date: Wed Oct 16 09:18:12 2019
New Revision: 375011
URL: http://llvm.org/viewvc/llvm-project?rev=375011&view=rev
Log:
[Remarks] Use StringRef::contains to avoid differences in error string
Different OSs have different error strings:
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/39534/steps/ninja%20check%201/logs/FAIL%3A%20LLVM-Unit%3A%3AYAMLRemarks.ParsingBadMeta
Modified:
llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp
Modified: llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp?rev=375011&r1=375010&r2=375011&view=diff
==============================================================================
--- llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp (original)
+++ llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp Wed Oct 16 09:18:12 2019
@@ -63,7 +63,12 @@ bool parseExpectError(const char (&Buf)[
return StringRef(Stream.str()).contains(Error);
}
-void parseExpectErrorMeta(StringRef Buf, const char *Error,
+enum class CmpType {
+ Equal,
+ Contains
+};
+
+void parseExpectErrorMeta(StringRef Buf, const char *Error, CmpType Cmp,
Optional<StringRef> ExternalFilePrependPath = None) {
std::string ErrorStr;
raw_string_ostream Stream(ErrorStr);
@@ -77,7 +82,11 @@ void parseExpectErrorMeta(StringRef Buf,
// Use a case insensitive comparision due to case differences in error strings
// for different OSs.
- EXPECT_EQ(StringRef(Stream.str()).lower(), StringRef(Error).lower());
+ if (Cmp == CmpType::Equal)
+ EXPECT_EQ(StringRef(Stream.str()).lower(), StringRef(Error).lower());
+
+ if (Cmp == CmpType::Contains)
+ EXPECT_TRUE(StringRef(Stream.str()).contains(StringRef(Error)));
}
TEST(YAMLRemarks, ParsingEmpty) {
@@ -684,32 +693,35 @@ TEST(YAMLRemarks, ParsingGoodMeta) {
TEST(YAMLRemarks, ParsingBadMeta) {
parseExpectErrorMeta(StringRef("REMARKSS", 9),
- "Expecting \\0 after magic number.");
+ "Expecting \\0 after magic number.", CmpType::Equal);
- parseExpectErrorMeta(StringRef("REMARKS\0", 8), "Expecting version number.");
+ parseExpectErrorMeta(StringRef("REMARKS\0", 8), "Expecting version number.",
+ CmpType::Equal);
parseExpectErrorMeta(StringRef("REMARKS\0"
"\x09\0\0\0\0\0\0\0",
16),
- "Mismatching remark version. Got 9, expected 0.");
+ "Mismatching remark version. Got 9, expected 0.",
+ CmpType::Equal);
parseExpectErrorMeta(StringRef("REMARKS\0"
"\0\0\0\0\0\0\0\0",
16),
- "Expecting string table size.");
+ "Expecting string table size.", CmpType::Equal);
parseExpectErrorMeta(StringRef("REMARKS\0"
"\0\0\0\0\0\0\0\0"
"\x01\0\0\0\0\0\0\0",
24),
- "Expecting string table.");
+ "Expecting string table.", CmpType::Equal);
parseExpectErrorMeta(StringRef("REMARKS\0"
"\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0"
"/path/",
30),
- "'/path/': No such file or directory");
+ "'/path/': No such file or directory",
+ CmpType::Contains);
parseExpectErrorMeta(StringRef("REMARKS\0"
"\0\0\0\0\0\0\0\0"
@@ -717,5 +729,5 @@ TEST(YAMLRemarks, ParsingBadMeta) {
"/path/",
30),
"'/baddir/path/': No such file or directory",
- StringRef("/baddir/"));
+ CmpType::Contains, StringRef("/baddir/"));
}
More information about the llvm-commits
mailing list