pytorch/test/cpp/jit/test_base.h
Mikhail Zolotukhin 5e7bc26f65 Fix ASSERT_ANY_THROW. (#19321)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/19321
ghimport-source-id: 9efffc36950152105bd0dc13f450161367101410

Differential Revision: D14962184

Pulled By: ZolotukhinM

fbshipit-source-id: 22d602f50eb5e17a3e3f59cc7feb59a8d88df00d
2019-04-16 15:44:53 -07:00

43 lines
1.5 KiB
C++

#pragma once
// This file defines assertion macros that work in both gtest and non-gtest
// builds, and has some common includes.
#include "torch/csrc/jit/ir.h"
#include "torch/csrc/jit/operator.h"
#if defined(USE_GTEST)
#include <gtest/gtest.h>
#include <test/cpp/common/support.h>
#else
#include "c10/util/Exception.h"
#define ASSERT_EQ(x, y) AT_ASSERT((x) == (y))
#define ASSERT_NE(x, y) AT_ASSERT((x) != (y))
#define ASSERT_TRUE AT_ASSERT
#define ASSERT_FALSE(x) ASSERT_TRUE(!(x))
#define ASSERT_THROWS_WITH(statement, substring) \
try { \
(void)statement; \
ASSERT_TRUE(false); \
} catch (const std::exception& e) { \
ASSERT_NE(std::string(e.what()).find(substring), std::string::npos); \
}
#define ASSERT_ANY_THROW(statement) \
{ \
bool threw = false; \
try { \
(void)statement; \
} catch (const std::exception& e) { \
threw = true; \
} \
ASSERT_TRUE(threw); \
}
#endif // defined(USE_GTEST)
static inline bool isSandcastle() {
return (
(std::getenv("SANDCASTLE")) ||
(std::getenv("TW_JOB_USER") &&
std::string(std::getenv("TW_JOB_USER")) == "sandcastle"));
}