Files
pytorch/test/cpp/common/support.h
Dmytro Dzhulgakov 46503a7ac0 Trim libshm deps, move tempfile.h to c10 (#17019)
Summary:
libshm_manager doesn't need to depend on all of libtorch. It only uses tiny tempfile.h which can be moved to c10. I could just duplicate the file too, but it's not worth it as c10 is small enough.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17019

Differential Revision: D14052688

Pulled By: dzhulgakov

fbshipit-source-id: 8797d15f8c7c49c49d40b7ab2f43aa3bf6becb0c
2019-02-13 19:38:35 -08:00

34 lines
1.5 KiB
C++

#pragma once
#include <c10/util/Exception.h>
#include <gtest/gtest.h>
#include <stdexcept>
#include <string>
namespace torch {
namespace test {
#define ASSERT_THROWS_WITH(statement, substring) \
{ \
std::string assert_throws_with_error_message; \
try { \
(void)statement; \
FAIL() << "Expected statement `" #statement \
"` to throw an exception, but it did not"; \
} catch (const c10::Error& e) { \
assert_throws_with_error_message = e.what_without_backtrace(); \
} catch (const std::exception& e) { \
assert_throws_with_error_message = e.what(); \
} \
if (assert_throws_with_error_message.find(substring) == \
std::string::npos) { \
FAIL() << "Error message \"" << assert_throws_with_error_message \
<< "\" did not contain expected substring \"" << substring \
<< "\""; \
} \
}
} // namespace test
} // namespace torch