| 28 | using testing::HasSubstr; |
| 29 | |
| 30 | TEST(ErrorUtilTest, StatusScopedDiagnosticHandler) { |
| 31 | MLIRContext context; |
| 32 | auto id = Identifier::get("test.cc", &context); |
| 33 | auto loc = FileLineColLoc::get(id, 0, 0, &context); |
| 34 | |
| 35 | // Test OK without diagnostic gets passed through. |
| 36 | { |
| 37 | TF_ASSERT_OK(StatusScopedDiagnosticHandler(&context).Combine(Status::OK())); |
| 38 | } |
| 39 | |
| 40 | // Verify diagnostics are captured as Unknown status. |
| 41 | { |
| 42 | StatusScopedDiagnosticHandler handler(&context); |
| 43 | emitError(loc) << "Diagnostic message"; |
| 44 | ASSERT_TRUE(tensorflow::errors::IsUnknown(handler.ConsumeStatus())); |
| 45 | } |
| 46 | |
| 47 | // Verify passed in errors are propagated. |
| 48 | { |
| 49 | Status err = tensorflow::errors::Internal("Passed in error"); |
| 50 | ASSERT_TRUE(tensorflow::errors::IsInternal( |
| 51 | StatusScopedDiagnosticHandler(&context).Combine(err))); |
| 52 | } |
| 53 | |
| 54 | // Verify diagnostic reported are append to passed in error. |
| 55 | { |
| 56 | auto function = [&]() { |
| 57 | emitError(loc) << "Diagnostic message reported"; |
| 58 | emitError(loc) << "Second diagnostic message reported"; |
| 59 | return tensorflow::errors::Internal("Passed in error"); |
| 60 | }; |
| 61 | Status s = StatusScopedDiagnosticHandler(&context).Combine(function()); |
| 62 | ASSERT_TRUE(tensorflow::errors::IsInternal(s)); |
| 63 | EXPECT_THAT(s.error_message(), HasSubstr("Passed in error")); |
| 64 | EXPECT_THAT(s.error_message(), HasSubstr("Diagnostic message reported")); |
| 65 | EXPECT_THAT(s.error_message(), |
| 66 | HasSubstr("Second diagnostic message reported")); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | } // namespace |
| 71 | } // namespace mlir |
nothing calls this directly
no test coverage detected