diff options
author | 2018-04-04 12:08:49 -0700 | |
---|---|---|
committer | 2018-04-04 12:11:49 -0700 | |
commit | 13e103b8f0dcc89673dd0d3d589b976c05c37a09 (patch) | |
tree | 3debee5abeae72842052b360124504c5a62e9779 /tensorflow/core | |
parent | bd540c8c45bf66a9c14af38a272840b47731b91a (diff) |
Replaced calls to deprecated tensorflow::StringPiece methods with their
tensorflow::str_util equivalents.
This will allow the deprecated methods to be removed.
PiperOrigin-RevId: 191627087
Diffstat (limited to 'tensorflow/core')
-rw-r--r-- | tensorflow/core/lib/strings/numbers.cc | 5 | ||||
-rw-r--r-- | tensorflow/core/lib/strings/ordered_code_test.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/lib/strings/scanner.h | 5 | ||||
-rw-r--r-- | tensorflow/core/platform/cloud/BUILD | 2 | ||||
-rw-r--r-- | tensorflow/core/platform/cloud/gcs_file_system.cc | 9 | ||||
-rw-r--r-- | tensorflow/core/platform/cloud/gcs_file_system_test.cc | 17 | ||||
-rw-r--r-- | tensorflow/core/platform/cloud/retrying_file_system_test.cc | 29 | ||||
-rw-r--r-- | tensorflow/core/platform/cloud/retrying_utils_test.cc | 8 | ||||
-rw-r--r-- | tensorflow/core/util/command_line_flags.cc | 20 | ||||
-rw-r--r-- | tensorflow/core/util/device_name_utils_test.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/util/equal_graph_def.cc | 5 | ||||
-rw-r--r-- | tensorflow/core/util/memmapped_file_system.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/util/reporter_test.cc | 2 | ||||
-rw-r--r-- | tensorflow/core/util/tensor_slice_reader_test.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/util/tensor_slice_writer_test.cc | 9 |
15 files changed, 72 insertions, 50 deletions
diff --git a/tensorflow/core/lib/strings/numbers.cc b/tensorflow/core/lib/strings/numbers.cc index 516decc3c0..8f34baa7de 100644 --- a/tensorflow/core/lib/strings/numbers.cc +++ b/tensorflow/core/lib/strings/numbers.cc @@ -23,6 +23,7 @@ limitations under the License. #include <locale> #include <unordered_map> +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/macros.h" @@ -203,7 +204,7 @@ bool safe_strto64(StringPiece str, int64* value) { int64 vlimit = kint64max; int sign = 1; - if (str.Consume("-")) { + if (str_util::ConsumePrefix(&str, "-")) { sign = -1; // Different limit for positive and negative integers. vlimit = kint64min; @@ -265,7 +266,7 @@ bool safe_strto32(StringPiece str, int32* value) { int64 vmax = kint32max; int sign = 1; - if (str.Consume("-")) { + if (str_util::ConsumePrefix(&str, "-")) { sign = -1; // Different max for positive and negative integers. ++vmax; diff --git a/tensorflow/core/lib/strings/ordered_code_test.cc b/tensorflow/core/lib/strings/ordered_code_test.cc index fee8a6f93e..ede9f4d390 100644 --- a/tensorflow/core/lib/strings/ordered_code_test.cc +++ b/tensorflow/core/lib/strings/ordered_code_test.cc @@ -22,6 +22,7 @@ limitations under the License. #include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -128,7 +129,7 @@ void TestWriteAppends(T first, U second) { string encoded_first_only = encoded; OCWriteToString<U>(&encoded, second); EXPECT_NE(encoded, encoded_first_only); - EXPECT_TRUE(StringPiece(encoded).starts_with(encoded_first_only)); + EXPECT_TRUE(str_util::StartsWith(encoded, encoded_first_only)); } template <typename T> diff --git a/tensorflow/core/lib/strings/scanner.h b/tensorflow/core/lib/strings/scanner.h index d3b63357ee..c82e771368 100644 --- a/tensorflow/core/lib/strings/scanner.h +++ b/tensorflow/core/lib/strings/scanner.h @@ -18,6 +18,7 @@ limitations under the License. #include <string> #include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/macros.h" namespace tensorflow { @@ -75,14 +76,14 @@ class Scanner { // Consume the next s.size() characters of the input, if they match <s>. If // they don't match <s>, this is a no-op. Scanner& ZeroOrOneLiteral(StringPiece s) { - cur_.Consume(s); + str_util::ConsumePrefix(&cur_, s); return *this; } // Consume the next s.size() characters of the input, if they match <s>. If // they don't match <s>, then GetResult will ultimately return false. Scanner& OneLiteral(StringPiece s) { - if (!cur_.Consume(s)) { + if (!str_util::ConsumePrefix(&cur_, s)) { error_ = true; } return *this; diff --git a/tensorflow/core/platform/cloud/BUILD b/tensorflow/core/platform/cloud/BUILD index 3ee7be3c4e..be84316c48 100644 --- a/tensorflow/core/platform/cloud/BUILD +++ b/tensorflow/core/platform/cloud/BUILD @@ -85,6 +85,7 @@ cc_library( ":retrying_utils", ":time_util", "//tensorflow/core:framework_headers_lib", + "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "@jsoncpp_git//:jsoncpp", ], @@ -263,6 +264,7 @@ tf_cc_test( deps = [ ":gcs_file_system", ":http_request_fake", + "//tensorflow/core:lib", "//tensorflow/core:test", "//tensorflow/core:test_main", ], diff --git a/tensorflow/core/platform/cloud/gcs_file_system.cc b/tensorflow/core/platform/cloud/gcs_file_system.cc index 1691826483..3c0dc13d75 100644 --- a/tensorflow/core/platform/cloud/gcs_file_system.cc +++ b/tensorflow/core/platform/cloud/gcs_file_system.cc @@ -172,7 +172,7 @@ Status ParseGcsPath(StringPiece fname, bool empty_object_ok, string* bucket, return errors::InvalidArgument("GCS path doesn't contain a bucket name: ", fname); } - objectp.Consume("/"); + str_util::ConsumePrefix(&objectp, "/"); *object = objectp.ToString(); if (!empty_object_ok && object->empty()) { return errors::InvalidArgument("GCS path doesn't contain an object name: ", @@ -535,7 +535,8 @@ class GcsWritableFile : public WritableFile { *uploaded = 0; } else { StringPiece range_piece(received_range); - range_piece.Consume("bytes="); // May or may not be present. + str_util::ConsumePrefix(&range_piece, + "bytes="); // May or may not be present. std::vector<int64> range_parts; if (!str_util::SplitAndParseAsInts(range_piece, '-', &range_parts) || range_parts.size() != 2) { @@ -1172,7 +1173,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, // 'object_prefix', which is part of 'dirname', should be removed from // the beginning of 'name'. StringPiece relative_path(name); - if (!relative_path.Consume(object_prefix)) { + if (!str_util::ConsumePrefix(&relative_path, object_prefix)) { return errors::Internal(strings::StrCat( "Unexpected response: the returned file name ", name, " doesn't match the prefix ", object_prefix)); @@ -1201,7 +1202,7 @@ Status GcsFileSystem::GetChildrenBounded(const string& dirname, } const string& prefix_str = prefix.asString(); StringPiece relative_path(prefix_str); - if (!relative_path.Consume(object_prefix)) { + if (!str_util::ConsumePrefix(&relative_path, object_prefix)) { return errors::Internal( "Unexpected response: the returned folder name ", prefix_str, " doesn't match the prefix ", object_prefix); diff --git a/tensorflow/core/platform/cloud/gcs_file_system_test.cc b/tensorflow/core/platform/cloud/gcs_file_system_test.cc index 8516421614..2fbde9b6a7 100644 --- a/tensorflow/core/platform/cloud/gcs_file_system_test.cc +++ b/tensorflow/core/platform/cloud/gcs_file_system_test.cc @@ -16,6 +16,7 @@ limitations under the License. #include "tensorflow/core/platform/cloud/gcs_file_system.h" #include <fstream> #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/cloud/http_request_fake.h" #include "tensorflow/core/platform/test.h" @@ -584,8 +585,9 @@ TEST(GcsFileSystemTest, NewWritableFile_ResumeUploadAllAttemptsFail) { TF_EXPECT_OK(file->Append("content2")); const auto& status = file->Close(); EXPECT_EQ(errors::Code::ABORTED, status.code()); - EXPECT_TRUE(StringPiece(status.error_message()) - .contains("All 10 retry attempts failed. The last failure: " + EXPECT_TRUE( + str_util::StrContains(status.error_message(), + "All 10 retry attempts failed. The last failure: " "Unavailable: important HTTP error 503")) << status; } @@ -641,13 +643,12 @@ TEST(GcsFileSystemTest, NewWritableFile_UploadReturns410) { const auto& status = file->Close(); EXPECT_EQ(errors::Code::UNAVAILABLE, status.code()); EXPECT_TRUE( - StringPiece(status.error_message()) - .contains( - "Upload to gs://bucket/path/writeable.txt failed, caused by: " - "Not found: important HTTP error 410")) + str_util::StrContains(status.error_message(), + "Upload to gs://bucket/path/writeable.txt failed, " + "caused by: Not found: important HTTP error 410")) << status; - EXPECT_TRUE(StringPiece(status.error_message()) - .contains("when uploading gs://bucket/path/writeable.txt")) + EXPECT_TRUE(str_util::StrContains( + status.error_message(), "when uploading gs://bucket/path/writeable.txt")) << status; } diff --git a/tensorflow/core/platform/cloud/retrying_file_system_test.cc b/tensorflow/core/platform/cloud/retrying_file_system_test.cc index d3f763bb3c..ee6886fef7 100644 --- a/tensorflow/core/platform/cloud/retrying_file_system_test.cc +++ b/tensorflow/core/platform/cloud/retrying_file_system_test.cc @@ -16,6 +16,7 @@ limitations under the License. #include "tensorflow/core/platform/cloud/retrying_file_system.h" #include <fstream> #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -245,7 +246,7 @@ TEST(RetryingFileSystemTest, NewRandomAccessFile_AllRetriesFailed) { char scratch[10]; const auto& status = random_access_file->Read(0, 10, &result, scratch); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -399,7 +400,7 @@ TEST(RetryingFileSystemTest, NewWritableFile_AllRetriesFailed) { // Use it and check the results. const auto& status = writable_file->Sync(); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -428,7 +429,7 @@ TEST(RetryingFileSystemTest, NewReadOnlyMemoryRegionFromFile_AllRetriesFailed) { const auto& status = fs.NewReadOnlyMemoryRegionFromFile("filename.txt", &result); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -454,7 +455,7 @@ TEST(RetryingFileSystemTest, GetChildren_AllRetriesFailed) { std::vector<string> result; const auto& status = fs.GetChildren("gs://path", &result); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -481,7 +482,7 @@ TEST(RetryingFileSystemTest, GetMatchingPaths_AllRetriesFailed) { std::vector<string> result; const auto& status = fs.GetMatchingPaths("gs://path/dir", &result); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -506,7 +507,7 @@ TEST(RetryingFileSystemTest, DeleteFile_AllRetriesFailed) { std::vector<string> result; const auto& status = fs.DeleteFile("gs://path/file.txt"); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -531,7 +532,7 @@ TEST(RetryingFileSystemTest, CreateDir_AllRetriesFailed) { std::vector<string> result; const auto& status = fs.CreateDir("gs://path/newdir"); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -556,7 +557,7 @@ TEST(RetryingFileSystemTest, DeleteDir_AllRetriesFailed) { std::vector<string> result; const auto& status = fs.DeleteDir("gs://path/dir"); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -582,7 +583,7 @@ TEST(RetryingFileSystemTest, GetFileSize_AllRetriesFailed) { uint64 size; const auto& status = fs.GetFileSize("gs://path/file.txt", &size); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -605,7 +606,7 @@ TEST(RetryingFileSystemTest, RenameFile_AllRetriesFailed) { const auto& status = fs.RenameFile("old_name", "new_name"); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -630,7 +631,7 @@ TEST(RetryingFileSystemTest, Stat_AllRetriesFailed) { FileStatistics stat; const auto& status = fs.Stat("file_name", &stat); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -642,7 +643,7 @@ TEST(RetryingFileSystemTest, FileExists_AllRetriesFailed) { const auto& status = fs.FileExists("file_name"); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -677,7 +678,7 @@ TEST(RetryingFileSystemTest, IsDirectory_AllRetriesFailed) { const auto& status = fs.IsDirectory("gs://path/dir"); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } @@ -706,7 +707,7 @@ TEST(RetryingFileSystemTest, DeleteRecursively_AllRetriesFailed) { const auto& status = fs.DeleteRecursively("gs://path/dir", &undeleted_files, &undeleted_dirs); EXPECT_TRUE( - StringPiece(status.error_message()).contains("Retriable error #10")) + str_util::StrContains(status.error_message(), "Retriable error #10")) << status; } diff --git a/tensorflow/core/platform/cloud/retrying_utils_test.cc b/tensorflow/core/platform/cloud/retrying_utils_test.cc index 6eb340e094..1b6527618a 100644 --- a/tensorflow/core/platform/cloud/retrying_utils_test.cc +++ b/tensorflow/core/platform/cloud/retrying_utils_test.cc @@ -16,6 +16,7 @@ limitations under the License. #include "tensorflow/core/platform/cloud/retrying_utils.h" #include <fstream> #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/test.h" @@ -31,10 +32,9 @@ TEST(RetryingUtilsTest, CallWithRetries_RetryDelays) { const auto& status = RetryingUtils::CallWithRetries(f, 500000L, sleep); EXPECT_EQ(errors::Code::ABORTED, status.code()); - EXPECT_TRUE(StringPiece(status.error_message()) - .contains("All 10 retry attempts " - "failed. The last failure: " - "Unavailable: Failed.")) + EXPECT_TRUE(str_util::StrContains( + status.error_message(), + "All 10 retry attempts failed. The last failure: Unavailable: Failed.")) << status; EXPECT_EQ(10, requested_delays.size()); diff --git a/tensorflow/core/util/command_line_flags.cc b/tensorflow/core/util/command_line_flags.cc index 3efc703faf..480ce94fca 100644 --- a/tensorflow/core/util/command_line_flags.cc +++ b/tensorflow/core/util/command_line_flags.cc @@ -17,6 +17,7 @@ limitations under the License. #include <vector> #include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/util/command_line_flags.h" @@ -28,7 +29,9 @@ bool ParseStringFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(string)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; - if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) { + if (str_util::ConsumePrefix(&arg, "--") && + str_util::ConsumePrefix(&arg, flag) && + str_util::ConsumePrefix(&arg, "=")) { *value_parsing_ok = hook(arg.ToString()); return true; } @@ -40,7 +43,9 @@ bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(int32)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; - if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) { + if (str_util::ConsumePrefix(&arg, "--") && + str_util::ConsumePrefix(&arg, flag) && + str_util::ConsumePrefix(&arg, "=")) { char extra; int32 parsed_int32; if (sscanf(arg.data(), "%d%c", &parsed_int32, &extra) != 1) { @@ -60,7 +65,9 @@ bool ParseInt64Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(int64)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; - if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) { + if (str_util::ConsumePrefix(&arg, "--") && + str_util::ConsumePrefix(&arg, flag) && + str_util::ConsumePrefix(&arg, "=")) { char extra; int64 parsed_int64; if (sscanf(arg.data(), "%lld%c", &parsed_int64, &extra) != 1) { @@ -80,7 +87,8 @@ bool ParseBoolFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(bool)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; - if (arg.Consume("--") && arg.Consume(flag)) { + if (str_util::ConsumePrefix(&arg, "--") && + str_util::ConsumePrefix(&arg, flag)) { if (arg.empty()) { *value_parsing_ok = hook(true); return true; @@ -107,7 +115,9 @@ bool ParseFloatFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, const std::function<bool(float)>& hook, bool* value_parsing_ok) { *value_parsing_ok = true; - if (arg.Consume("--") && arg.Consume(flag) && arg.Consume("=")) { + if (str_util::ConsumePrefix(&arg, "--") && + str_util::ConsumePrefix(&arg, flag) && + str_util::ConsumePrefix(&arg, "=")) { char extra; float parsed_float; if (sscanf(arg.data(), "%f%c", &parsed_float, &extra) != 1) { diff --git a/tensorflow/core/util/device_name_utils_test.cc b/tensorflow/core/util/device_name_utils_test.cc index c1bc0f3378..ff9c108f10 100644 --- a/tensorflow/core/util/device_name_utils_test.cc +++ b/tensorflow/core/util/device_name_utils_test.cc @@ -408,7 +408,7 @@ static void MergeDevNamesError(const string& name_a, const string& name_b, DeviceNameUtils::ParsedName target_a = Name(name_a); Status s = DeviceNameUtils::MergeDevNames(&target_a, Name(name_b)); EXPECT_EQ(s.code(), error::INVALID_ARGUMENT); - EXPECT_TRUE(StringPiece(s.error_message()).contains(expected_error_substr)) + EXPECT_TRUE(str_util::StrContains(s.error_message(), expected_error_substr)) << s; } diff --git a/tensorflow/core/util/equal_graph_def.cc b/tensorflow/core/util/equal_graph_def.cc index f1ec497a67..b87dce0dff 100644 --- a/tensorflow/core/util/equal_graph_def.cc +++ b/tensorflow/core/util/equal_graph_def.cc @@ -23,6 +23,7 @@ limitations under the License. #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/lib/hash/hash.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/protobuf.h" @@ -144,7 +145,7 @@ bool EqualNodeDef(const NodeDef& actual, const NodeDef& expected, string* diff, int first_control_input = actual.input_size(); for (int i = 0; i < actual.input_size(); ++i) { - if (StringPiece(actual.input(i)).starts_with("^")) { + if (str_util::StartsWith(actual.input(i), "^")) { first_control_input = i; break; } @@ -240,7 +241,7 @@ uint64 NodeDefHash(const NodeDef& ndef, const EqualGraphDefOptions& options) { // Normal inputs. Order important. int first_control_input = ndef.input_size(); for (int i = 0; i < ndef.input_size(); ++i) { - if (StringPiece(ndef.input(i)).starts_with("^")) { + if (str_util::StartsWith(ndef.input(i), "^")) { first_control_input = i; break; } diff --git a/tensorflow/core/util/memmapped_file_system.cc b/tensorflow/core/util/memmapped_file_system.cc index ea0a381f4f..1fa6b8bec0 100644 --- a/tensorflow/core/util/memmapped_file_system.cc +++ b/tensorflow/core/util/memmapped_file_system.cc @@ -15,6 +15,7 @@ limitations under the License. #include "tensorflow/core/util/memmapped_file_system.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/util/memmapped_file_system.pb.h" @@ -242,7 +243,7 @@ Status MemmappedFileSystem::InitializeFromFile(Env* env, } bool MemmappedFileSystem::IsMemmappedPackageFilename(const string& filename) { - return StringPiece(filename).starts_with(kMemmappedPackagePrefix); + return str_util::StartsWith(filename, kMemmappedPackagePrefix); } namespace { diff --git a/tensorflow/core/util/reporter_test.cc b/tensorflow/core/util/reporter_test.cc index 575c27d4ef..90ea09876e 100644 --- a/tensorflow/core/util/reporter_test.cc +++ b/tensorflow/core/util/reporter_test.cc @@ -29,7 +29,7 @@ namespace { // Tests of all the error paths in log_reader.cc follow: static void ExpectHasSubstr(StringPiece s, StringPiece expected) { - EXPECT_TRUE(StringPiece(s).contains(expected)) + EXPECT_TRUE(str_util::StrContains(s, expected)) << s << " does not contain " << expected; } diff --git a/tensorflow/core/util/tensor_slice_reader_test.cc b/tensorflow/core/util/tensor_slice_reader_test.cc index 010cc36823..3c9590e488 100644 --- a/tensorflow/core/util/tensor_slice_reader_test.cc +++ b/tensorflow/core/util/tensor_slice_reader_test.cc @@ -22,6 +22,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/logging.h" @@ -422,7 +423,7 @@ static void VersionTest(const VersionDef& versions, const string& error) { // Read it back in and verify that we get the expected error TensorSliceReader reader(path, OpenTableTensorSliceReader); EXPECT_TRUE(reader.status().code() == error::INVALID_ARGUMENT && - StringPiece(reader.status().error_message()).starts_with(error)) + str_util::StartsWith(reader.status().error_message(), error)) << "Expected error starting with '" << errors::InvalidArgument(error) << "', got '" << reader.status() << "'"; } diff --git a/tensorflow/core/util/tensor_slice_writer_test.cc b/tensorflow/core/util/tensor_slice_writer_test.cc index ff5bfd65ae..31397f11b6 100644 --- a/tensorflow/core/util/tensor_slice_writer_test.cc +++ b/tensorflow/core/util/tensor_slice_writer_test.cc @@ -22,6 +22,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/test.h" @@ -333,8 +334,8 @@ TEST(TensorSliceWriteTest, SizeErrors) { const std::vector<int8> data(300000000, -1); Status s = writer.Add("test1", shape, slice, data.data()); EXPECT_EQ(s.code(), error::INVALID_ARGUMENT); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("Tensor slice is too large to serialize")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), "Tensor slice is too large to serialize")); } // Add a large string tensor slice, which will fail. @@ -344,8 +345,8 @@ TEST(TensorSliceWriteTest, SizeErrors) { const std::vector<string> data(256 * 1024, std::string(8192, 'f')); Status s = writer.Add("test2", shape, slice, data.data()); EXPECT_EQ(s.code(), error::INVALID_ARGUMENT); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("Tensor slice is too large to serialize")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), "Tensor slice is too large to serialize")); } } |