summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkosak@google.com <kosak@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2015-07-17 21:56:19 +0000
committerkosak@google.com <kosak@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2015-07-17 21:56:19 +0000
commit837211f62a332c6d95ca55b05d40676c580a0c1e (patch)
treef981dbe5c35701863d9076862f7d58d5fbc4b9f7 /test
parentf3aba5a9f6b3e975740de5a117935243cb18671c (diff)
downloadgoogletest-837211f62a332c6d95ca55b05d40676c580a0c1e.tar.gz
Add support for --gtest_flagfile
git-svn-id: http://googletest.googlecode.com/svn/trunk@724 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test')
-rw-r--r--test/gtest-filepath_test.cc18
-rw-r--r--test/gtest_unittest.cc99
2 files changed, 99 insertions, 18 deletions
diff --git a/test/gtest-filepath_test.cc b/test/gtest-filepath_test.cc
index ae9f55a..da72986 100644
--- a/test/gtest-filepath_test.cc
+++ b/test/gtest-filepath_test.cc
@@ -514,24 +514,6 @@ class DirectoryCreationTest : public Test {
posix::RmDir(testdata_path_.c_str());
}
- std::string TempDir() const {
-#if GTEST_OS_WINDOWS_MOBILE
- return "\\temp\\";
-#elif GTEST_OS_WINDOWS
- const char* temp_dir = posix::GetEnv("TEMP");
- if (temp_dir == NULL || temp_dir[0] == '\0')
- return "\\temp\\";
- else if (temp_dir[strlen(temp_dir) - 1] == '\\')
- return temp_dir;
- else
- return std::string(temp_dir) + "\\";
-#elif GTEST_OS_LINUX_ANDROID
- return "/sdcard/";
-#else
- return "/tmp/";
-#endif // GTEST_OS_WINDOWS_MOBILE
- }
-
void CreateTextFile(const char* filename) {
FILE* f = posix::FOpen(filename, "w");
fprintf(f, "text\n");
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index b3ee60a..71a6a96 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -6345,6 +6345,105 @@ TEST_F(InitGoogleTestTest, WideStrings) {
}
# endif // GTEST_OS_WINDOWS
+class FlagfileTest : public InitGoogleTestTest {
+ public:
+ virtual void SetUp() {
+ InitGoogleTestTest::SetUp();
+
+ testdata_path_.Set(internal::FilePath(
+ internal::TempDir() + internal::GetCurrentExecutableName().string() +
+ "_flagfile_test"));
+ testing::internal::posix::RmDir(testdata_path_.c_str());
+ EXPECT_TRUE(testdata_path_.CreateFolder());
+ }
+
+ virtual void TearDown() {
+ testing::internal::posix::RmDir(testdata_path_.c_str());
+ InitGoogleTestTest::TearDown();
+ }
+
+ internal::FilePath CreateFlagfile(const char* contents) {
+ internal::FilePath file_path(internal::FilePath::GenerateUniqueFileName(
+ testdata_path_, internal::FilePath("unique"), "txt"));
+ FILE* f = testing::internal::posix::FOpen(file_path.c_str(), "w");
+ fprintf(f, "%s", contents);
+ fclose(f);
+ return file_path;
+ }
+
+ private:
+ internal::FilePath testdata_path_;
+};
+
+// Tests an empty flagfile.
+TEST_F(FlagfileTest, Empty) {
+ internal::FilePath flagfile_path(CreateFlagfile(""));
+ std::string flagfile_flag =
+ std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
+
+ const char* argv[] = {
+ "foo.exe",
+ flagfile_flag.c_str(),
+ NULL
+ };
+
+ const char* argv2[] = {
+ "foo.exe",
+ NULL
+ };
+
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
+}
+
+// Tests passing a non-empty --gtest_filter flag via --gtest_flagfile.
+TEST_F(FlagfileTest, FilterNonEmpty) {
+ internal::FilePath flagfile_path(CreateFlagfile(
+ "--" GTEST_FLAG_PREFIX_ "filter=abc"));
+ std::string flagfile_flag =
+ std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
+
+ const char* argv[] = {
+ "foo.exe",
+ flagfile_flag.c_str(),
+ NULL
+ };
+
+ const char* argv2[] = {
+ "foo.exe",
+ NULL
+ };
+
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abc"), false);
+}
+
+// Tests passing several flags via --gtest_flagfile.
+TEST_F(FlagfileTest, SeveralFlags) {
+ internal::FilePath flagfile_path(CreateFlagfile(
+ "--" GTEST_FLAG_PREFIX_ "filter=abc\n"
+ "--" GTEST_FLAG_PREFIX_ "break_on_failure\n"
+ "--" GTEST_FLAG_PREFIX_ "list_tests"));
+ std::string flagfile_flag =
+ std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
+
+ const char* argv[] = {
+ "foo.exe",
+ flagfile_flag.c_str(),
+ NULL
+ };
+
+ const char* argv2[] = {
+ "foo.exe",
+ NULL
+ };
+
+ Flags expected_flags;
+ expected_flags.break_on_failure = true;
+ expected_flags.filter = "abc";
+ expected_flags.list_tests = true;
+
+ GTEST_TEST_PARSING_FLAGS_(argv, argv2, expected_flags, false);
+}
+
// Tests current_test_info() in UnitTest.
class CurrentTestInfoTest : public Test {
protected: