Caffe2 - C++ API
A deep learning, cross platform ML framework
test_base.h
1 #pragma once
2 
3 // This file defines assertion macros that work in both gtest and non-gtest
4 // builds, and has some common includes.
5 #include "torch/csrc/jit/ir.h"
6 #include "torch/csrc/jit/operator.h"
7 
8 #if defined(USE_GTEST)
9 #include <gtest/gtest.h>
10 #include <test/cpp/common/support.h>
11 #else
12 #include "c10/util/Exception.h"
13 #define ASSERT_EQ(x, y) AT_ASSERT((x) == (y))
14 #define ASSERT_NE(x, y) AT_ASSERT((x) != (y))
15 #define ASSERT_TRUE AT_ASSERT
16 #define ASSERT_FALSE(x) ASSERT_TRUE(!(x))
17 #define ASSERT_THROWS_WITH(statement, substring) \
18  try { \
19  (void)statement; \
20  ASSERT_TRUE(false); \
21  } catch (const std::exception& e) { \
22  ASSERT_NE(std::string(e.what()).find(substring), std::string::npos); \
23  }
24 #define ASSERT_ANY_THROW(statement) \
25  bool threw = false; \
26  try { \
27  (void)statement; \
28  } catch (const std::exception& e) { \
29  threw = true; \
30  } \
31  ASSERT_TRUE(threw);
32 
33 #endif // defined(USE_GTEST)
34 
35 static inline bool isSandcastle() {
36  return (
37  (std::getenv("SANDCASTLE")) ||
38  (std::getenv("TW_JOB_USER") &&
39  std::string(std::getenv("TW_JOB_USER")) == "sandcastle"));
40 }