Before this patch, the diagnostic message is printed to errs() directly, which makes it difficult to use FailedWithMessage() in unit testing.
In this patch, we add a custom error handler for YAMLParser, which helps collect diagnostic messages and make it easy to use FailedWithMessage() to check error messages.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for this! I just want to make sure that the normal error message hasn't degraded as a result. Does yaml2obj produce the same full error message as before?
DWARFYAML::emitDebugSections() isn't used in yaml2obj. It's only used in unit testing. Hence, this patch doesn't affect yaml2obj.
Great, LGTM, with one nit.
llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp | ||
---|---|---|
25 | Since you don't do anything with the expected after this, this can just be EXPECT_THAT_EXPECTED - ASSERT_THAT_EXPECTED terminates the current test rather than allowing it to continue. This isn't relevant currently, but might be important should the test be extended to check the values that have been parsed. I don't think testing the values needs doing in this patch though, since this patch is about error handling. |
Thanks!
llvm/lib/ObjectYAML/DWARFEmitter.cpp | ||
---|---|---|
480 | *static_cast<SMDiagnostic *>(DiagContext) = Diag; |
*static_cast<SMDiagnostic *>(DiagContext) = Diag;