pytorch/test/cpp/jit/test_base.h
Michael Suo 666223df46 [jit] gtestify test_argument_spec.cpp (#45019)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/45019

See https://github.com/pytorch/pytorch/pull/45018 for context.

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM

Differential Revision: D23802298

Pulled By: suo

fbshipit-source-id: 0e36d095d4d81dcd5ebe6d56b3dc469d6d5482d0
2020-09-22 19:44:14 -07:00

47 lines
1.8 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/ir.h"
#include "torch/csrc/jit/runtime/operator.h"
#if defined(USE_GTEST)
#include <gtest/gtest.h>
#include <test/cpp/common/support.h>
#else
#include "c10/util/Exception.h"
// Temporary: we are going to remove these polyfills entirely.
// But for now avoid redefining them if they are already defined in gtest.
// (ASSERT_EQ is a proxy for whether gtest is already present)
#ifndef ASSERT_EQ
#define ASSERT_EQ(x, y) TORCH_INTERNAL_ASSERT((x) == (y))
#define ASSERT_NE(x, y) TORCH_INTERNAL_ASSERT((x) != (y))
#define ASSERT_TRUE TORCH_INTERNAL_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 // ndef(ASSERT_EQ)
#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"));
}