Use Env::LocalTempFilename for a temp filename.
This function works both in and outside of tests. Additionally, LocalTempFilename works well on Windows where as TmpDir is a little problematic because of bazel oddities. PiperOrigin-RevId: 296250909 Change-Id: I313e4e3467e8f5956c681adb577c70918fe853b6
This commit is contained in:
parent
8bb7420492
commit
f446da7fb2
@ -32,7 +32,8 @@ static std::vector<int> BufferSizes() {
|
||||
|
||||
TEST(BufferedInputStream, ReadLine_Empty) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, ""));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file));
|
||||
@ -48,7 +49,8 @@ TEST(BufferedInputStream, ReadLine_Empty) {
|
||||
|
||||
TEST(BufferedInputStream, ReadLine1) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(
|
||||
WriteStringToFile(env, fname, "line one\nline two\nline three\n"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
@ -73,7 +75,8 @@ TEST(BufferedInputStream, ReadLine1) {
|
||||
|
||||
TEST(BufferedInputStream, ReadLine_NoTrailingNewLine) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, "line one\nline two\nline three"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file));
|
||||
@ -97,7 +100,8 @@ TEST(BufferedInputStream, ReadLine_NoTrailingNewLine) {
|
||||
|
||||
TEST(BufferedInputStream, ReadLine_EmptyLines) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(
|
||||
WriteStringToFile(env, fname, "line one\n\n\nline two\nline three"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
@ -126,7 +130,8 @@ TEST(BufferedInputStream, ReadLine_EmptyLines) {
|
||||
|
||||
TEST(BufferedInputStream, ReadLine_CRLF) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname,
|
||||
"line one\r\n\r\n\r\nline two\r\nline three"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
@ -155,7 +160,8 @@ TEST(BufferedInputStream, ReadLine_CRLF) {
|
||||
|
||||
TEST(BufferedInputStream, ReadNBytes) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffer_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, "0123456789"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file));
|
||||
@ -192,7 +198,8 @@ TEST(BufferedInputStream, ReadNBytes) {
|
||||
|
||||
TEST(BufferedInputStream, SkipNBytes) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, "0123456789"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file));
|
||||
@ -229,7 +236,8 @@ TEST(BufferedInputStream, SkipNBytes) {
|
||||
|
||||
TEST(BufferedInputStream, ReadNBytesRandomAccessFile) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffer_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, "0123456789"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file));
|
||||
@ -264,7 +272,8 @@ TEST(BufferedInputStream, ReadNBytesRandomAccessFile) {
|
||||
|
||||
TEST(BufferedInputStream, SkipNBytesRandomAccessFile) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, "0123456789"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file));
|
||||
@ -299,7 +308,8 @@ TEST(BufferedInputStream, SkipNBytesRandomAccessFile) {
|
||||
|
||||
TEST(BufferedInputStream, Seek) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, "0123456789"));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
TF_ASSERT_OK(env->NewRandomAccessFile(fname, &file));
|
||||
@ -329,7 +339,8 @@ TEST(BufferedInputStream, Seek) {
|
||||
|
||||
TEST(BufferedInputStream, ReadAll_Empty) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
const string expected = "";
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, expected));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
@ -346,7 +357,8 @@ TEST(BufferedInputStream, ReadAll_Empty) {
|
||||
|
||||
TEST(BufferedInputStream, ReadAll_Text) {
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
const string expected = "line one\nline two\nline three";
|
||||
TF_ASSERT_OK(WriteStringToFile(env, fname, expected));
|
||||
std::unique_ptr<RandomAccessFile> file;
|
||||
@ -365,7 +377,8 @@ void BM_BufferedReaderSmallReads(const int iters, const int buff_size,
|
||||
const int file_size) {
|
||||
testing::StopTiming();
|
||||
Env* env = Env::Default();
|
||||
string fname = testing::TmpDir() + "/buffered_inputstream_test";
|
||||
string fname;
|
||||
ASSERT_TRUE(env->LocalTempFilename(&fname));
|
||||
|
||||
const string file_elem = "0123456789";
|
||||
std::unique_ptr<WritableFile> write_file;
|
||||
|
Loading…
Reference in New Issue
Block a user