diff options
author | Sean Silva <silvas@purdue.edu> | 2012-11-19 23:21:47 +0000 |
---|---|---|
committer | Sean Silva <silvas@purdue.edu> | 2012-11-19 23:21:47 +0000 |
commit | aba8270dbad556b667db943f5abff63be89e2602 (patch) | |
tree | 74040216e1ea4722c01ed4ed7f98093d913c0248 /llvm/unittests | |
parent | 3c0c536300df007927879eaed4835b0b4cc3f3e8 (diff) | |
download | bcm5719-llvm-aba8270dbad556b667db943f5abff63be89e2602.tar.gz bcm5719-llvm-aba8270dbad556b667db943f5abff63be89e2602.zip |
Allow using MemoryBuffers with yaml::Stream directly.
The rationale is to get YAML filenames in diagnostics from
yaml::Stream::printError -- currently the filename is hard-coded as
"YAML" because there's no buffer information available.
Patch by Kim Gräsman!
llvm-svn: 168341
Diffstat (limited to 'llvm/unittests')
-rw-r--r-- | llvm/unittests/Support/YAMLParserTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/unittests/Support/YAMLParserTest.cpp b/llvm/unittests/Support/YAMLParserTest.cpp index 480a5739f44..e9839358a01 100644 --- a/llvm/unittests/Support/YAMLParserTest.cpp +++ b/llvm/unittests/Support/YAMLParserTest.cpp @@ -10,6 +10,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" #include "gtest/gtest.h" @@ -21,6 +22,12 @@ static void SuppressDiagnosticsOutput(const SMDiagnostic &, void *) { // to reduce noise in unit test runs. } +// Assumes Ctx is an SMDiagnostic where Diag can be stored. +static void CollectDiagnosticsOutput(const SMDiagnostic &Diag, void *Ctx) { + SMDiagnostic* DiagOut = static_cast<SMDiagnostic*>(Ctx); + *DiagOut = Diag; +} + // Checks that the given input gives a parse error. Makes sure that an error // text is available and the parse fails. static void ExpectParseError(StringRef Message, StringRef Input) { @@ -182,4 +189,31 @@ TEST(YAMLParser, WorksWithIteratorAlgorithms) { EXPECT_EQ(6, std::distance(Array->begin(), Array->end())); } +TEST(YAMLParser, DefaultDiagnosticFilename) { + SourceMgr SM; + + SMDiagnostic GeneratedDiag; + SM.setDiagHandler(CollectDiagnosticsOutput, &GeneratedDiag); + + // When we construct a YAML stream over an unnamed string, + // the filename is hard-coded as "YAML". + yaml::Stream UnnamedStream("[]", SM); + UnnamedStream.printError(UnnamedStream.begin()->getRoot(), "Hello, World!"); + EXPECT_EQ("YAML", GeneratedDiag.getFilename()); +} + +TEST(YAMLParser, DiagnosticFilenameFromBufferID) { + SourceMgr SM; + + SMDiagnostic GeneratedDiag; + SM.setDiagHandler(CollectDiagnosticsOutput, &GeneratedDiag); + + // When we construct a YAML stream over a named buffer, + // we get its ID as filename in diagnostics. + MemoryBuffer* Buffer = MemoryBuffer::getMemBuffer("[]", "buffername.yaml"); + yaml::Stream Stream(Buffer, SM); + Stream.printError(Stream.begin()->getRoot(), "Hello, World!"); + EXPECT_EQ("buffername.yaml", GeneratedDiag.getFilename()); +} + } // end namespace llvm |