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 namespace util { 32 class Status; 33 } // namespace util 34 35 namespace xla { 36 template <typename T> 37 class Array2D; 38 class Literal; 39 40 namespace testing { 41 42 namespace internal_status { GetStatus(const Status & status)43inline const Status& GetStatus(const Status& status) { return status; } 44 45 template <typename T> GetStatus(const StatusOr<T> & status)46inline const Status& GetStatus(const StatusOr<T>& status) { 47 return status.status(); 48 } 49 } // namespace internal_status 50 51 } // namespace testing 52 } // namespace xla 53 54 // The following macros are similar to macros in gmock, but deliberately named 55 // differently in order to avoid conflicts in files which include both. 56 57 // Macros for testing the results of functions that return Status or 58 // StatusOr<T> (for any type T). 59 #define EXPECT_IS_OK(expression) \ 60 EXPECT_EQ(Status::OK(), xla::testing::internal_status::GetStatus(expression)) 61 #define EXPECT_IS_NOT_OK(expression) \ 62 EXPECT_NE(Status::OK(), xla::testing::internal_status::GetStatus(expression)) 63 #undef ASSERT_IS_OK 64 #define ASSERT_IS_OK(expression) \ 65 ASSERT_EQ(Status::OK(), xla::testing::internal_status::GetStatus(expression)) 66 #undef ASSERT_IS_NOT_OK 67 #define ASSERT_IS_NOT_OK(expression) \ 68 ASSERT_NE(Status::OK(), xla::testing::internal_status::GetStatus(expression)) 69 70 #endif // TENSORFLOW_COMPILER_XLA_TEST_HELPERS_H_ 71