summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorAlex Bradbury <asb@lowrisc.org>2017-07-17 11:41:30 +0000
committerAlex Bradbury <asb@lowrisc.org>2017-07-17 11:41:30 +0000
commit1684317583f99316024a5e57d7377d8ad9087ffd (patch)
treed087e76bdf920838c178b8fe18fc1927306ba5f1 /llvm/unittests/Support
parent11199b2ee5636b3d3bfd7029474fa7ae99460521 (diff)
downloadbcm5719-llvm-1684317583f99316024a5e57d7377d8ad9087ffd.tar.gz
bcm5719-llvm-1684317583f99316024a5e57d7377d8ad9087ffd.zip
[YAMLTraits] Add filename support to yaml::Input
Summary: The current yaml::Input constructor takes a StringRef of data as its first parameter, discarding any filename information that may have been present when a YAML file was opened. Add an alterate yaml::Input constructor that takes a MemoryBufferRef, which can have a filename associated with it. This leads to clearer diagnostic messages. Sponsored By: DARPA, AFRL Reviewed By: arphaman Differential Revision: https://reviews.llvm.org/D35398 Patch by: Jonathan Anderson (trombonehero) llvm-svn: 308172
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/YAMLIOTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index 5cf0e9d0f5b..120773a0c8d 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -232,6 +232,22 @@ TEST(YAMLIO, TestSequenceMapWriteAndRead) {
}
}
+//
+// Test YAML filename handling.
+//
+static void testErrorFilename(const llvm::SMDiagnostic &Error, void *) {
+ EXPECT_EQ(Error.getFilename(), "foo.yaml");
+}
+
+TEST(YAMLIO, TestGivenFilename) {
+ auto Buffer = llvm::MemoryBuffer::getMemBuffer("{ x: 42 }", "foo.yaml");
+ Input yin(*Buffer, nullptr, testErrorFilename);
+ FooBar Value;
+ yin >> Value;
+
+ EXPECT_TRUE(!!yin.error());
+}
+
//===----------------------------------------------------------------------===//
// Test built-in types
OpenPOWER on IntegriCloud