Remove the fake test_tmpdir flag in favour of testing::TempDir().

Change-Id: Ifa46c97eb781266e3f848b38d452b82f77aff09a
Reviewed-on: https://code-review.googlesource.com/c/re2/+/46810
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/testing/dfa_test.cc b/re2/testing/dfa_test.cc
index fb3cc14..f394c02 100644
--- a/re2/testing/dfa_test.cc
+++ b/re2/testing/dfa_test.cc
@@ -8,6 +8,7 @@
 #include <vector>
 
 #include "util/test.h"
+#include "util/flags.h"
 #include "util/logging.h"
 #include "util/strutil.h"
 #include "re2/prog.h"
diff --git a/re2/testing/dump.cc b/re2/testing/dump.cc
index 1df8ddd..85cfea2 100644
--- a/re2/testing/dump.cc
+++ b/re2/testing/dump.cc
@@ -26,7 +26,9 @@
 #include "re2/regexp.h"
 
 // Cause a link error if this file is used outside of testing.
-DECLARE_string(test_tmpdir);
+namespace testing {
+std::string TempDir();
+}  // namespace testing
 
 namespace re2 {
 
@@ -154,14 +156,10 @@
 }
 
 std::string Regexp::Dump() {
-  std::string s;
-
   // Make sure being called from a unit test.
-  if (FLAGS_test_tmpdir.empty()) {
-    LOG(ERROR) << "Cannot use except for testing.";
-    return s;
-  }
+  CHECK(!::testing::TempDir().empty());
 
+  std::string s;
   DumpRegexpAppending(this, &s);
   return s;
 }
diff --git a/re2/testing/exhaustive1_test.cc b/re2/testing/exhaustive1_test.cc
index 9ead27e..fe96913 100644
--- a/re2/testing/exhaustive1_test.cc
+++ b/re2/testing/exhaustive1_test.cc
@@ -8,6 +8,7 @@
 #include <vector>
 
 #include "util/test.h"
+#include "util/flags.h"
 #include "re2/testing/exhaustive_tester.h"
 
 DECLARE_string(regexp_engines);
diff --git a/re2/testing/exhaustive_tester.cc b/re2/testing/exhaustive_tester.cc
index cadd2b4..a71c406 100644
--- a/re2/testing/exhaustive_tester.cc
+++ b/re2/testing/exhaustive_tester.cc
@@ -14,6 +14,7 @@
 #include <stdio.h>
 
 #include "util/test.h"
+#include "util/flags.h"
 #include "util/logging.h"
 #include "util/strutil.h"
 #include "re2/testing/exhaustive_tester.h"
diff --git a/re2/testing/random_test.cc b/re2/testing/random_test.cc
index c0b1fe5..011f35f 100644
--- a/re2/testing/random_test.cc
+++ b/re2/testing/random_test.cc
@@ -9,6 +9,7 @@
 #include <vector>
 
 #include "util/test.h"
+#include "util/flags.h"
 #include "re2/testing/exhaustive_tester.h"
 
 DEFINE_int32(regexpseed, 404, "Random regexp seed.");
diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc
index 1fcc550..e1e29d0 100644
--- a/re2/testing/regexp_benchmark.cc
+++ b/re2/testing/regexp_benchmark.cc
@@ -12,6 +12,7 @@
 #include <utility>
 
 #include "util/test.h"
+#include "util/flags.h"
 #include "util/logging.h"
 #include "util/strutil.h"
 #include "re2/prog.h"
diff --git a/util/benchmark.cc b/util/benchmark.cc
index cf5024a..e39c334 100644
--- a/util/benchmark.cc
+++ b/util/benchmark.cc
@@ -12,8 +12,6 @@
 #include "util/flags.h"
 #include "re2/re2.h"
 
-DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
-
 #ifdef _WIN32
 #define snprintf _snprintf
 #endif
diff --git a/util/test.cc b/util/test.cc
index 29c8b41..028616b 100644
--- a/util/test.cc
+++ b/util/test.cc
@@ -3,10 +3,13 @@
 // license that can be found in the LICENSE file.
 
 #include <stdio.h>
+#include <string>
 
 #include "util/test.h"
 
-DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
+namespace testing {
+std::string TempDir() { return "/tmp/"; }
+}  // namespace testing
 
 struct Test {
   void (*fn)(void);
diff --git a/util/test.h b/util/test.h
index 5242e94..de72a3f 100644
--- a/util/test.h
+++ b/util/test.h
@@ -6,7 +6,6 @@
 #define UTIL_TEST_H_
 
 #include "util/util.h"
-#include "util/flags.h"
 #include "util/logging.h"
 
 #define TEST(x, y) \