1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_XLA_TEST_HELPERS_H_
17 #define TENSORFLOW_COMPILER_XLA_TEST_HELPERS_H_
18 
19 #include <list>
20 #include <vector>
21 
22 #include "absl/strings/string_view.h"
23 #include "tensorflow/compiler/xla/statusor.h"
24 #include "tensorflow/compiler/xla/types.h"
25 #include "tensorflow/core/platform/protobuf.h"
26 #include "tensorflow/core/platform/regexp.h"
27 #include "tensorflow/core/platform/test.h"
28 
29 // This module contains a minimal subset of gmock functionality just
30 // sufficient to execute the currently existing tests.
31 
32 namespace xla {
33 template <typename T>
34 class Array2D;
35 class Literal;
36 
37 namespace testing {
38 
39 namespace internal_status {
GetStatus(const Status & status)40 inline const Status& GetStatus(const Status& status) { return status; }
41 
42 template <typename T>
GetStatus(const StatusOr<T> & status)43 inline const Status& GetStatus(const StatusOr<T>& status) {
44   return status.status();
45 }
46 }  // namespace internal_status
47 
48 }  // namespace testing
49 }  // namespace xla
50 
51 // The following macros are similar to macros in gmock, but deliberately named
52 // differently in order to avoid conflicts in files which include both.
53 
54 // Macros for testing the results of functions that return Status or
55 // StatusOr<T> (for any type T).
56 #define EXPECT_IS_OK(expression) \
57   EXPECT_EQ(Status::OK(), xla::testing::internal_status::GetStatus(expression))
58 #define EXPECT_IS_NOT_OK(expression) \
59   EXPECT_NE(Status::OK(), xla::testing::internal_status::GetStatus(expression))
60 #undef ASSERT_IS_OK
61 #define ASSERT_IS_OK(expression) \
62   ASSERT_EQ(Status::OK(), xla::testing::internal_status::GetStatus(expression))
63 #undef ASSERT_IS_NOT_OK
64 #define ASSERT_IS_NOT_OK(expression) \
65   ASSERT_NE(Status::OK(), xla::testing::internal_status::GetStatus(expression))
66 
67 #endif  // TENSORFLOW_COMPILER_XLA_TEST_HELPERS_H_
68